Post on 29-Mar-2018
ARTIFICIAL INTELLIGENCE
Lecturer: Silja Renooij
Informed search
Utrecht University The Netherlands
These slides are part of the INFOB2KI Course Notes available fromwww.cs.uu.nl/docs/vakken/b2ki/schema.html
INFOB2KI 2017-2018
Shakey (1966-1972)
Shakey is a robot which navigates using?
a) Dijkstra’s algorithmb) A1c) A2d) A*
2
Recap: Search Search problem: States (configurations of the world) Actions and costs Successor function Start state and goal test
Search tree: Nodes represent how to reach states Cost of reaching state = sum of action costs
Search algorithm: Systematically builds a search tree Chooses an ordering of the fringe Optimal: find least‐cost plans
3
Search HeuristicsA heuristic is:
a function that estimates how close a state is to a goal designed for a particular search problem
easy to compute: otherwise overhead of computing the heuristic could outweigh time saved by reducing search!
Examples:
Manhatten distance Euclidean distance
4
Heuristic search (outline)
Best‐first search– Greedy search– A* search
Heuristic functions
Local search algorithms– Hill‐climbing search– Simulated annealing search– Local beam search– Genetic algorithms
5
Best-first search Tree/Graph‐search with an evaluation function f(n) for
each node n– estimate of "desirability" Expand most desirable unexpanded node Should direct search toward goal
Implementation:Order the nodes in fringe in decreasing order of desirability f(n)
Finds best solution, according to evaluation function
Special cases:– greedy search– A* search
6
Both also use heuristic h(n) with• h(n) ≥ 0 for all n• h(n) = 0 for state[n] = goal
Greedy search
Evaluation function f(n) = h(n) where – heuristic h(n) = estimated cost from n to goal
e.g., hSLD(n) = straight‐line distance from n to BucharestNote: hSLD(n) ≥ 0 for all n; hSLD(Bucharest) = 0
Greedy best‐first search expands the node that appears to be closest to goal Goal‐test: upon generation = upon expansion
8
Properties of greedy search
Complete? TREE‐SEARCH: No; 1GRAPH‐SEARCH: Yes (in finite state spaces)
Optimal? No
Time? O(bm) (but a good heuristic can give dramatic improvement)
Space? O(bm) (keeps all nodes in memory)
Properties similar to DFS without space benefit; behaviour not necessarily
1 consider e.g. finding a path from Neamt to Fagaras with SLD heuristic, then Iasi Neamt Iasi Neamt… since from Iasi neighbour Neamt is closer to Fagaras than neighbour Vaslui
13
A* search
Combines benefits of greedy best‐first search and uniform‐cost search
Evaluation function f(n) = g(n) + h(n)where– g(n) = cost so far to reach n (= path cost; dynamic)– h(n) = estimated cost from n to goal (= static heuristic) f(n) = estimated total cost of path through n to goal
A* search avoids expanding paths that are already expensive
Goal‐test upon expansion!14
A* search example
Done, or continue?
19
For Bucharest: f(n) <> min f(n)g(n) <> min g(n)h(n) = 0
min g(n)
A* search example
Done, or continue?
20
min g(n)
For Bucharest: f(n) = min f(n)g(n) <> min g(n)h(n) = 0
A* vs Dijkstra: https://www.youtube.com/watch?v=g024lzsknDo
Admissible heuristics Definition: a heuristic h(n) is admissible if
h(n) ≤ h*(n) for every node n
where h*(n) is the optimal heuristic, i.e. gives true cost to reach the goal state from n.
An admissible heuristic never overestimates the actual cost to reach the goal, i.e., it is optimistic (property transfers to f(n))
Example: hSLD(n) (never overestimates the actual road distance)
Theorem: If h(n) is admissible then A* using TREE‐SEARCH is optimal
21
Optimality of A* (proof tree)Consider: Optimal goal G A fringe with (generated, but not yet expanded):
– suboptimal goal G2
– node n, on a shortest path to G
To prove: G2 will never be expanded before n.
First we show that f(G2) > f(G):1) f(G) = g(G) since h(G) = 0 2) f(G2) = g(G2) since h(G2) = 0 3) g(G2) > g(G) G2 suboptimal, so higher (path) costs f(G2) > f(G) from 1—3) 22
Optimality of A* (proof-cntd)Recall:G optimal; fringe with suboptimal G2 and n on shortest path to G
To prove: G2 will never be expanded before n.
Established: f(G2) > f(G)
Next we show that f(G2) > f(n):
1) h(n) ≤ h*(n) assumption h is admissible↔ h(n) + g(n) ≤ h*(n) + g(n) add g(n) to both sides↔ f(n) ≤ g(G) n on shortest path to G; def f
2) f(G) = g(G) + 0 h(G) = 0; def f f(G) ≥ f(n) 1,2
Hence f(G2) > f(n), and A* will never select G2 for expansion 23
Consistent heuristics A heuristic is consistent (or monotonic) if for every node n
and every successor n' of n, generated by any action a :
h(n) ≤ c(n,a,n') + h(n') where c(n,a,n') is the step cost
If h is consistent, we have
f(n') = g(n') + h(n') (def)= g(n) + c(n,a,n') + h(n') ≥ g(n) + h(n) (consistent)= f(n) (def)
i.e., f(n) is non‐decreasing along any path.
Intuition: h should be optimistic, but not to the extent thattotal costs f can drop by taking a next step
24
Optimality of A* (again)Theorem: If h(n) is consistent, A* using GRAPH‐SEARCH is optimal
A* expands nodes in order of increasing f value
Gradually adds "f‐contours" of nodes Contour fc has all nodes n with f(n) ≤ c
Contoursf380f400f420
25
Properties of A*
Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) = f *)
Optimal? Yes(if heuristic is consistent (GRAPH) /admissible (TREE) )
Time? Exponential in d
Space? Keeps all nodes in memory
26
Admissible heuristicsRecall the properties of (admissible) heuristic h: h(goal node) = 0 0 ≤ h(n) ≤ h*(n) for every node n
(admissible: should never overestimate!)
E.g., two common heuristics 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 (only horizontal and vertical moves!!)))
h1(Start) = ? h2(Start) = ?
27
Admissible heuristics
E.g., two common heuristics for the 8‐puzzle: h1(n) = number of misplaced tiles h2(n) = total Manhattan distance
h1(Start) = 8 h2(Start) = 3+1+2+2+2+3+3+2 = 18
28
Which is better? - Dominance
If h2(n) ≥ h1(n) for all n (and both admissible)then h2 dominates h1
h2 is better for search
Typical search costs (average number of nodes expanded over 100 instances of 8‐puzzle per solution length d ):
d=12 IDS = 3,644,035 nodesA*(h1) = 227 nodes A*(h2) = 73 nodes
d=24 IDS = too many nodesA*(h1) = 39,135 nodes A*(h2) = 1,641 nodes
29
Good heuristics
h*(n) ≥ h(n) ≥ 0 for all n (h is admissible)
The closer h is to h*, the less nodes are kept open for search (more efficient)
If h(n)=h(n)* for all n then A* leads direct to optimal solution without search
If h(n)=0 for all n then A* is uniform cost search (= Dijkstra’s algorithm + goal test)
However, if h is not admissible then optimal solution can be missed!
30
Relaxed problemsRelaxed problem: a problem with fewer restrictions on the actions
E.g. allow moves to occupied slots in 8‐puzzle
The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem
If the rules of the 8‐puzzle are further relaxed so that
a tile can move anywhere in one step
h1(n) gives the best (shortest) solution
a tile can move to any adjacent square
h2(n) gives the shortest solution31
Variations on A*
Hierarchical A* IDA* (Iterative Deepening A*) SMA* (Simplified Memory‐bounded A*)
Specific for dynamic environments: LPA* (Lifelong Planning A*) D* (A* for dynamic goals)
32
33
Summary best-first search
Similar to uninformed search: tree/graph search goal‐test step & path costs solution = (least‐cost) path through state‐
space
more problem specific ingredients(beyond definition of problem):
Heuristic function h(n) Evaluation function f(n)
Local search algorithmsIn many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution
State space = set of "complete‐state” configurations(rather than partial/incremental)
Search: find configuration satisfying constraintse.g. n‐queens
In such cases, we can use local search algorithms
keep a single "current" state, and try to improve it by moving to neighboring states
find goal state, or state that optimizes someobjective function (an evaluation function)
34
Example: TSP
Which is the shortest route that visits all cities exactly once,and returns at the starting point?
A
B C
DE
35
Hill-climbing search No search tree Terminates when it reaches “peak” (steepest‐ascent version) No look‐ahead beyond immediate neighbors (aka greedy local
search)
"Like climbing Everest in thick fog with amnesia"
# VALUE = value from objective function
36
Hill-climbing: 8-queens problem
h = # of pairs of queens that attack each other, either directly or indirectly h = 17 for the above state squares show h(neighbors)
Objective: h=0 (minimization: gradient descent)38
Simulated annealing search Combines hill‐climbingwith random walk Idea: escape local max/min by allowing some “random"
moves (‘shake’) but gradually decrease their frequency and ‘intensity’
40
Simulated annealing search
Property: if T decreases slowly enough, a global optimum is found with probability approaching 1
Widely used in VLSI layout, airline scheduling, etc
# instead of best
# possibly try worse anyway
# T decreases over time!
# go if better
41
Local beam search
Keep track of k states in memory rather than just one
Start with k randomly generated states
At each iteration, all the successors of all k states are generated
If any one is a goal state, stop; else select the k best successors from the complete list and repeat.
“Come on over here, the grass is greener!”
42
Genetic algorithms
A successor state is generated by combining two parent states
Start with k randomly generated states (population)
A state (or, individual) is represented as a string over a finite alphabet (often a string of 0s and 1s)
Objective function (or, fitness function): higher values for better states.
Produce the next generation of states by selection, crossover, and mutation
43
Summary Informed Search
Use domain knowledge to guide search towards goal. If path to goal is relevant:
– best first search
If only finding the goal is relevant: – local search
What about ?: search vs optimization vs learning
44