Download Informed Search - Lecture 5 - Artificial intelligence - Notes | CS 440 and more Study notes Computer Science in PDF only on Docsity!
Informed SearchInformed Search
(A)(A)
Lecture #5Lecture
AnnouncementsAnnouncements
Turn in writing assignment #1 now Turn in writing assignment #1 now
- – You should give two copies to JasonYou should give two copies to Jason One with your name on itOne with your name on it One withoutOne without At the end of class, Jason will give you back someone else’ At the end of class, Jason will give you back someone else’ss (anonymous) essay to critique(anonymous) essay to critique
- – Your evaluation will not effect their gradeYour evaluation will not effect their grade
- –^ You will be graded on your critiqueYou will be graded on your critique
- – Critique: one paragraphCritique: one paragraph What they did rightWhat they did right What they did wrongWhat they did wrong The grade you would have given themThe grade you would have given them
- – Due ThursdayDue Thursday ACM club: Wed., 5:00- ACM club: Wed., 5:00-6:00, USC 1106:00, USC 110
- – ““Automation and RevisionsAutomation and Revisions”” ((croncron,, svnsvn))
Review:Review:
Tree searchTree search
functionfunction TREETREE--SEARCH(SEARCH( problem, fringe, strategyproblem, fringe, strategy )) returnsreturns a solution or failurea solution or failure fringefringe ←← INSERT(MAKEINSERT(MAKE--NODE(NODE( problemproblem .InitialState.InitialState()),()), fringefringe )) loop doloop do ifif EMPTY?(EMPTY?( fringefringe )) thenthen returnreturn failurefailure node node ←← strategystrategy .SelectAndRemoveNode(.SelectAndRemoveNode( fringefringe )) ifif^ problemproblem .Solution?(.Solution?( nodenode ))^ thenthen returnreturn^ nodenode elseelse fringefringe ←← APPEND(APPEND( fringefringe ,, problemproblem .EXPAND(.EXPAND( nodenode )))) enddoenddo
BestBest--first searchfirst search
Informed search strategy: expand apparently best Informed search strategy: expand apparently best
nodenode
Factors going into determination of best: Factors going into determination ofbest:
- – Current cost of the solution pathCurrent cost of the solution path
- – Estimated distance to the nearest goal stateEstimated distance to the nearest goal state
Node is selected for expansion based on an Node is selected for expansion based on an
evaluation function evaluation function f(n)f(n)
Implementation: Implementation:
- – FringeFringe is a queue sorted in decreasing order ofis a queue sorted in decreasing order of ff
- – Special cases: greedy search, A* searchSpecial cases: greedy search, A* search
HeuristicsHeuristics
Heuristic:Heuristic: “A rule of thumb, simplification, or“A rule of thumb, simplification, or
educated guess that reduces or limits theeducated guess that reduces or limits the
search for solutions in domains that aresearch for solutions in domains that are
difficult and poorly understood.difficult and poorly understood.””
– – The heuristic functionThe heuristic function h(n)h(n) estimates costestimates cost
of the cheapest path from nodeof the cheapest path from node nn to goalto goal
node.node.
– – IfIf^ nn^ is a goal nodeis a goal node^ h(n)=0h(n)=
Greedy best- Greedy best-first searchfirst search
Expand node on the frontier closest to Expand node on the frontier closest to
goalgoal
Determination of closest based upon the Determination of closest based upon the
heuristic functionheuristic function hh
Greedy search: An exampleGreedy search: An example
Consider path planning between two citiesConsider path planning between two cities
Use the straight line distance heuristic,Use the straight line distance heuristic,^ hh^ SLDSLD
The greedy solution is (A, B, D)The greedy solution is (A, B, D)
The least cost solution is (A, B, D)The least cost solution is (A, B, D)
A B
C
D
Greedy search: An exampleGreedy search: An example
Consider path planning between two cities Consider path planning between two cities
Use the straight line distance heuristic, Use the straight line distance heuristic, (^) hh (^) SLDSLD
The greedy solution is (A, C, D) The greedy solution is (A, C, D)
The least cost solution is (A, B, D) The least cost solution is (A, B, D)
A B
C
D
A* SearchA* Search
Order states by theirOrder states by their total estimatedtotal estimated costcost
Always select the node with the lowest valueAlways select the node with the lowest value
Total estimated cost:Total estimated cost:
g(n)g(n) the cost to reachthe cost to reach n (n ( known)known)
h(n)h(n)^ the estimated cost to the goalthe estimated cost to the goal
f(n) = g(n) + h(n)
Avoiding repeated statesAvoiding repeated states
BFS: BFS:
- – Add to fringe only if state not already visited.Add to fringe only if state not already visited.
- – i.e., state absent from thei.e., state absent from the^ closed listclosed list ..
A: A:
- – If node represents state already visited,If node represents state already visited,
update cost according lower total estimatedupdate cost according lower total estimated cost.cost.
Heuristic functionsHeuristic functions
Heuristics for the 8 puzzle:Heuristics for the 8 puzzle:
hh^11 = the number of misplaced tiles= the number of misplaced tiles
hh^22 = the sum of the distances of the tiles from their goal= the sum of the distances of the tiles from their goal
positions (manhattan distance)positions (manhattan distance)
- – hh 22 (s)=3+1+2+2+2+3+3+2=18(s)=3+1+2+2+2+3+3+2=
Comparison of heuristics Comparison of heuristics
Even very simple heuristics likeEven very simple heuristics like hh 11 andand hh (^22)
can significantly reduce the search cost: can significantly reduce the search cost:
A* withA* with hh 22 3939 113113
A* withA* with^ hh 11 9393 539539
Iterative DeepeningIterative Deepening 47,12747,127 3,473,9413,473,
AlgorithmAlgorithm Depth 10Depth 10 Depth 14Depth 14
A* in RomaniaA* in Romania
Expand Pitesti and determineExpand Pitesti and determine f(n)f(n) for each nodefor each node
- – f(Bucharest)=f(Bucharest)=c(Pitesti,Bucharest)+h(Bucharestc(Pitesti,Bucharest)+h(Bucharest)=418+0=418)=418+0= Best choice is BucharestBest choice is Bucharest
Note values along solution path !!Note values along solution path !!
Is the solution optimal?Is the solution optimal?
Admissible heuristics Admissible heuristics
A heuristic is admissible if it A heuristic is admissible if it never overestimatesnever overestimates the cost to reach the goal (optimistic) the cost to reach the goal (optimistic) Formally:Formally: 1.1. h(n) <= h(n)h(n) <= h(n) wherewhere h(n)h(n) is the true cost fromis the true cost from nn 2.2. h(n) >= 0h(n) >= 0 soso h(G)=0h(G)=0 for any goalfor any goal GG ..
Examples:Examples: hh (^) SLDSLD (n(n)) never overestimates the actual road distancenever overestimates the actual road distance Heuristics for 8 puzzleHeuristics for 8 puzzle
Optimality of AOptimality of A
LetLet^ GG^22 be a suboptimal goal node.be a suboptimal goal node.
LetLet^ nn^ be an unexpanded node on an optimal cost path tobe an unexpanded node on an optimal cost path to
goalgoal GG. Then:. Then:
f(Gf(G 22 )) = g(G= g(G 22 )) sincesince h(Gh(G 22 )=0)=
> g(G)> g(G) sincesince GG 22 is suboptimalis suboptimal
>= f(n)>= f(n) sincesince hh is admissibleis admissible
SinceSince^ f(Gf(G^22 ) > f(n)) > f(n) , A* will never select, A* will never select^ GG^22 for expansionfor expansion
Graph searchGraph search
Turns out there is an additional way to Turns out there is an additional way to
avoid the necessary bookkeeping requiredavoid the necessary bookkeeping required
for graph search: use a consistentfor graph search: use aconsistent
heuristic.heuristic.
Consistency Consistency
A heuristic isA heuristic is consistentconsistent if:if:
h(n)h(n) ≤≤ c(n, a, nc(n, a, n’’) + h(n) + h(n’’))
Given a consistent heuristic:Given a consistent heuristic:
f(nf(n’’) =) = g(ng(n’’) +) + h(nh(n’’))
≥ ≥ g(n) + c(n,a,ng(n) +c(n,a,n’’) +) + h(nh(n’’))
≥ ≥ g(n) + h(n) = f(n)g(n) + h(n) = f(n)
A consequence of consistency:A consequence of consistency: f(n)f(n)
monotonically decreasing along a pathmonotonically decreasing along a path
Monotonicity implies optimalityMonotonicityimplies optimality
A* expands nodes in order of increasing A* expands nodes in order of increasing ff valuevalue
Expansion represented as contours of states with Expansion represented as contours of states with
equalequal ff valuevalue
A* expands all nodes with A* expands all nodes with f(n) < Cf(n) < C
When a heuristic isWhen a heuristic is ““almostalmost””
admissibleadmissible
Graceful Decay of AdmissibilityGraceful Decay of Admissibility
If a heuristic rarely overestimates cost by more thanIf a heuristic rarely overestimates cost by more than δ δ ,,
then the A* algorithm will rarely find a solution whosethen the A* algorithm will rarely find a solution whose
cost is more thatcost is more that δδ greater than the cost of the optimalgreater than the cost of the optimal
solution.solution.
Means:Means:
- – So long as we undershoot almost all the time, andSo long as we undershoot almost all the time, and
bound how much we overshoot, we seldom get inbound how much we overshoot, we seldom get in
trouble, and the trouble is minor.trouble, and the trouble is minor.
Evaluation of AEvaluation of A
Completeness: YES Completeness: YES
- – Unless there are infinitely many nodes withUnless there are infinitely many nodes with f<f(G)f<f(G)
Evaluation of A* Evaluation of A*
Completeness: YESCompleteness: YES
Time complexity:Time complexity:
- – Number of nodes expanded is still exponential since ANumber of nodes expanded is still exponential since A
expands all nodes withexpands all nodes with f(n) < Cf(n) < C
Evaluation of A* Evaluation of A*
Completeness: YES Completeness: YES
Time complexity: Time complexity:
- – Number of nodes expanded is still exponential since ANumber of nodes expanded is still exponential since A
expands all nodes withexpands all nodes with f(n) < Cf(n) < C
Space complexity: also exponential. Space complexity: also exponential.
Evaluation of AEvaluation of A
Completeness: YESCompleteness: YES
Time complexity:Time complexity:
- – Number of nodes expanded is still exponential since ANumber of nodes expanded is still exponential since A
expands all nodes withexpands all nodes with^ f(n) < Cf(n) < C
Space complexity: also exponential.Space complexity: also exponential.
Optimality: YESOptimality: YES
- – A* does not expand any node withA* does not expand any node with^ f(n) > Cf(n) > C
- – Assuming anAssuming an admissableadmissable heuristicheuristic
Comparing heuristicsComparing heuristics
Heuristics for the 8 puzzle:Heuristics for the 8 puzzle:
h h 11 = the number of misplaced tiles= the number of misplaced tiles
h h 22 = the sum of the distances of the tiles from their goal= the sum of the distances of the tiles from their goal
positions (manhattan distance)positions (manhattan distance)