Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

45
Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007

Transcript of Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Page 1: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Searching for Solutions

Artificial Intelligence

CMSC 25000

January 11, 2007

Page 2: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Agenda• Search – Motivation

– Problem-solving agents– Rigorous problem definitions

• Blind exhaustive search:– Breadth-first search– Uniform search– Depth-first search– Iterative deepening search

• Search analysis– Computational cost, limitations

Page 3: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Problem-Solving Agents

• Goal-based agents– Identify goal, sequence of actions that satisfy

• Goal: set of satisfying world states– Precise specification of what to achieve

• Problem formulation:– Identify states and actions to consider in achieving goal

– Given a set of actions, consider sequence of actions leading to a state with some value

• Search: Process of looking for sequence– Problem -> action sequence solution

Page 4: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Agent Environment Specification

● Dimensions– Fully observable vs partially observable: Fully– Deterministic vs stochastic: Deterministic – Static vs dynamic: Static– Discrete vs continuous: Discrete

● Issues?

Page 5: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Closer to Reality

• Sensorless agents (conformant problems)– Replace state with “belief state”

• Multiple physical states, successors:sets of successors

• Partial observability (contigency problems)– Solution is tree, branch chosen based on percepts

Page 6: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: vacuum world

• Single-state, start in #5. Solution?

Page 7: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: vacuum world

• Single-state, start in #5. Solution? [Right, Vacuum]

• Sensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution?

Page 8: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: vacuum world

• Sensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Vacuum,Left,Vacuum]

• Contingency – Nondeterministic: Vacuum may

dirty a clean carpet– Partially observable: location, dirt at current location.– Percept: [L, Clean], i.e., start in #5 or #7

Solution?

Page 9: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: vacuum world

• Sensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Vacuum,Left,Vacuum]

• Contingency – Nondeterministic: Vacuum may

dirty a clean carpet– Partially observable: location, dirt at current location.– Percept: [L, Clean], i.e., start in #5 or #7

Solution? [Right, if dirt then Vacuum]

Page 10: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Formal Problem Definitions• Key components:

– Initial state: • E.g. First location

– Available actions:• Successor function: reachable states

– Goal test:• Conditions for goal satisfaction

– Path cost:• Cost of sequence from initial state to reachable state

• Solution: Path from initial state to goal– Optimal if lowest cost

Page 11: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Selecting a state space

• Real world is absurdly complex state space must be abstracted for problem solving

• (Abstract) state = set of real states• (Abstract) action = complex combination of real actions

– e.g., "Arad Zerind" represents a complex set of possible routes, detours, rest stops, etc.

• For guaranteed realizability, any real state "in Arad“ must get to some real state "in Zerind"

• (Abstract) solution = – set of real paths that are solutions in the real world

• Each abstract action should be "easier" than the original problem

Page 12: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Why Search?

• Not just city route search– Many AI problems can be posed as search

• Planning: – Vertices: World states; Edges: Actions

• Game-playing: – Vertices: Board configurations; Edges: Moves

• Speech Recognition:– Vertices: Phonemes; Edges: Phone transitions

Page 13: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Vacuum world state space graph

• states?• actions?• goal test?• path cost?

Page 14: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Vacuum world state space graph

• states? integer dirt and robot location • actions? Left, Right, Vacuum• goal test? no dirt at all locations• path cost? 1 per action

Page 15: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: The 8-puzzle

• states?• actions?• goal test?• path cost?

Page 16: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: The 8-puzzle

• states? locations of tiles • actions? move blank left, right, up, down • goal test? = goal state (given)• path cost? 1 per move

[Note: optimal solution of n-Puzzle family is NP-hard]

Page 17: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Example: robotic assembly

• states?: real-valued coordinates of robot joint angles, parts of the object to be assembled

• actions?: continuous motions of robot joints• goal test?: complete assembly• path cost?: time to execute

Page 18: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Basic Search Algorithm

• Form a 1-element queue of 0 cost=root node

• Until first path in queue ends at goal or no paths– Remove 1st path from queue; extend path one step– Reject all paths with loops– Add new paths to queue

• If goal found=>success; else, failure

Paths to extendOrder of paths added

Position new paths added

Page 19: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.
Page 20: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Basic Search Problem

• Vertices: Cities; Edges: Steps to next, distance• Find route from S(tart) to G(oal)

S

D

A

E

B C

F

G

3

4

5

4

2 4 3

4

5

Page 21: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Formal Statement

• Initial State: in(S)

• Successor function:– Go to all neighboring nodes

• Goal state: in(G)

• Path cost: – Sum of edge costs

Page 22: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.
Page 23: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.
Page 24: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.
Page 25: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Blind Search

• Need SOME route from S to G– Assume no information known– Depth-first search, breadth-first search,

uniform-cost search, iterative deepening search

• Convert search problem to search tree– Root=Zero length path at Start– Node=Path: label by terminal node

• Child one-step extension of parent path

Page 26: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Search TreeS

A D

B D

C E

D F

G

E

FB

GC

EA

B

D E

F G

B F

A C G

Page 27: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Breadth-first Search

• Explore all paths to a given depth

S

A D

B D A E

C E E B B F

D F B F D E A C G

Page 28: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Breadth-first Search Algorithm

• Form a 1-element queue of 0 cost=root node

