AI-unit-2
AI-unit-2
UNIT-II
1
Problem-solving agents
Decide what to do by finding sequences of actions
that lead to desirable states.
Goal formulation: first step of problem solving.
Depends on current situation and agent’s
performance measure.
Actions: cause transitions between world states.
Problem formulation: deciding which actions and
states to consider, given a goal.
Contd.
Search
considering sequences of actions that lead to states of
Search algorithm
Takes a problem as input.
Execution
Carrying out the actions sequence.
Agent design
formulate, search, execute
Problem-solving agents
4
Example: Romania
On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest.
Formulate goal:
be in Bucharest.
Formulate problem:
states: various cities.
actions: drive between cities.
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
5
Example: Romania
6
Single-state problem formulation
A problem is defined by four items:
7
Selecting a state space
Real world is absurdly complex
state space must be abstracted for problem solving
(Abstract) state = set of real states
(Abstract) action = complex combination of real actions
e.g., "Arad Zerind" represents a complex set of possible routes,
detours, rest stops, etc.
(Abstract) solution =
set of real paths that are solutions in the real worl.
Each abstract action should be "easier" than the original
problem.
8
Vacuum world state space graph
states?
actions?
goal test?
path cost? 9
Vacuum world state space graph
states?
actions?
goal test?
path cost?
11
Example: The 8-puzzle
16
Tree search example
17
Tree search example
18
Tree search example
19
Search strategies
A search strategy is defined by picking the order of node
expansion.
Strategies are evaluated along the following dimensions:
completeness: Is the algorithm guaranteed to find a solution when
there is one?
time complexity: How long does it take to find a solution?
space complexity: How much memory is needed to perform the
search?
optimality: Does it find an optimal solution?
Let
b is max no of successors of any node.
d is depth of the shallowest goal node.
m is max length of any path.
20
Uninformed search strategies
Uninformed or blind search strategies use only the
information available in the problem definition.
Strategy is informed or heuristic if it knows that one non-
goal state is more promising than other.
Blind search
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Bidirectional search
21
Breadth-first search
Expand root node first, then its successors and then their
successors and so on.
Implementation:
fringe is a FIFO queue, i.e., new successors go at end.
22
Breadth-first search
Expand root node first, then its successors and then their
successors and so on.
Implementation:
fringe is a FIFO queue, i.e., new successors go at end.
23
Breadth-first search
Expand root node first, then its successors and then their
successors and so on.
Implementation:
fringe is a FIFO queue, i.e., new successors go at end.
24
Breadth-first search
Expand root node first, then its successors and then their
successors and so on.
Implementation:
fringe is a FIFO queue, i.e., new successors go at end.
25
Properties of breadth-first search
26
Uniform-cost search
Optimal with any step cost.
Expand least-cost unexpanded n nodes.
Implementation:
fringe = queue ordered by path cost
Equivalent to breadth-first if step costs all equal
27
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
28
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
29
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
30
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
31
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
32
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
33
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
34
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
35
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
36
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
37
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
38
Depth-first search
Expand deepest unexpanded node.
Implementation:
fringe = LIFO queue, i.e., put successors at front.
39
Properties of depth-first search
Complete? No: fails in infinite-depth spaces.
complete in finite spaces
Time? O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than
breadth-first.
Space? O(bm), i.e., linear space.
Optimal? No
40
Depth-limited search
For unbounded trees
depth-first search with depth limit l i.e. nodes at depth l
have no successors.
Incomplete if l<d.
Non optimal if l>d.
41
Iterative deepening search
Finds the best depth limit.
Gradually increases the limit until a goal is found.
Combines benefits of BFS and DFS.
States are generated multiple times.
42
Iterative deepening search l =0
43
Iterative deepening search l =1
44
Iterative deepening search l =2
45
Iterative deepening search l =3
46
Iterative deepening search
Number of nodes generated in an iterative
deepening search to depth d with branching factor
b:
NIDS = d b1 + (d-1)b2 + … + 3bd-2 +2bd-1 + 1bd
47
Properties of IDS
Complete? Yes
Time? O(bd)
Space? O(bd)
Optimal? Yes.
48
Bidirectional search
Idea is to run two simultaneous searches.
One forward from the initial state
One backward from the goal.
Stops when the two searches meet in the middle.
Motivation is (bd/2)+(bd/2) is much less than (bd).
Searching backward is not an easy job.
49
Bidirectional search
50
Summary of algorithms
51
Informed Search Algorithms
Informed Search Strategies
• These use problem-specific knowledge.
• Finds solutions more efficiently.
• General approach is best-first search.
Best-first search
• Idea: use an evaluation function f(n) for selecting a node
for expansion.
– estimate of "desirability“
– Expand most desirable unexpanded node
• Implementation:
priority queue, a data structure that will maintain the
fringe in ascending order of f-values.
Best-first search
• Family of best first search algorithms exists with different
evaluation functions.
• A key component is a heuristic function h(n):
h(n) = estimated cost of the cheapest path from node n to
a goal node.
• If n is goal node, h(n)=0.
• Special cases:
– greedy best-first search
– A* search
Greedy best-first search
• Evaluation function f(n) = h(n) (heuristic)
= estimate of cost from n to goal.
• e.g., hSLD(n) = straight-line distance from n
to Bucharest.
• Greedy best-first search expands the node
that appears to be closest to goal.
Romania with step costs in km
Greedy best-first search
example
Greedy best-first search
example
Greedy best-first search
example
Greedy best-first search
example
Properties of greedy best-first
search
• Complete? No – can get stuck in loops,
e.g., Iasi Neamt Iasi Neamt
• Time? O(bm), but a good heuristic can give
dramatic improvement
• Space? O(bm) -- keeps all nodes in
memory
• Optimal? No
A* search
• Idea: avoid expanding paths that are
already expensive.
• Evaluation function f(n) = g(n) + h(n).
• g(n) = cost so far to reach n.
• h(n) = estimated cost from n to goal.
• f(n) = estimated total cost of path through
n to goal.
A* search example
A* search example
A* search example
A* search example
A* search example
A* search example
Admissible heuristics
• A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach
the goal state from n.
• An admissible heuristic never overestimates the
cost to reach the goal, i.e., it is optimistic.
• Example: hSLD(n) (never overestimates the
actual road distance).
• Theorem: If h(n) is admissible, A* using TREE-
SEARCH is optimal.
Optimality of A* (proof)
• Suppose some suboptimal goal G2 has been generated and is in the
fringe. Let n be an unexpanded node in the fringe such that n is on a
shortest path to an optimal goal G.
•
• h1(S) = ?
• h2(S) = ?
Admissible heuristics
• E.g., for the 8-puzzle:
• h1(n) = number of misplaced tiles
• h2(n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
Dominance
• If h2(n) ≥ h1(n) for all n (both admissible)
• then h2 dominates h1
• h2 is better for search.
plateau
ridge
Hill Climbing: Disadvantages
Local maximum
A state that is better than all of its
neighbours, but not better than some other
states far away.
33
Hill Climbing: Disadvantages
Plateau
A flat area of the search space in which all
neighbouring states have the same value.
34
Hill Climbing: Disadvantages
Ridge: The orientation of the high region,
compared to the set of available moves,
makes it impossible to climb up. However,
two moves executed serially may increase
the height.
35
Simulated Annealing search
• Idea: escape local maxima by allowing some
"bad" moves but gradually decrease their
frequency.
• Annealing is the process used to temper or
harden metals and glass by heating them to a
high temperature and then gradually cooling
them, thus allowing the material to coalesce into
a low energy crystalline state.
Simulated Annealing search
• Not best but picks a random move.
• If it improves situation, then accepted.
• Otherwise with some probability less than 1.
• The probability decreases exponentially with the
badness of the move
– The amount E by which the evaluation is worsened.
– As T goes down.
– Bad moves are allowed at the start then
decreases.
Simulated annealing search
Simulated annealing search
• One can prove: If T decreases slowly enough,
then simulated annealing search will find a
global optimum with probability approaching 1
MINIMAX-VALUE(n)=
UTILITY(n) If n is a terminal
maxs successors(n) MINIMAX-VALUE(s) If n is a max node
mins successors(n) MINIMAX-VALUE(s) If n is a min node
Minimax
[-∞,+∞]
[-∞, +∞]
Alpha-Beta Example
(continued)
[-∞,+∞]
[-∞,3]
Alpha-Beta Example
(continued)
[-∞,+∞]
[-∞,3]
Alpha-Beta Example
(continued)
[3,+∞]
[3,3]
Alpha-Beta Example
(continued)
[3,+∞]
This node is worse
for MAX
[3,3] [-∞,2]
Alpha-Beta Example
(continued)
[3,14] ,
[3,5] ,
[3,3]
[3,3]