Top Banner
CS 188: Artificial Intelligence Search Instructors: Dan Klein and Pieter Abbeel University of California, Berkeley [These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.]
52

CS 188: Artificial Intelligence

Jan 03, 2016

Download

Documents

Willa Poole

CS 188: Artificial Intelligence. Search. Instructors: Dan Klein and Pieter Abbeel University of California, Berkeley [These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http:// ai.berkeley.edu .]. Today. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

CS 294-5: Statistical Natural Language Processing

AnnouncementsProject 0: Python TutorialDue Friday at 5pm

Math self-diagnostic on web --- optional, but important to check your preparedness for second half

SectionsSign-up Friday at 2pm on piazzaStart next week, can go to any, but have priority in your own

Instructional accounts: after lecture, but not needed except if you use lab machines

CS 188: Artificial Intelligence

SearchInstructors: Dan Klein and Pieter AbbeelUniversity of California, Berkeley[These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.]Please retain proper attribution, including the reference to ai.berkeley.edu. Thanks!2

TodayAgents that Plan Ahead

Search Problems

Uninformed Search Methods

Depth-First Search

Breadth-First Search

Uniform-Cost Search

General theme in the class:

A goal we have in mind.

A mathematical abstraction to formalize this

Algorithms that operate on these abstractions3Agents that Plan

Reflex AgentsReflex agents:Choose action based on current percept (and maybe memory)May have memory or a model of the worlds current stateDo not consider the future consequences of their actionsConsider how the world IS

Can a reflex agent be rational?

[Demo: reflex optimal (L2D1)]

[Demo: reflex optimal (L2D2)]Examples: blinking your eye (not using your entire thinking capabilities), vacuum cleaner moving towards nearest dirt5Video of Demo Reflex Optimal

Video of Demo Reflex Odd

Planning AgentsPlanning agents:Ask what ifDecisions based on (hypothesized) consequences of actionsMust have a model of how the world evolves in response to actionsMust formulate a goal (test)Consider how the world WOULD BE

Optimal vs. complete planning

Planning vs. replanning

[Demo: replanning (L2D3)]

[Demo: mastermind (L2D4)]Video of Demo Replanning

Video of Demo Mastermind

Search Problems

Search ProblemsA search problem consists of:

A state space

A successor function(with actions, costs)

A start state and a goal test

A solution is a sequence of actions (a plan) which transforms the start state to a goal state

N, 1.0E, 1.0Often comes back on exams

Goal test sometimes more than one state that satisfies having achieved the goal, for example, eat all the dots

Abstraction12Search Problems Are Models

Example: Traveling in RomaniaState space:CitiesSuccessor function:Roads: Go to adjacent city with cost = distanceStart state:AradGoal test:Is state == Bucharest?

Solution?

Whats in a State Space?Problem: PathingStates: (x,y) locationActions: NSEWSuccessor: update location onlyGoal test: is (x,y)=ENDProblem: Eat-All-DotsStates: {(x,y), dot booleans}Actions: NSEWSuccessor: update location and possibly a dot booleanGoal test: dots all falseThe world state includes every last detail of the environmentA search state keeps only the details needed for planning (abstraction)

Wrong example for eat-all-dots: (x, y, dot count)15State Space Sizes?World state:Agent positions: 120Food count: 30Ghost positions: 12Agent facing: NSEW

How manyWorld states?120x(230)x(122)x4States for pathing?120States for eat-all-dots?120x(230)

90 * (2^30-1) + 30 * 2^29 = 145 billion2^29 = 536 870 91216Quiz: Safe PassageProblem: eat all dots while keeping the ghosts perma-scaredWhat does the state space have to specify?(agent position, dot booleans, power pellet booleans, remaining scared time)

State Space Graphs and Search Trees

State Space GraphsState space graph: A mathematical representation of a search problemNodes are (abstracted) world configurationsArcs represent successors (action results)The goal test is a set of goal nodes (maybe only one)

In a state space graph, each state occurs only once!

We can rarely build this full graph in memory (its too big), but its a useful idea

State Space GraphsState space graph: A mathematical representation of a search problemNodes are (abstracted) world configurationsArcs represent successors (action results)The goal test is a set of goal nodes (maybe only one)

In a search graph, each state occurs only once!

We can rarely build this full graph in memory (its too big), but its a useful idea

SGdbpqcehafrTiny search graph for a tiny search problemSearch TreesA search tree:A what if tree of plans and their outcomesThe start state is the root nodeChildren correspond to successorsNodes show states, but correspond to PLANS that achieve those statesFor most problems, we can never actually build the whole tree

E, 1.0N, 1.0This is now / startPossible futuresDifferent plans that achieve the same state, will be different nodes in the tree.21State Space Graphs vs. Search TreesSabdpacephfrqqcGaqephfrqqcGaSGdbpqcehafrWe construct both on demand and we construct as little as possible.Each NODE in in the search tree is an entire PATH in the state space graph.Search TreeState Space GraphQuiz: State Space Graphs vs. Search TreesSGbaConsider this 4-state graph: Important: Lots of repeated structure in the search tree!How big is its search tree (from S)?

Tree Search

Search Example: Romania

Searching with a Search TreeSearch:Expand out potential plans (tree nodes)Maintain a fringe of partial plans under considerationTry to expand as few tree nodes as possible

General Tree SearchImportant ideas:FringeExpansionExploration strategy

Main question: which fringe nodes to explore?

Example: Tree SearchSGdbpqcehafrLeft: show treeRight: fringe28

Depth-First SearchDepth-First SearchSabdpacephfrqqcGaqephfrqqcGaSGdbpqcehafrqphfdbacerStrategy: expand a deepest node firstImplementation: Fringe is a LIFO stackSearch Algorithm Properties

Search Algorithm PropertiesComplete: Guaranteed to find a solution if one exists?Optimal: Guaranteed to find the least cost path?Time complexity?Space complexity?

Cartoon of search tree:b is the branching factorm is the maximum depthsolutions at various depths

Number of nodes in entire tree?1 + b + b2 + . bm = O(bm)

b1 nodeb nodesb2 nodesbm nodesm tiersDepth-First Search (DFS) Propertiesb1 nodeb nodesb2 nodesbm nodesm tiersWhat nodes DFS expand?Some left prefix of the tree.Could process the whole tree!If m is finite, takes time O(bm)

How much space does the fringe take?Only has siblings on path to root, so O(bm)

Is it complete?m could be infinite, so only if we prevent cycles (more later)

Is it optimal?No, it finds the leftmost solution, regardless of depth or cost

Breadth-First Search

Breadth-First SearchSabdpacephfrqqcGaqephfrqqcGaSGdbpqcehafrSearchTiersStrategy: expand a shallowest node firstImplementation: Fringe is a FIFO queueBreadth-First Search (BFS) PropertiesWhat nodes does BFS expand?Processes all nodes above shallowest solutionLet depth of shallowest solution be sSearch takes time O(bs)

How much space does the fringe take?Has roughly the last tier, so O(bs)

Is it complete?s must be finite if a solution exists, so yes!

Is it optimal?Only if costs are all 1 (more on costs later)

b1 nodeb nodesb2 nodesbm nodess tiersbs nodesQuiz: DFS vs BFS

Quiz: DFS vs BFSWhen will BFS outperform DFS?

When will DFS outperform BFS?[Demo: dfs/bfs maze water (L2D6)]Video of Demo Maze Water DFS/BFS (part 1)

Video of Demo Maze Water DFS/BFS (part 2)

Iterative DeepeningbIdea: get DFSs space advantage with BFSs time / shallow-solution advantagesRun a DFS with depth limit 1. If no solutionRun a DFS with depth limit 2. If no solutionRun a DFS with depth limit 3. ..

Isnt that wastefully redundant?Generally most work happens in the lowest level searched, so not so bad!Cost-Sensitive SearchBFS finds the shortest path in terms of number of actions.It does not find the least-cost path. We will now covera similar algorithm which does find the least-cost path. STARTGOALdbpqcehafr29281823244151322Uniform Cost Search

Uniform Cost SearchSabdpacephfrqqcGaqephfrqqcGaStrategy: expand a cheapest node first:Fringe is a priority queue (priority: cumulative cost)SGdbpqcehafr39116411571381011171106391128821512Cost contours2Uniform Cost Search (UCS) PropertiesWhat nodes does UCS expand?Processes all nodes with cost less than cheapest solution!If that solution costs C* and arcs cost at least , then the effective depth is roughly C*/Takes time O(bC*/) (exponential in effective depth)

How much space does the fringe take?Has roughly the last tier, so O(bC*/)

Is it complete?Assuming best solution has a finite cost and minimum arc cost is positive, yes!

Is it optimal?Yes! (Proof next lecture via A*)

bC*/ tiersc 3c 2c 1Uniform Cost IssuesRemember: UCS explores increasing cost contours

The good: UCS is complete and optimal!

The bad:Explores options in every directionNo information about goal location

Well fix that soon!

StartGoalc 3c 2c 1[Demo: empty grid UCS (L2D5)][Demo: maze with deep/shallow water DFS/BFS/UCS (L2D7)]46Video of Demo Empty UCS

Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 1)

Let students guess which one of the three it is. (This is BFS.)48Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 2)

Let students guess which one of the three it is. (This is UCS.)

49Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 3)

Let students guess which one of the three it is. (This is DFS.)

50The One QueueAll these search algorithms are the same except for fringe strategiesConceptually, all fringes are priority queues (i.e. collections of nodes with attached priorities)Practically, for DFS and BFS, you can avoid the log(n) overhead from an actual priority queue, by using stacks and queuesCan even code one implementation that takes a variable queuing object

Search and ModelsSearch operates over models of the worldThe agent doesnt actually try all the plans out in the real world!Planning is all in simulationYour search is only as good as your models

Search Gone Wrong?

Some Hints for P1Graph 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