CSE 473: Artificial Intelligence Spring 2012

Slides:



Advertisements
Similar presentations
Informed search algorithms
Advertisements

Informed search algorithms
Review: Search problem formulation
Informed search algorithms
An Introduction to Artificial Intelligence
Solving Problem by Searching
1 Heuristic Search Chapter 4. 2 Outline Heuristic function Greedy Best-first search Admissible heuristic and A* Properties of A* Algorithm IDA*
Problem Solving by Searching
Review: Search problem formulation
CS 188: Artificial Intelligence Fall 2009 Lecture 3: A* Search 9/3/2009 Dan Klein – UC Berkeley Multiple slides from Stuart Russell or Andrew Moore.
Informed Search Methods Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 4 Spring 2005.
Cooperating Intelligent Systems Informed search Chapter 4, AIMA.
CS 460 Spring 2011 Lecture 3 Heuristic Search / Local Search.
Informed Search CSE 473 University of Washington.
Problem Solving and Search in AI Heuristic Search
Review Best-first search uses an evaluation function f(n) to select the next node for expansion. Greedy best-first search uses f(n) = h(n). Greedy best.
CSC344: AI for Games Lecture 4: Informed search
Heuristics CSE 473 University of Washington. © Daniel S. Weld Topics Agency Problem Spaces SearchKnowledge Representation Planning PerceptionNLPMulti-agentRobotics.
Rutgers CS440, Fall 2003 Heuristic search Reading: AIMA 2 nd ed., Ch
Informed Search Idea: be smart about what paths to try.
Vilalta&Eick: Informed Search Informed Search and Exploration Search Strategies Heuristic Functions Local Search Algorithms Vilalta&Eick: Informed Search.
Informed search algorithms
Informed (Heuristic) Search
Informed search algorithms
Informed search algorithms Chapter 4. Outline Best-first search Greedy best-first search A * search Heuristics.
1 Shanghai Jiao Tong University Informed Search and Exploration.
Quiz 1 : Queue based search  q1a1: Any complete search algorithm must have exponential (or worse) time complexity.  q1a2: DFS requires more space than.
CSE 573: Artificial Intelligence Autumn 2012 Heuristic Search With slides from Dan Klein, Stuart Russell, Andrew Moore, Luke Zettlemoyer Dan Weld.
Informed search algorithms Chapter 4. Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most.
ISC 4322/6300 – GAM 4322 Artificial Intelligence Lecture 3 Informed Search and Exploration Instructor: Alireza Tavakkoli September 10, 2009 University.
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select.
Informed searching. Informed search Blind search algorithms do not consider any information about the states and the goals Often there is extra knowledge.
Chapter 4 Informed/Heuristic Search
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
Lecture 3: Uninformed Search
Heuristic Search Andrea Danyluk September 16, 2013.
Advanced Artificial Intelligence Lecture 2: Search.
CSE 573: Artificial Intelligence Autumn2012 Heuristics & Pattern Databases for Search With many slides from Dan Klein, Richard Korf, Stuart Russell, Andrew.
Informed Search and Heuristics Chapter 3.5~7. Outline Best-first search Greedy best-first search A * search Heuristics.
4/11/2005EE562 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 4, 4/11/2005 University of Washington, Department of Electrical Engineering Spring 2005.
A General Introduction to Artificial Intelligence.
Feng Zhiyong Tianjin University Fall  Best-first search  Greedy best-first search  A * search  Heuristics  Local search algorithms  Hill-climbing.
Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most desirable unexpanded node Implementation:
Informed Search CSE 473 University of Washington.
Problem Spaces & Search Dan Weld CSE 573. © Daniel S. Weld 2 Logistics Read rest of R&N chapter 4 Also read chapter 5 PS 1 will arrive by , so be.
Searching for Solutions
CE 473: Artificial Intelligence Autumn 2011 A* Search Luke Zettlemoyer Based on slides from Dan Klein Multiple slides from Stuart Russell or Andrew Moore.
CSE 473: Artificial Intelligence Spring 2012 Search: Cost & Heuristics Luke Zettlemoyer Lecture adapted from Dan Klein’s slides Multiple slides from Stuart.
Chapter 3.5 and 3.6 Heuristic Search Continued. Review:Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
CPSC 420 – Artificial Intelligence Texas A & M University Lecture 5 Lecturer: Laurie webster II, M.S.S.E., M.S.E.e., M.S.BME, Ph.D., P.E.
Reading Material Sections 3.3 – 3.5 Sections 4.1 – 4.2 “Optimal Rectangle Packing: New Results” By R. Korf (optional) “Optimal Rectangle Packing: A Meta-CSP.
CMPT 463. What will be covered A* search Local search Game tree Constraint satisfaction problems (CSP)
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Review: Tree search Initialize the frontier using the starting state
Logistics Problem Set 1 Mailing List Due 10/13 at start of class
Artificial Intelligence Problem solving by searching CSC 361
Discussion on Greedy Search and A*
Discussion on Greedy Search and A*
CAP 5636 – Advanced Artificial Intelligence
CS 4100 Artificial Intelligence
Heuristics Local Search
Heuristics Local Search
CSE 473 University of Washington
CS 188: Artificial Intelligence Fall 2006
Announcements This Friday Project 1 due Talk by Jeniya Tabassum
HW 1: Warmup Missionaries and Cannibals
Informed Search Idea: be smart about what paths to try.
Heuristic Search Generate and Test Hill Climbing Best First Search
HW 1: Warmup Missionaries and Cannibals
Informed Search Idea: be smart about what paths to try.
Presentation transcript:

