Artificial Intelligence Informed Search and Exploration Chapter 4 (4.1 4.2) A General Search algorithm: Chapter 3: Search Strategies Task : Find a sequence of actions leading from the initial state to a goal state 1. Initialize the search tree with the initial state. 2. Report failure if search tree is empty 3. Move to a leaf node according to a strategy 4. Ready if a goal state. 5. Expand the current state by generating successors to the current state. Add them to the search tree as leaves. 6. Repeat from 2. Chapter 3: Search Strategies Uninformed search: Use only information available in the problem formulation Breadth-first Uniform-cost Depth-first Depth-limited Iterative deepening Chapter 4: Informed Search and Exploration Informed search: Use heuristics to guide the search Best first search Greedy search A* search Local search and Optimization: Hill-climbing Simulated annealing Genetic algorithm Informed Search Searching in Large Problems We talked about building goal-based agents using search strategies But the strategies we discussed were uninformed because the agent is given nothing more than the problem definition Now informed search strategies Some search spaces of problems are too large to search efficiently using uninformed methods Sometimes we have additional domain knowledge about the problem that we can use to inform the agent that is searching Often there is extra knowledge that can be used to guide the search: To do this, we use heuristics (informed guesses) Heuristic means serving to aid discovery 1
Best-First Search (BeFS) The General search algorithm can handle an evaluation function that controls which leaf node to expand This function returns a number describing the desirability of expanding the node A Best-first search uses the following strategy to select next leaf node: Move to the node with best value of the evaluation function Best-First Search Best-first search is a generic informed search strategy that uses an evaluation function f(n), incorporating some kind of domain knowledge The leaf nodes are normally collected in a queue for reasons of efficiency The queue is kept ordered according to the value on the evaluation function f(n) is used to sort states in the open list using a priority queue (like UCS) Best-First (??) Search Best-First Search General Search algorithm: 1. Set N to be a sorted list of initial nodes. 2. If N is empty, then exit and signal failure. 3. Set n to be the first node in N, and remove n from N. 4. If n is a goal node, then exit and signal success. 5. Otherwise, add the children of n to N, sort the nodes in N according to the value on their evaluation function, and return to step 2. Special cases: Greedy search A* search Heuristic Searching Heuristic Searching We define a heuristic function h(n): Is computed from the state at node n Uses domain-specific information in some way Heuristics can estimate the goodness of a particular node (or state) n: How close is n to a goal node? What might be the minimal cost path from n to a goal node? We will formalize a heuristic function h(n) as follows: h(n) 0 for all nodes n h(n) = 0 implies that n is a goal node h(n) = implies that n is a dead end from which a goal cannot be reached 2
Greedy Search Greedy Search Greedy search is the best-first search strategy, with a simple evaluation function of f(n) = h(n) Estimation function: h(n) = estimate of cost from n to goal (heuristic) It relies only on the heuristic to select what is currently believed to be closest to the goal state Greedy search minimizes the estimated cost to the goal Incomplete: can start down an infinite path and never return. Not optimal: minimizes cost one step ahead only For example: h SLD (n) = straight-line distance from n to Bucharest Greedy search expands first the node that appears to be closest to the goal, according to h(n) Romania with h SLD in km Greedy Search Example Greedy Search Example Greedy Search Example 3
Greedy Search Example Greedy Search Example Minimal? Optimal? Minimal? Yes Optimal? No Romania with h SLD in km Greedy Search Issues Greedy Search is generally faster than the uninformed methods It has more knowledge about the problem domain! Resembles DFS in that it tends to follow a path that is initially good, and Properties of Greedy Search A* Search Complete? Time? No can get stuck in loops e.g., Iasi > Neamt > Iasi > Neamt > Complete in finite space with repeated- state checking O(b m ) but a good heuristic can give dramatic improvement Idea: avoid expanding paths that are already expensive Uniform-cost search, minimize the cost of the path so far, g(n), it is optimal and complete, but can be very inefficient We combine Uniform-cost search and Greedy search to get the advantages of both Space? O(b m ) keeps all nodes in memory Optimal? No (a better solution could exist through an expensive node) Evaluation function: f(n) = g(n) + h(n) with: g(n) cost so far to reach n h(n) estimated cost to goal from n f(n) estimated cheapest total cost of path through n to goal 4
Heuristic Functions Admissible Heuristics Heuristic functions are good for helping us find good solutions quickly But it is difficult to design accurate heuristics! They can be expensive to compute They can make errors estimating the costs These problems keep informed searches like the A* search from being complete and optimal There is hope! We can add a constraint on our heuristic function h(n) is called a admissible if it never overestimates the cost to the goal from node n A* search uses an admissible heuristic, that is, h(n) h*(n) where h*(n) is the true cost to the goal from n For example: h SLD (n) never overestimates actual road distance Theorem: A* search is optimal A* Search Algorithm A* Search Algorithm The leaf nodes are normally collected in a queue The queue is kept sorted according to the value on the evaluation function f(n)=g(n)+h(n) Order the nodes in the fringe in increasing values of f(n) 1. Set N to be the start node. 2. If N is empty, then exit and signal failure. 3. Set n to be the first node in N, and remove n from N. 4. If n is a goal node, then exit and signal success. 5. Otherwise, add the children of n to N, sort the nodes in N according to the value on their f(n), and return to step 2. Properties of A* Search Properties of A* Search When we conduct an A search using an admissible heuristic, it is called A* search Complete? Yes, unless infinitely many nodes with f f(g) A* search is complete if The branching factor is finite Every action has a fixed cost A* search is optimal provided that h(n) never overestimates the cost to reach the goal Very good search method, but with complexity problems Time? Space? Optimal? Exponential in [(relative error in h) x (length of solution)] Keeps all nodes in memory Yes cannot expand f i+1 until f i is finished 5
Romania with Step Costs in km A* Search Example A* Search Example A* Search Example A* Search Example A* Search Example 6
A* Search Example Optimality of A* (standard proof) Suppose some suboptimal goal G 2 has been generated and is in the queue. Let n be an unexpanded node on a shortest path to an optimal goal G 1. Memory Bounded Search Devising Heuristics Iterative Deepening A* (IDA*) Simplified Memory Bounded A* (SMA*) Often done by relaxing the problem See AIMA2e for more details The goal of admissible heuristics is to get as close as possible to the actual cost without going over Trade-off: A really good h(n) might be expensive to compute Could we find the solution faster with a simpler one? Devising Heuristics Devising Heuristics If h(n) = h*(n) for all n: Only nodes on optimal solution are searched No unnecessary work We know the actual cost from n to goal If h(n) = 0 for all n: Heuristic is still admissible A* is identical to UCS If h 1 (n) h 2 (n) h*(n) for each non-goal node n: We say h 2 dominates h 1 h 2 is closer to actual cost, but is still admissible A* using h 1 (i.e. A 1 *) expands at least as many, if not more nodes than A 2 * A 2 * is said to be better informed than A 1 * The closer h is to h*, the fewer nodes will need to be expanded; the more accurate the search will be 7
Devising Heuristics If h 1 (n) h 2 (n) h*(n) for each non-goal node n: We say h 2 dominates h 1 h 2 is closer to actual cost, but is still admissible A* using h 1 (i.e. A 1 *) expands at least as many, if not more nodes than A 2 * A 2 * is said to be better informed than A 1 * Exemple: 8-puzzle!! When to Use Search Techniques? The search space is small, and There is no other available techniques, or It is not worth the effort to develop a more efficient technique The search space is large, and There is no other available techniques, and There exist good heuristics Summary Summary Heuristic function Greedy search Admissible heuristic and A* IDA* SMA* Devising Heuristic A* is complete and optimal Summary Best-first search = general search, where the minimum-cost nodes (according to some measure) are expanded first Greedy search = best-first with the estimated cost to reach the goal as a heuristic measure - Generally faster than uninformed search - not optimal -not complete A* search = best-first with measure = path cost so far + estimated path cost to goal - combines advantages of uniform-cost and greedy searches - complete, optimal and optimally efficient - space complexity still exponential Next Time! Iterative improvement Hill climbing Simulated annealing Genetic Algorithm 8