Artificial Intelligence AI Basics
Artificial Intelligence AI Basics
Artificial Intelligence AI Basics
Module 1
Problems- problem spaces and search, production systems, Problem
characteristics, Searching strategies Generate and Test, Heuristic
Search Techniques- Hill climbing issues in hill climbing, General
Example Problems. Python-Introduction to Python- Lists Dictionaries &
Tuples in Python- Python implementation of Hill Climbing
ARTIFICIAL INTELLIGENCE
AI APPRAOCHES
SJCET Page 1
Module-1 Artificial Intelligence
SJCET Page 2
Module-1 Artificial Intelligence
STRONG AI/HARD AI
WEAK AI /SOFT AI
SJCET Page 3
Module-1 Artificial Intelligence
2. Autonomous control
The ALLVINN computer vision system was trained to steer a car to
keep it following a lane. It was placed in CMUs NAVLAB computer
controlled minivan and used to navigate across the United States.
NAVLAB has video camera that transmit rode images to ALVINN which
then computes the best direction to steer based on experience from
previous training runs.
3. Diagnosis
Medical diagnosis program was able to diagnose various diseases
and gave explanation for diagnosis.
4. Logistics Planning
To do automated logistic planning and scheduling for
transportation. This involved up to 50,000 vehicles, cargo, and people at
a time, and had to account for starting points, destinations, routes and
conflict resolution among all parameters.
5. Robotics
The AI technique was able to create three dimensional models of a
patients internal anatomy.
SJCET Page 4
Module-1 Artificial Intelligence
6. Game playing
We can buy machines that can play master level chess for a few
hundred dollars. There is some AI in them, but they play well against
people mainly through brute force computation--looking at hundreds of
thousands of positions. To beat a world champion by brute force and
known reliable heuristics requires being able to look at 200 million
positions per second.
7. Speech recognition
9. Computer vision
SJCET Page 5
Module-1 Artificial Intelligence
One of the most feasible kinds of expert system given the present
knowledge of AI is to put some information in one of a fixed set of
categories using several sources of information. An example is advising
whether to accept a proposed credit card purchase. Information is
available about the owner of the credit card, his record of payment and
also about the item he is buying and about the establishment from which
he is buying it (e.g., about whether there have been previous credit card
frauds at this establishment).
SJCET Page 6
Module-1 Artificial Intelligence
INTELLIGENT AGENTS
SJCET Page 7
Module-1 Artificial Intelligence
Rational agents
An agent should strive to "do the right thing", based on what it can
perceive and the actions it can perform. The right action is the one
that will cause the agent to be most successful
Performance measure is an objective criterion for success of an
agent's behavior
E.g., performance measure of a vacuum-cleaner agent could be
amount of dirt cleaned up, amount of time taken, amount of
electricity consumed, amount of noise generated, etc.
Rational Agent is the one with which for each possible percept
sequence, it should select an action that is expected to maximize
its performance measure, given the evidence provided by the
percept sequence and whatever built-in knowledge the agent has.
Rationality is distinct from omniscience (all-knowing with infinite
knowledge)
Agents can perform actions in order to modify future percepts so
as to obtain useful information (information gathering, exploration)
An agent is autonomous if its behavior is determined by its own
experience (with ability to learn and adapt)
SJCET Page 8
Module-1 Artificial Intelligence
Environment types
SJCET Page 9
Module-1 Artificial Intelligence
SJCET Page 10
Module-1 Artificial Intelligence
PROBLEM-SOLVING AGENTS
A Problem solving agent is a goal-based agent. It decide what to do by
finding sequence of actions that lead to desirable states. The agent can
adopt a goal and aim at satisfying it.
SJCET Page 11
Module-1 Artificial Intelligence
Initial state :- Specify one or more states within that space that
describe possible situations from which the problem solving
process may start. These states are called the initial sates.
SJCET Page 12
Module-1 Artificial Intelligence
State space is the set of all states reachable from the initial
state.(initial state + successor function).State space forms a graph in
which nodes are states and the arcs between nodes are actions. A path
in state space is a sequence of states connected by a sequence of actions.
.
Initial State: The starting position can be described as an 8 by 8 array.
SJCET Page 13
Module-1 Artificial Intelligence
Goal State: any board position in which the opponent does not have a
legal move and his or her king is under attack.
Current Position
While pawn at square ( 5 , 2), AND Square ( 5 , 3 ) is empty, AND
Square ( 5 , 4 ). is empty.
The current position of a coin on the board is its STATE and the set of
all possible STATES is STATE SPACE. One or more states where the
problem terminates is FINAL STATE or GOAL STATE.
Example Problems
TOY PROBLEM
The agent is in one of the 2 locations, each of which might or might not
contain dirt. Any state can be designated as the initial state. After trying
these actions (Left, Right, Suck), we get another state. The goal test
checks whether all squares are clean.
The state space for the vacuum world. Arcs denote actions: L = Left,R =
Right,S = Suck
SJCET Page 14
Module-1 Artificial Intelligence
2. 8 Puzzle
Arrange the tiles so that all the tiles are in the correct positions.
You do this by moving tiles. You can move a tile up, down, left, or right,
so long as the following conditions are met:
A) there's no other tile blocking you in the direction of the movement;
and
B) you're not trying to move outside of the boundaries/edges.
For example, suppose we wanted to get from the initial state to the goal
state given below.
SJCET Page 15
Module-1 Artificial Intelligence
and the is a blank tile you can slide around. This 8 puzzle instance
can be solved in 5 steps.
3. 8-Queens Problem
7 X
6 X
5 X
4 X
3 X
2 X
1 X
0 X
SJCET Page 16
Module-1 Artificial Intelligence
0 1 2 3 4 5 6 7
In either case the path cost is of no interest because only the final
state counts.
For eg: Incremental formulation
1. States - Any arrangement of 0 to 8 queens on the board
2. Initial state - No queens on the board
3. Successor function - Add a queen to any empty square
4. Goal test - 8 queens on board and none attacked
4. Water-Jug Problem
You are given two jugs a 4-gallon one and other 3-gallon one.
Neither has any measuring marker on it. There is a pump that can be
used to fill the jugs with water. The Problem : How can you get exactly 2
gallons of water into the 4-gallon jug?
SJCET Page 17
Module-1 Artificial Intelligence
ISSUES
8. (x, y) (x (3 y), 3)
SJCET Page 18
Module-1 Artificial Intelligence
9. (x, y) (x + y, 0)
10.(x, y) (0, x + y)
0 0
0 3
2
3 0
9
3 3
2
4 2
7
0 2
5 or 12
2 0
9 or 11
SJCET Page 19
Module-1 Artificial Intelligence
2. Specify one or more state with in the space as start state. This
is termed as initial state.
4. Set of assumptions
Eg:- in water jug problem we assumed that we can fill a jug from
the pump, we can pour the water out of jug on to the ground, there are
no other measuring devises available and there are no measuring
markers on the jug.
5. Towers of Hanoi
There are three posts 1, 2, and 3. One of which, say post 1, has n
disks on it in ascending size. The Problem is: How to transfer all disks
from the post 1 to post 2, keeping the order of ascending size. Each time
only one disk can be moved. Post 2 is used for the intermediate storage
The goal of this puzzle is start with the rings arranged as shown above,
and to move them all to this configuration:
SJCET Page 20
Module-1 Artificial Intelligence
Only the top ring on a peg can be moved, and it may only be placed on a
smaller ring, or on an empty peg. For the Tower of Hanoi, the problem
space is the set of all possible configurations of rings on the pegs. Some
of the configurations or states in the space are given special
interpretations:
Towers of Hanoi
Initial state
Goal State
SJCET Page 21
Module-1 Artificial Intelligence
SJCET Page 22
Module-1 Artificial Intelligence
If there are n cities then the number of possible paths among them
is 1*2*3*4*(n-1) or (n-1)! .The time required to examine a single
path is proportional to n!. Assume there are 35 cities to visit. To solve
this problem he would take more time than he would be willing to send.
This phenomenon is called combinatorial explosion.
3. VLSI layout
4. Robot Navigation
6. Protein Design
SJCET Page 23
Module-1 Artificial Intelligence
7. Internet Searching
Eg:
{<Go(sibiu),In(sibiu)>,<Go(timisora),In(Timisora)>,<Go(zerint),In(zerint)>}
Together the initial state and successor function defines the state space.
A path in the state space is a sequence of state connected by sequence
of action.
The Goal Test
It determines whether the given state is goal or not Eg: { In(Bucharest)}
SJCET Page 24
Module-1 Artificial Intelligence
A Path Cost
This function assigns a numeric cost to each path. The step cost of
taking action a to go from state x to state y is denoted by c(x,a,y).
FORMULATING PROBLEMS
Abstraction: the process of removing details from representation Eg: in
an actual cross country trip it includes many details like traveling
companions, what is on the radio, the scenery out of the window,
weather, and condition of the road. These things are irrelevant to the
problem for finding solution.
Action Abstraction: in addition to abstracting state description we can
abstract actions also. A driving action has many effects. Besides
changing the location of the vehicle, it takes up time, consumes fuel,
generates pollution etc. In our formulation we take into account only the
change in location. In a problem solving scenario think of the abstract
state and action to be chosen corresponding to large set of detailed world
states and detailed action sequence. The choice of a good abstraction
thus involves removing as much details as possible.
SJCET Page 25
Module-1 Artificial Intelligence
1. State the state in the state space to which the node corresponds
2. Parent node node in the search tree that generated this node
3. Action action that was applied to the parent to generate the node.
4. Path cost cost of the path from the initial state to the node as
indicated by parent pointers
5. Depth no of steps along the path from the initial state.
Collection of nodes that have been generated but not yet expanded
is called fringe. Each element of the fringe is a leaf node i.e. a node with
no successors in the tree.
SJCET Page 26
Module-1 Artificial Intelligence
Control Strategies and Rule Applier- that specifies the order in which the
rules will be compared to the database and ways in which conflicts are
resolved. This is also known as a rule interpreter, which performs
SJCET Page 27
Module-1 Artificial Intelligence
3.ACTION STAGE
RB actions are
SJCET Page 28
Module-1 Artificial Intelligence
SJCET Page 29
Module-1 Artificial Intelligence
We can now draw a part of a search space by showing the initial state at
the top of an upside-down tree, with each "level" consisting of states that
result from applying operators to states in the level above:
PROBLEM CHARACTERISTICS
SJCET Page 30
Module-1 Artificial Intelligence
(x2 + 3x + sin2x.cos2x)dx
(x2 + 3x + sin2x.cos2x)dx
(1 cos2x)cos2xdx
cos2xdx cos4xdx
29
Problem Classification
SJCET Page 31
Module-1 Artificial Intelligence
The goal is to transform the starting position into the goal position by
sliding the tiles around. In an attempt to solve the 8- puzzle, we might
make a stupid move. For example, in the game shown above, we
might start by sliding tile 5 into the empty space. Having done that,
we cannot change our mind and immediately slide tile 6 into the
empty space since the empty space will essentially have moved. But
we can backtrack and undo the 1st move, sliding tile 5 back to where
it was. Then we can move tile 6. Here mistakes can be
recovered.Backtracking will be necessary to recover from such
mistakes, so the control structure must be implemented using a
pushdown stack in which decisions are recorded in case they need to
be undone.
SJCET Page 32
Module-1 Artificial Intelligence
Plan revision is made as the plan is carried out and the necessary
feedback is provided.
SJCET Page 33
Module-1 Artificial Intelligence
One place the salesman could start is Boston. In that case, one
path that might be followed is the one shown below which is 8850 miles
long.
SJCET Page 34
Module-1 Artificial Intelligence
But is this the solution to the problem? The answer is that we cannot be
sure unless we also try all other paths to make sure that none of them is
shorter. Best path problems are computationally harder than any path
problems.
SJCET Page 35
Module-1 Artificial Intelligence
SJCET Page 36
Module-1 Artificial Intelligence
SEARCH ALGORITHMS
Search Strategies
Breath-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Bidirectional search
Hill climbing
Simulated annealing
Best-first search
A* search
UNINFORMED/BLIND SEARCH
Let us suppose that the state labeled G is a goal state in this space, and
that, as shown, no operators apply to the states I, J, E, F and H.
A program will start with the initial state A, and try to find the goal
by applying operators to that state, and then to the states B and/or C
that result, and so forth. The idea is to find a goal state, and often one is
also interested in finding the goal state as fast as possible, or in finding a
solution that requires the minimum number of steps, or satisfies some
other requirements.
Algorithm: Note:
SJCET Page 38
Module-1 Artificial Intelligence
Advantages:
1. BFS will not get trapped anywhere .This contrasts with DFS which
may follow a single unfruitful path for a very long time before the
path actually terminates in a state that has no successors.
2. If there is solution then BFS is guaranteed to find it. Furthermore
if there are multiple solutions then a minimal solution will be
found. This is guaranteed by the fact that longer paths are never
explored until all shorter ones have already been examined. This
contrasts with DFS which may find a long path to a solution in one
part of the tree when a shorter path exists in some other
unexplored part of the tree.
Disadvantages:
We associate with each node n a cost g(n) that measures the cost of
getting to node n from the start node. g(start) = 0. If ni is a successor of n,
then g(ni) = g(n) + c(n,ni) , where c(n,ni) is the cost of going from node n to
node ni .
SJCET Page 39
Module-1 Artificial Intelligence
Advantage:
Disadvantages:
The most recently created state from which alternative moves are
available will be revisited and a new state is created. This form of
backtracking is called chronological backtracking because the order in
which steps are undone depends only on the temporal sequence in which
steps where originally made. Specifically the most recent step is always
the first to be undone. This form of backtracking is what is usually
meant by the simple backtracking. An example is shown below:
SJCET Page 40
Module-1 Artificial Intelligence
Algorithm:
1. If the initial state is a goal state, terminate with success and return
that state.
SJCET Page 41
Module-1 Artificial Intelligence
the remove the paths to expand them, you still remove them from the
front. The result of this is that DFS explores one path, ignoring
alternatives, until it either finds the goal or it cant go anywhere else.
Optimality: No, unless search space is finite and no loops are possible.
Advantages:
1. DFS requires less memory since only the nodes on the current
path are stored. This contrasts with BFS where all of the tree that
has so far been generated must be stored. Once a node has been
expanded it can be removed from memory as soon as all its
descendants have been fully explored.
2. Easily programmed: function call stack does most of the work of
maintaining state of the search.
3. DFS may find a solution without examining much of the search
space at all. This contrasts with BFS in which all parts of the tree
must be examined to level n before any nodes at level n+1 can be
examined. This is particularly significant if many acceptable
solutions exist. DFS can stop when one of them is found.
Disadvantages:
SJCET Page 42
Module-1 Artificial Intelligence
SJCET Page 43
Module-1 Artificial Intelligence
Algorithm :
1. Determine the vertex where the search should start and assign the
maximum search depth
2. Check if the current vertex is within the maximum search depth
o If not: Do nothing
o If yes:
1. Expand the vertex and save all of its successors in a
stack
2. Call DLS recursively for all vertices of the stack and go
back to Step 2
Problems:
SJCET Page 44
Module-1 Artificial Intelligence
Node generation:
SJCET Page 45
Module-1 Artificial Intelligence
level d: once
level d-1: 2
level d-2: 3
.
level 2: d-1
level 1: d
Algorithm :
1. Set DEPTH-LIMIT = 0
2. Conduct depth-first search to a depth of DEPTH-LIMIT If a solution
path is found, then return it.
3. Increment DEPTH-LIMIT by 1 and go to step 2.
Advantages:
Disadvantage:
SJCET Page 46
Module-1 Artificial Intelligence
6. Bi-Directional Search
This does not come without a price: Aside from the complexity of
searching two times in parallel, we have to decide which search tree to
extend at each step; we have to be able to travel backwards from goal to
initial state - which may not be possible without extra work; and we need
an efficient way to find the intersection of the two search trees. This
additional complexity means that the A* search algorithm is often a
better choice if we have a reasonable heuristic.
Completeness: Yes
SJCET Page 47
Module-1 Artificial Intelligence
Heuristic function:
SJCET Page 48
Module-1 Artificial Intelligence
SJCET Page 49
Module-1 Artificial Intelligence
HILL CLIMBING
The key difference between Generate and Test and Hill climbing is
the use of an evaluation function as a way to inject task-specific
knowledge into the control process.
SJCET Page 50
Module-1 Artificial Intelligence
Successor function:
It is function which returns all possible states which are generated
by a single queen move to another in the same column. The total
successor of the each state 8x7 =56.
SJCET Page 51
Module-1 Artificial Intelligence
SJCET Page 52
Module-1 Artificial Intelligence
SJCET Page 53
Module-1 Artificial Intelligence
Start
Goal
Local heuristic:
+1 for each block that is resting on the thing it is supposed to be
resting on.
-1 for each block that is resting on a wrong thing.
Using this function, the goal state has a score of 8. The initial slate has a
score of 4 (since it gets one point added for blocks C, D, E, F, G and H
and one point subtracted for blocks A and B).
There is only one move from the initial state namely to move block A to
the table. That produces a state with a score of 6 (since now As position
causes a point to be added rather than subtracted).
SJCET Page 54
Module-1 Artificial Intelligence
From the new state, there are three possible moves, leading A to the
three stales shown in Fig. These states have the scores:
SJCET Page 55
Module-1 Artificial Intelligence
Global heuristic:
For each block that has the correct support structure: +1 to every
block in the support structure.
For each block that has a wrong support structure: -1 to every block
in the support structure.
SJCET Page 56
Module-1 Artificial Intelligence
Using this function, the goal state has a score of 28.(1 for B,2 for
C.) The initial slate has a score of -28 (since it gets one point
subtracted for block C, 2 for D)
The three states that can be produced next have the following
scores
SJCET Page 57
Module-1 Artificial Intelligence
a)score -28
b)score -16
c)score -15
SIMULATED ANNEALING
A variation of hill climbing in which, at the beginning of the
process, some downhill moves may be made.
To do enough exploration of the whole space early on, so that the
final solution is relatively insensitive to the starting state.
Thus lowering the chances of getting caught at a local maximum,
or plateau, or a ridge.
Physical substances are melted and then gradually cooled until
some solid state is reached. The goal is to produce a minimal-
energy state.
Here we attempt to minimize rather than maximising the value of
the objective function.
The process is one of valley descending in which the objective
function is the energy level.
Nevertheless, there is some probability for a transition to a higher
energy state: p=e-E/kT.
SJCET Page 58
Module-1 Artificial Intelligence
ALGORITHM-SIMULATED ANNEALING
SJCET Page 59
Module-1 Artificial Intelligence
SJCET Page 60
Module-1 Artificial Intelligence
SJCET Page 61