CSE 473: Artificial Intelligence Spring 2012 Heuristics & Pattern Databases for Search Dan Weld Change the three pac man slides so students can see each one in turn and then decide which is which With many slides from Dan Klein, Richard Korf, Stuart Russell, Andrew Moore, & UW Faculty

Recap: Search Problem States Successor function: Start state Goal test configurations of the world Successor function: function from states to lists of (state, action, cost) triples Start state Goal test

General Tree Search Paradigm function tree-search(root-node) fringe  successors(root-node) while ( notempty(fringe) ) {node  remove-first(fringe) state  state(node) if goal-test(state) return solution(node) fringe  insert-all(successors(node),fringe) } return failure end tree-search

Extra Work? Failure to detect repeated states can cause exponentially more work (why?)

General Graph Search Paradigm function tree-search(root-node) fringe  successors(root-node) explored  empty while ( notempty(fringe) ) {node  remove-first(fringe) state  state(node) if goal-test(state) return solution(node) explored  insert(node,explored) fringe  insert-all(successors(node),fringe, if node not in explored) } return failure end tree-search

Some Hints Graph search is almost always better than tree search (when not?) Implement your closed list as a dict or set! Nodes are conceptually paths, but better to represent with a state, cost, last action, and reference to the parent node

Informed (Heuristic) Search Idea: be smart about what paths to try.

Blind Search vs. Informed Search What’s the difference? How do we formally specify this? A node is selected for expansion based on an evaluation function that estimates cost to goal.

Best-First Search Use an evaluation function f(n) for node n. Always choose the node from fringe that has the lowest f value. Fringe = priority queue 3 5 1 4 6

Uniform Cost Search f(n) = cost from root The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information about goal location … c  1 c  2 c  3 Start Goal

Greedy Search f(n) = estimate of cost from n to goal A common case: Takes you straight to the (wrong) goal Worst-case: like a badly-guided DFS b … b … For any search problem, you know the goal. Now, you have an idea of how far away you are from the goal.

A* search f(n) = estimated total cost of path thru n to goal f(n) = g(n) + h(n) g(n) = cost so far to reach n h(n) = estimated cost from n to goal (satisfying some important conditions)

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

Consistent Heuristics h(n) is consistent if for every node n for every successor n´ due to legal action a h(n) <= c(n,a,n´) + h(n´) Every consistent heuristic is also admissible. Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal n h(n) c(n,a,n´) h(n´) n´ G

When should A* terminate? Should we stop when we enqueue a goal? A 2 2 h = 2 G S h = 3 h = 0 B 3 2 h = 1 No: only stop when we dequeue a goal

Optimality of A*: Blocking Notation: g(n) = cost to node n h(n) = estimated cost from n to the nearest goal (heuristic) f(n) = g(n) + h(n) = estimated total cost via n G*: a lowest cost goal node G: another goal node …

Optimality of A*: Blocking Proof: What could go wrong? We’d have to have to pop a suboptimal goal G off the fringe before G* … This can’t happen: For all nodes n on the best path to G* f(n) < f(G) So, G* will be popped before G

Which Algorithm? 18

Which Algorithm?

Which Algorithm?

Which Algorithm? Uniform cost search (UCS): 21

Which Algorithm? A*, Manhattan Heuristic:

Which Algorithm? Best First / Greedy, Manhattan Heuristic:

Properties of A* Uniform-Cost A* b b … …

UCS vs A* Contours Uniform-cost expanded in all directions A* expands mainly toward the goal, but does hedge its bets to ensure optimality Start Goal python pacman.py -p SearchAgent -l contoursMaze --frameTime -1 -a heuristic=manhattanHeuristic,fn=astar Start Goal

Iterative-Deepening A* Like iterative-deepening depth-first, but... Depth bound modified to be an f-limit Start with f-limit = h(start) Prune any node if f(node) > f-limit Next f-limit = min-cost of any node pruned FL=21 e FL=15 d a f b c

