530 likes | 644 Views
CS 416 Artificial Intelligence. Lecture 5 Finish Uninformed Searches Begin Informed Searches. Uniform-cost search (review). Always expand the lowest-path-cost node Don’t evaluate the node until it is “expanded”… not when it is the result of expansion. Uniform-cost search (review).
E N D
CS 416Artificial Intelligence Lecture 5 Finish Uninformed Searches Begin Informed Searches
Uniform-cost search (review) • Always expand the lowest-path-cost node • Don’t evaluate the node until it is “expanded”… not when it is the result of expansion
Uniform-cost search (review) • Fringe = [S0] • Expand(S) {A1, B5, C15} B
Uniform-cost search (review) • Fringe = [A1, B5, C15] • Expand(A) = {G11}
Uniform-cost search (review) • Fringe = [B5, G11, C15] • Expand(B) {G10}
Uniform-cost search (review) • Fringe = [G10, C15] • Expand(G) Goal
Bidirectional search • Search from goal to start • Search from start to goal • Two bd/2 searches instead of one bd
Bidirectional search • Implementation • Each search checks nodes before expansion to see if they are on the fringe of the other search
Bidirectional search • Example: Bidirectional BFS search with d=6 & b=10 • Worst case: both search trees must expand all but one element of the third level of the tree • 2* (1 + 10 + 100 + 1000 + 10000 - 10) node expansions • Versus 1 * (1 + 10 + 100 + … + 10000000) expansions
Bidirectional search • Implementation • Checking fringe of other tree • At least one search tree must be kept in memory • Checking can be done in constant time (hash table) • Searching back from goal • Must be able to compute predecessors to node n: Pred (n) • Easy with 15-puzzle, but how about chess?
Avoid repeated states • Search algorithms that forget their history are doomed to repeat it.Russell and Norvig • So remember where you’ve been… on a list • If you come upon a node you’ve visited before, don’t expand it • Let’s call this GRAPH-SEARCH
GRAPH-SEARCH • Faster and smaller space requirements if many repeating states • Time-space requirements are a function of state space not depth/branching of tree to goal • At this point in class, repeated states will be thrown away – even if the new path to the state is better than the one explored previously
Interesting problems • Exercise 3.9: • 3 cannibals and 3 missionaries and a boat that can hold one or two people are on one side of the river. Get everyone across the river (early AI problem, 1968) • 8-puzzle and 15-puzzle, invented by Sam Loyd in good ol’ USA in 1870s. Think about search space. • Rubik’s cube • Traveling Salesman Problem (TSP)
Chapter 4 – Informed Search • INFORMED? • Uses problem-specific knowledge beyond the definition of the problem itself • selecting best lane in traffic • playing a sport • what’s the heuristic (or evaluation function)? www.curling.ca
Best-first search • BFS/DFS/UCS differ in how they select a node to pull off the fringe • We want to pull off the fringe the node that’s on the optimal path • But if we know the “best” node to explore, we don’t have to search!!! We’re not certain we know the best node
Best-first search • Use an evaluation function to select node to expand • f(n) = evaluation function = expected “cost” for a path from root to goal that goes through node n • Select the node n on fringe that minimizes f(n) • How do we build f(n)?
Evaluation function: f(n) • Combine two costs • f(n) = g(n) + h(n) • g(n) = cost to get to n from start We know this! • h(n) = cost to get to from n to goal
Heuristics • A function, h(n), that estimates cost of cheapest path from node n to the goal • h(n) = 0 if n == goal node
Greedy best-first search • Trust your heuristic and ignore path costs • evaluate node that minimizes h(n) • f(n) = h(n) • Example: getting from A to B • Explore nodes with shortest straight distance to B • Shortcomings of heuristic? • Greedy can be bad
A* (A-star) Search • Don’t simply minimize the cost to goal… minimize the cost from start to goal… • f(n) = g(n) + h(n) • g(n) = cost to get to n from start • h(n) = cost to get from n to goal • Select node from fringe that minimizes f(n)
A* is Optimal? • A* can be optimal if h(n) satisfies conditions • h(n) never overestimates cost to reach the goal • it is eternally optimistic • called anadmissible heuristic • f(n) never overestimates cost of a solution through n • Proof of optimality?
A* is Optimal • We must prove that A* will not return a suboptimal goal or a suboptimal path to a goal • Let G be a suboptimal goal node • f(G) = g(G) + h(G) • h(G) = 0 because G is a goal node and we cannot overestimate actual cost to reach G • f(G) = g(G) > C* (because G is suboptimal)
A* is Optimal (cont.) • Let n be a node on the optimal path • because h(n) does not overestimate • f(n) = g(n) + h(n) <= C* • Therefore f(n) <= C* < f(G) • node n will be selected before node G A* is optimal if h() is admissible
Repeated States and GRAPH-SEARCH • GRAPH-SEARCH always ignores all but the first occurrence of a state during search • Lower cost path may be tossed • So, don’t throw away subsequent occurrences • Or, ensure that the optimal path to any repeated state is always the first one followed • Additional constraint on heurisitic, consistency
Consistent heuristic: h(n) • Heuristic function must be monotonic • for every node, n, and successor,n’, obtained with action a • estimated cost of reaching goal from n is no greater than cost of getting to n’ plus estimated cost of reaching goal from n’ • h(n) <= c(n, a, n’) + h(n’) • This implies f(n) along any path are nondecreasing
Examples of consistent h(n) • h(n) <= c(n, a, nsucc) + h(nsucc) • recall h(n) is admissible • The quickest you can get there from here is 10 minutes • It may take more than 10 minutes, but not fewer • After taking an action and learning the cost • It took you two minutes to get here and you still have nine minutes to go • We cannot learn… it took you two minutes to get here and you have seven minutes to go 10 0 2 10 9
Example of inconsistent h(n) • As a thought exercise for after class • Consider what happens when a heuristic is inconsistent • Consider how one could have a consistent but non-admissible heuristic
Proof of monotonicity of f(n) • If h(n) is consistent (monotonic) • then f(n) along any path is nondecreasing • let n’ be a successor of n • g(n’) = g(n) + c (n, a, n’) for some a • f(n’) = g(n’) + h(n’) = g(n) + c(n, a, n’) + h(n’) >= g(n) + h(n) = f(n) monotonicity impliesh(n) <= c(n, a, n’) + h(n’)
Contours • Because f(n) is nondecreasing • we can draw contours • If we know C* • We only need to explore contours less than C*
Properties of A* • A* expands all nodes with f(n) < C* • A* expands some (at least one) of the nodes on the C* contour before finding the goal • A* expands no nodes with f(n) > C* • these unexpanded nodes can be pruned
A* is Optimally Efficient • Compared to other algorithms that search from root • Compared to other algorithms using same heuristic • No other optimal algorithm is guaranteed to expand fewer nodes than A*(except perhaps eliminating consideration of ties at f(n) = C*)
Pros and Cons of A* • A* is optimal and optimally efficient • A* is still slow and bulky (space kills first) • Number of nodes grows exponentially with the length to goal • This is actually a function of heuristic, but they all have errors • A* must search all nodes within this goal contour • Finding suboptimal goals is sometimes only feasible solution • Sometimes, better heuristics are non-admissible
Memory-bounded Heuristic Search • Try to reduce memory needs • Take advantage of heuristic to improve performance • Iterative-deepening A* (IDA*) • Recursive best-first search (RBFS) • SMA*
Iterative Deepening A* • Iterative Deepening • Remember from uninformed search, this was a depth-first search where the max depth was iteratively increased • As an informed search, we again perform depth-first search, but only nodes with f-cost less than or equal to smallest f-cost of nodes expanded at last iteration • What happens when f-cost is real-valued?
Recursive best-first search • Depth-first combined with best alternative • Keep track of options along fringe • As soon as current depth-first exploration becomes more expensive of best fringe option • back up to fringe, but update node costs along the way
Quality of Iterative Deepening A* and Recursive best-first search • RBFS • O(bd) space complexity [if h(n) is admissible] • Time complexity is hard to describe • efficiency is heavily dependent on quality of h(n) • same states may be explored many times • IDA* and RBFS use too little memory • even if you wanted to use more than O(bd) memory, these two could not provide any advantage
Simple Memory-bounded A* • Use all available memory • Follow A* algorithm and fill memory with new expanded nodes • If new node does not fit • free() stored node with worst f-value • propagate f-value of freed node to parent • SMA* will regenerate a subtree only when it is needed • the path through deleted subtree is unknown, but cost is known
Thrashing • Typically discussed in OS w.r.t. memory • The cost of repeatedly freeing and regenerating parts of the search tree dominate the cost of actual search • time complexity will scale significantly if thrashing • So we saved space with SMA*, but if the problem is large, it will be intractable from the point of view of computation time
Meta-foo • What does meta mean in AI? • Frequently it means step back a level from foo • Metareasoning = reasoning about reasoning • These informed search algorithms have pros and cons regarding how they choose to explore new levels • a metalevel learning algorithm may combine learn how to combine techniques and parameterize search
Heuristic Functions • 8-puzzle problem Avg Depth=22 Branching = approx 3 322 states 170,000 repeated
Heuristics • The number of misplaced tiles (h1) • Admissible because at least n moves required to solve n misplaced tiles • The distance from each tile to its goal position (h2) • No diagonals, so use Manhattan Distance • As if walking around rectilinear city blocks • also admissible
Compare these two heuristics • Effective Branching Factor, b* • If A* creates N nodes to find the goal at depth d • b* = branching factor such that a uniform tree of depth d contains N+1 nodes (add 1 to N to account for root) • N+1 = 1 + b* + (b*)2 + … + (b*)d • b* close to 1 is ideal • because this means the heuristic guided the A* search linearly • If b* were 100, on average, the heuristic had to consider 100 children for each node • Compare heuristics based on their b*
Compare these two heuristics • h2 is always better than h1 • for any node, n, h2(n) >= h1(n) • h2dominates h1 • Recall all nodes with f(n) < C* will be expanded? • This means all nodes, h(n) + g(n) < C*, will be expanded • All nodes where h(n) < C* - g(n) will be expanded • All nodes h2 expands will also be expanded by h1 and because h1 is smaller, others will be expanded as well
Inventing admissible heuristic funcs • How can you create h(n)? • Simplify problem by reducing restrictions on actions • Allow 8-puzzle pieces to sit atop on another • Call this a relaxed problem • The cost of optimal solution to relaxed problem is admissible heuristic for original problem • It is at least as expensive for the original problem
Examples of relaxed problems • A tile can move from square A to square B if • A is horizontally or vertically adjacent to B • and B is blank • A tile can move from A to B if A is adjacent to B (overlap) • A tile can move from A to B if B is blank (teleport) • A tile can move from A to B (teleport and overlap) • Solutions to these relaxed problems can be computed without search and therefore heuristic is easy to compute
Multiple Heuristics • If multiple heuristics available: • h(n) = max {h1(n), h2(n), …, hm(n)}