20
Introduction to search Chapter 3

Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Embed Size (px)

Citation preview

Page 1: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Introduction to search

Chapter 3

Page 2: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Why study search?

Search is a basis for all AI search proposed as the basis of intelligence inference all learning algorithms, e.g., can be seen as

searching some space of hypothesis

Page 3: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Intelligence as search

“The solutions to problems are represented as symbol structures. A physical-symbol system exercises its intelligence in problem-solving by search -- that is, by generating & progressively modifying symbol structures until it produces a solution structure.”

Page 4: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

The search task

Given a description of the initial state list of legal actions

• preconditions

• effects goal test -- tells you if a goal has been reached

Find an ordered list of actions to perform in order to

go from the initial state to the goal

Page 5: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Search as a graph

Nodes search-space states

Directed arcs legal actions from each state to another

ExampleRather than being given, however, we often

build the graph (implicitly) as we go; we aren’t given the graph explicitly

Page 6: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Trip as search

State: geographical location (city, street, etc.)

Actions: following a roadInitial state: MadisonGoal state: Minneapolis

Page 7: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

The following is the basic outline for the various search algorithms

(some steps are modified depending on the specifics of the search, e.g. if doing hill climbing, iterative deepening, or beam search).

General Pseudocode for Searching

Page 8: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

OPEN = { startNode } // Nodes under consideration. CLOSED = { } // Nodes we're done with.

while OPEN is not empty { remove an item from OPEN based on search strategy used - call it Xif goalState?(X) return the solution foundotherwise // Expand node X. { 1) add X to CLOSED 2) generate the immediate neighbors (ie, children of X) 3) eliminate those children already in OPEN or CLOSED 4) add REMAINING children to OPEN } } return FAILURE // Failed if OPEN exhausted without a goal being found

Page 9: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

“Considering” a node

If goal-state?(node) then done else expand(node) expand = add previously unvisited neighbors /

children (states that be gotten to from node by applying the operators) to the OPEN list

Page 10: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Task: find a route from the start node to the goal node

build a tree (try all/many possible paths)OPEN list allows backtracking from a path that

“dies out”; saves other possible ways nodes under consideration (to be expanded)

CLOSED list prevents us from repeatedly trying a node & ending up in an infinite loop nodes that have been processed

Search algorithm explained

Page 11: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

General search methodsGiven a set of search-space nodes, which

one should we consider next? Youngest [depth-first search]

• most recently created node Oldest [breadth-first search]

• least-recently created node Best [best-first search]

• requires a scoring function Random

• simulated annealing

Page 12: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Implementing search strategiesBreadth

queue: first in, first out put new nodes at the back of list

Depth stack: last in, first out put new nodes at the front of list

Best priority queue add new nodes then sort list

The next node to consider is popped off the front of the OPEN list

Page 13: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Example of search strategies

Page 14: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Search danger: infinite spaces

We must be careful that our search doesn’t go forever the goal we are looking for may not be in the

search space but because the space is infinite we might not know this

the goal may be in the search space but we go down an infinite branch

example

Page 15: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

BFS tradeoffs

pros guaranteed to find a solution if it exists guaranteed to find the shortest solution (in

terms of arcs)

cons OPEN becomes too big [O(bd)] example

Page 16: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

DFS tradeoffs

pros might find solution quickly needs less space for OPEN [O(b * m)] example

cons can get stuck (run forever) in infinite spaces might not find shortest solution

Page 17: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Best-first search tradeoffs

pro can use domain specific knowledge

con requires a good heuristic (scoring) function

Page 18: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Fixing DFS: iterative deepeningCombines the strengths of breadth- & depth-

first searchdo DFS but with depth limited to k

if find solution, done (return path, etc.) else, increment k & start over

don’t save partial solutions from previous iterations; too much memory required

due to exponential growth, most work is at the bottom

guaranteed to find the shortest solution, but OPEN doesn’t get too big (as in BFS)

Page 19: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Iterative deepening idea

We do only a little more work overall, but our storage needs are much less we get the good aspects of BFS -- shortest

solution without the negative aspects -- OPEN list too

big

Page 20: Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning

Search space examples

Define state representation (k-rep) initial state goal state operators

Draw search space (if it is small)Build search Tree