IDA* Analysis Complete & Optimal (ala A*) Space usage  depth of solution Each iteration is DFS - no priority queue! # nodes expanded relative to A* Depends on # unique values of heuristic function In 8 puzzle: few values  close to # A* expands In traveling salesman: each f value is unique  1+2+…+n = O(n2) where n=nodes A* expands if n is too big for main memory, n2 is too long to wait! Generates duplicate nodes in cyclic graphs

Forgetfulness A* used exponential memory How much does IDA* use? During a run? In between runs? © Daniel S. Weld

SMA* Use all available memory Start like A* When memory is full… Erase node with highest f-value First, backup parent with this f-value So… parent knows cost-bound on best child © Daniel S. Weld

Alternative Approach to Finite Memory… Optimality is nice to have, but… © Daniel S. Weld

Depth-First Branch & Bound Single DF search  uses linear space Keep track of best solution so far If f(n) = g(n)+h(n)  cost(best-soln) Then prune n Requires Finite search tree, or Good upper bound on solution cost Generates duplicate nodes in cyclic graphs Tradeoff: Prune space, but… Must apply test to each node © Daniel S. Weld Adapted from Richard Korf presentation

Beam Search Idea Evaluation Best first but only keep N best items on priority queue Evaluation Complete? Time Complexity? Space Complexity? No O(b^d) O(b + N) © Daniel S. Weld

Hill Climbing Idea Problems? Local maxima Plateaus Diagonal ridges “Gradient ascent” Idea Always choose best child; no backtracking Beam search with |queue| = 1 Problems? Local maxima Plateaus Diagonal ridges © Daniel S. Weld

Randomizing Hill Climbing Randomly disobeying heuristic Random restarts ( heavy tailed distributions )  Local Search © Daniel S. Weld

Simulated Annealing Objective: avoid local minima Technique: For the most part use hill climbing When no improvement possible Choose random neighbor Let  be the decrease in quality Move to neighbor with probability e --/T Reduce “temperature” (T) over time Pros & cons Optimal? If T decreased slowly enough, will reach optimal state Widely used See also WalkSAT temp © Daniel S. Weld

It’s what makes search actually work Heuristics It’s what makes search actually work

Admissable Heuristics f(x) = g(x) + h(x) g: cost so far h: underestimate of remaining costs Where do heuristics come from? © Daniel S. Weld

Relaxed Problems Derive admissible heuristic from exact cost of a solution to a relaxed version of problem For transportation planning, relax requirement that car has to stay on road  Euclidean dist For blocks world, distance = # move operations heuristic = number of misplaced blocks What is relaxed problem? # out of place = 2, true distance to goal = 3 Cost of optimal soln to relaxed problem  cost of optimal soln for real problem

What’s being relaxed?

Example: Pancake Problem Action: Flip over the top n pancakes Gates, W. and Papadimitriou, C., "Bounds for Sorting by Prefix Reversal.", Discrete Mathematics. 27, 47-57, 1979. Cost: Number of pancakes flipped

Example: Pancake Problem Gates, W. and Papadimitriou, C., "Bounds for Sorting by Prefix Reversal.", Discrete Mathematics. 27, 47-57, 1979.

Example: Pancake Problem State space graph with costs as weights 4 2 3 2 3 4 3 4 2 A* expanded 8100 ; Path cost = 33 UCS expanded 25263 . Path cost = 33 Greedy expanded 10 . Path cost = 41 [0, 7, 5, 3, 2, 1, 4, 6] (7, 0, 5, 3, 2, 1, 4, 6) (6, 4, 1, 2, 3, 5, 0, 7) (3, 2, 1, 4, 6, 5, 0, 7) (1, 2, 3, 4, 6, 5, 0, 7) (5, 6, 4, 3, 2, 1, 0, 7) (6, 5, 4, 3, 2, 1, 0, 7) (0, 1, 2, 3, 4, 5, 6, 7) 3 2 2 3 4 3

Example: Heuristic Function Heuristic: the largest pancake that is still out of place 4 3 2 h(x) A* expanded 8100 ; Path cost = 33 UCS expanded 25263 . Path cost = 33 Greedy expanded 10 . Path cost = 41 [0, 7, 5, 3, 2, 1, 4, 6] (7, 0, 5, 3, 2, 1, 4, 6) (6, 4, 1, 2, 3, 5, 0, 7) (3, 2, 1, 4, 6, 5, 0, 7) (1, 2, 3, 4, 6, 5, 0, 7) (5, 6, 4, 3, 2, 1, 0, 7) (6, 5, 4, 3, 2, 1, 0, 7) (0, 1, 2, 3, 4, 5, 6, 7)

Traveling Salesman Problem What can be Relaxed?