• Until first path in queue ends at goal or no paths– Remove 1st path from queue; extend path one

step– Reject all paths with loops– Add new paths to BACK of queue

• If goal found=>success; else, failure

Page 29: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Analyzing Search Algorithms

• Criteria:– Completeness: Finds a solution if one exists– Optimal: Find the best (least cost) solution– Time complexity: Order of growth of running time– Space complexity: Order of growth of space needs

• BFS:– Complete: yes; Optimal: only if # steps= cost– Time complexity: O(b^d+1); Space: O(b^d+1)

Page 30: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Uniform-cost Search

• BFS: – Extends path with fewest steps

• UCS:– Extends path with least cost

• Analysis:– Complete?: Yes; Optimal?: Yes– Time: O(b^(C*/e)); Space: O(b^(C*/e))

Page 31: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Uniform-cost Search Algorithm

• Form a 1-element queue of 0 cost=root node• Until first path in queue ends at goal or no

paths– Remove 1st path from queue; extend path one

step– Reject all paths with loops– Add new paths to queue– Sort paths in order of increasing length

• If goal found=>success; else, failure

Page 32: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Depth-first Search

• Pick a child of each node visited, go forward– Ignore alternatives until exhaust path w/o goal

S

A

B

C E

D F

G

Page 33: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Depth-first Search Algorithm

• Form a 1-element queue of 0 cost=root node• Until first path in queue ends at goal or no

paths– Remove 1st path from queue; extend path one

step– Reject all paths with loops– Add new paths to FRONT of queue

• If goal found=>success; else, failure

Page 34: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Search Issues

• Breadth-first search:– Good if many (effectively) infinite paths, b<<– Bad if many end at same short depth, b>>

• Uniform-cost search:– Tries paths with many short steps first– Identical to BFS if all steps same cost

• Depth-first search:– Good if: most partial=>complete, not too long– Bad if many (effectively) infinite paths

Page 35: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Iterative Deepening

• Problem: – DFS good space behavior

• Could go down blind path, or sub-optimal

• Solution:– Search at progressively greater depths:

• 1,2,3,4,5…..

Page 36: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Progressive Deepening• Question: Aren’t we wasting a lot of work?

– E.g. cost of intermediate depths

• Answer: (surprisingly) No!– Most nodes at fringe– Fringe (depth d): Cost = b^d– Preceding depths: b^0 + b^1+…b^(d-1)

• (b^d - 1)/(b -1)

– Ratio of last ply cost/all preceding ~ b - 1– For large branching factors, prior work small

relative to maximum depth

Page 37: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Heuristic Search• A little knowledge is a powerful thing

– Order choices to explore better options first– More knowledge => less search– Better search alg?? Better search space

• Measure of remaining cost to goal-heuristic– E.g. actual distance => straight-line distance

S

D

A

E

B C

F

G

4.06.710.4

11.0

8.96.9

3.0

Page 38: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Hill-climbing Search

• Select child to expand that is closest to goal

S

A10.4 D 8.9

A10.4 E 6.9

B6.7 F3.0

G

Page 39: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Hill-climbing Search Algorithm

• Form a 1-element queue of 0 cost=root node• Until first path in queue ends at goal or no paths

– Remove 1st path from queue; extend path one step– Reject all paths with loops– Sort new paths by estimated distance to goal– Add new paths to FRONT of queue

• If goal found=>success; else, failure

Page 40: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Beam Search• Breadth-first search of fixed width - top w

– Guarantees limited branching factor, E.g. w=2

S

A D

B D A E

10.4 8.9

6.7 8.9 10.4 6.9

C E B F4.0 6.9 6.7 3

A C G

Page 41: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Beam Search Algorithm

– Form a 1-element queue of 0 cost=root node– Until first path in queue ends at goal or no

paths• Extend all paths one step• Reject all paths with loops• Sort all paths in queue by estimated distance to goal

– Put top w in queue

– If goal found=>success; else, failure

Page 42: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Best-first Search• Expand best open node ANYWHERE in tree

– Form a 1-element queue of 0 cost=root node– Until first path in queue ends at goal or no paths

• Remove 1st path from queue; extend path one step• Reject all paths with loops• Put in queue• Sort all paths by estimated distance to goal

– If goal found=>success; else, failure

Page 43: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Heuristic Search Issues• Parameter-oriented hill climbing

– Make one step adjustments to all parameters• E.g. tuning brightness, contrast, r, g, b on TV

– Test effect on performance measure

• Problems:– Foothill problem: aka local maximum

• All one-step changes - worse!, but not global max

– Plateau problem: one-step changes, no FOM +– Ridge problem: all one-steps down, but not even local max

• Solution (local max): Randomize!!

Page 44: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Summary

• Blind search: – Find some path to goal– Depth-first, Breadth-first– Iterative Deepening

• Analyzing search algorithms– Completeness, Optimality, Time, Space

• Next time:– A little knowledge is a useful thing...

Page 45: Searching for Solutions Artificial Intelligence CMSC 25000 January 11, 2007.

Search CostsType Worst / Worst

Time Space Reach Goal?

Depth-first B^d+1/ Bd Yes

Breadth-first B^d+1/B^d Yes

Hill-Climbing (no backup)

d/ B No

Hill-Climbing B^d+1 /Bd Yes

Beam Search Wd / WB No

Best-first B^d+1/B^d Yes