Heuristics for eight puzzle 7 2 3 8 3 5 1 6 1 2 3 7 8 4 5 6  start goal What can we relax?

Importance of Heuristics 7 2 3 8 5 4 1 6 h1 = number of tiles in wrong place D IDS A*(h1) A*(h2) 2 10 6 6 4 112 13 12 6 680 20 18 8 6384 39 25 10 47127 93 39 12 364404 227 73 14 3473941 539 113 18 3056 363 24 39135 1641

Importance of Heuristics 7 2 3 8 5 4 1 6 h1 = number of tiles in wrong place h2 =  distances of tiles from correct loc D IDS A*(h1) A*(h2) 2 10 6 6 4 112 13 12 6 680 20 18 8 6384 39 25 10 47127 93 39 12 364404 227 73 14 3473941 539 113 18 3056 363 24 39135 1641 Decrease effective branching factor

Combining Admissible Heuristics Can always take max Adding does not preserve admissibility in general

Performance of IDA* on 15 Puzzle Random 15 puzzle instances were first solved optimally using IDA* with Manhattan distance heuristic (Korf, 1985). Optimal solution lengths average 53 moves. 400 million nodes generated on average. Average solution time is about 50 seconds on current machines.

Limitation of Manhattan Distance To solve a 24-Puzzle instance, IDA* with Manhattan distance would take about 65,000 years on average. Assumes that each tile moves independently In fact, tiles interfere with each other. Accounting for these interactions is the key to more accurate heuristic functions.

Example: Linear Conflict 3 1 1 3 Manhattan distance is 2+2=4 moves

Example: Linear Conflict 3 1 1 3 Manhattan distance is 2+2=4 moves

Example: Linear Conflict 3 1 3 1 Manhattan distance is 2+2=4 moves

Example: Linear Conflict 3 1 3 1 Manhattan distance is 2+2=4 moves

Example: Linear Conflict 3 1 3 1 Manhattan distance is 2+2=4 moves

Example: Linear Conflict 1 3 1 3 Manhattan distance is 2+2=4 moves

Example: Linear Conflict 1 3 1 3 Manhattan distance is 2+2=4 moves, but linear conflict adds 2 additional moves.

Linear Conflict Heuristic Hansson, Mayer, and Yung, 1991 Given two tiles in their goal row, but reversed in position, additional vertical moves can be added to Manhattan distance. Still not accurate enough to solve 24-Puzzle We can generalize this idea further.

Pattern Database Heuristics Culberson and Schaeffer, 1996 A pattern database is a complete set of such positions, with associated number of moves. e.g. a 7-tile pattern database for the Fifteen Puzzle contains 519 million entries.

Heuristics from Pattern Databases 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 31 moves is a lower bound on the total number of moves needed to solve this particular state.

Precomputing Pattern Databases Entire database is computed with one backward breadth-first search from goal. All non-pattern tiles are indistinguishable, but all tile moves are counted. The first time each state is encountered, the total number of moves made so far is stored. Once computed, the same table is used for all problems with the same goal state.

Combining Multiple Databases 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 31 moves needed to solve red tiles 22 moves need to solve blue tiles Overall heuristic is maximum of 31 moves

Additive Pattern Databases Culberson and Schaeffer counted all moves needed to correctly position the pattern tiles. In contrast, we count only moves of the pattern tiles, ignoring non-pattern moves. If no tile belongs to more than one pattern, then we can add their heuristic values. Manhattan distance is a special case of this, where each pattern contains a single tile.

Example Additive Databases 1 2 3 4 5 6 7 8 9 10 11 12 13 15 14 The 7-tile database contains 58 million entries. The 8-tile database contains 519 million entries.

Computing the Heuristic 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 20 moves needed to solve red tiles 25 moves needed to solve blue tiles Overall heuristic is sum, or 20+25=45 moves

Drawbacks of Standard Pattern DBs Since we can only take max Diminishing returns on additional DBs Would like to be able to add values © Daniel S. Weld Adapted from Richard Korf presentation

Disjoint Pattern DBs Partition tiles into disjoint sets During search 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 Partition tiles into disjoint sets For each set, precompute table E.g. 8 tile DB has 519 million entries And 7 tile DB has 58 million During search Look up heuristic values for each set Can add values without overestimating! Manhattan distance is a special case of this idea where each set is a single tile © Daniel S. Weld Adapted from Richard Korf presentation

Performance 15 Puzzle: 2000x speedup vs Manhattan dist IDA* with the two DBs shown previously solves 15 Puzzles optimally in 30 milliseconds 24 Puzzle: 12 million x speedup vs Manhattan IDA* can solve random instances in 2 days. Requires 4 DBs as shown Each DB has 128 million entries Without PDBs: 65,000 years © Daniel S. Weld Adapted from Richard Korf presentation