csc384&intro&to&&...
TRANSCRIPT
CSC384 Intro to Ar-ficial Intelligence
Winter 2015
Announcements
Note-‐taker Volunteer: "The AccessAbility Resource Centre is looking for a volunteer note-‐taker to take notes on behalf of students with a disability registered in this class. Volunteer note-‐takers are responsible for submiNng their notes to AccessAbility every week. The notes can be submiOed online or scanned at the Centre. Volunteer note-‐takers will receive a cer-ficate of recogni-on and reference leOer at the end of the year. If you are interested in this opportunity, please take a note-‐taker flyer and follow the instruc-ons provided. If you have any ques-ons, please call 905-‐828-‐5422, email [email protected] or drop by the Centre (room 2037, Davis Building). Thank you."
2015-‐01-‐16 Lisa Yan 1
Announcements
• Tutorial: Monday 5-‐7 January 19 • Assignment 1 – Out: Sunday – Due: January 30, Friday, at noon
• Chapter 3: Problem Solving by Searching
2015-‐01-‐16 Lisa Yan 2
Goal based: Problem Solving Agent
A design of “Formulate, Search, Execute”: • Goal formulation:
Adop a goal, based on agent’s current stage. • Problem formula-on:
Given a goal, what ac-ons & states to consider. • Search solu-on:
The process of looking for a sequence of ac-ons that reaches the goal.
• Execu-on 2015-‐01-‐16 Lisa Yan 3
Goal based: Problem Solving Agent
General-‐purpose search algorithms to solve problems: • Uninformed search: (blind search)
Algorithms are given no informa-on about the problem other than its defini-on - some solvable but not efficient.
• Informed search: (heuris-c search) Algorithms look for solu-ons with given guidance.
2015-‐01-‐16 Lisa Yan 4
Uninformed Search
2015-‐01-‐16 Lisa Yan 5
Searching
• Problem-‐solving (goal-‐based) agent: – Adopt a goal – Aim to sa-sfy it
• Next task to achieve: determine the “best”
path to the goal • Many AI problems can be successfully solved by search, e.g., game playing programs
2015-‐01-‐16 Lisa Yan 6
Problem Solving
5 components: • Ini-al state: agent starts in • Ac-ons space: possible available ac-ons • Transi-on model • Goal test: determine whether achieves a goal state
• Path cost: numeric cost to reflect performance measure
State Space
2015-‐01-‐16 Lisa Yan 7
ε
Toy Problem: the 8-‐puzzle
Ini-al State
Goal State
2015-‐01-‐16 Lisa Yan 8
Toy Problem: the 8-‐puzzle
• States: integer loca-ons of 8 -les. • Ac-ons: blank moves lem, right, up. • Goal test: state matches the goal configura-on • Path cost: costs 1 per move, so the length of the path
Ini-al State
Goal State
2015-‐01-‐16 Lisa Yan 9
Toy Problem: Vacuum World
2015-‐01-‐16 Lisa Yan 10
Vacuum World
• states: integer dirt and robot loca-ons (ignore dirt amounts etc.)
• ac-ons: Lem, Right, Suck, NoOp • goal test: no dirt • path cost: 1 per ac-on (0 for NoOp) 2015-‐01-‐16 Lisa Yan 11
8-‐Queens Puzzle
• n-‐queens problem: place n queens on an nxn board – place 8 queens on a chessboard so that no two queens aOack each other.
– A queen aOacks any piece in the same row, column or diagonal.
– 3 more queens missing
2015-‐01-‐16 Lisa Yan 12
Formulate problems
• Goal test: 8 queens on board, none aOacked. • Path cost: zero. • States: any arrangement of 0 to 8 queens on board.
• Ac/ons: add a queen to any square In this formula-on, we have 64^8 possible sequences to inves-gate.
2015-‐01-‐16 Lisa Yan 13
Missionaries and cannibals
The missionaries and cannibals problem is usually stated as follows: Three missionaries and three cannibals are on one side of a river, along with a boat that can hold one or two people. Find a way to get everyone to the other side, without ever leaving a group of missionaries in one place outnumbered by the cannibals in that place.
2015-‐01-‐16 Lisa Yan 14
Real-‐world Problems: TSP • The travelling salesperson problem (TSP) is a famous touring problem in which each city must be visited exactly once. The aim is to find the shortest tour.
• The problem is NP-‐hard, but an enormous amount of effort has been expended to improve the capabili-es of TSP algorithms.
• In addi-on to planning trips for travelling salespersons, these algorithms have been used for tasks such as planning movements of automa-c circuit board drills.
2015-‐01-‐16 Lisa Yan 15
Real-‐world Problems: Planning trip Touring holiday in Romania: • currently in Arad (ini-al state), need to catch flight leaves tomorrow from Bucharest
• Goal: drive to Bucharest • Problem:
– states: various ci-es – ac-ons: drive between ci-es – observable & determinis-c
• Find solu-on: Search for a route of sequence of ci-es, e.g., Arad, Sibiu, Fagaras, Bucharest
2015-‐01-‐16 Lisa Yan 16
Example: Romania
Figure 1 A simplified road map of Romania. 2015-‐01-‐16 Lisa Yan 17
Search Problem • Ini-al state, e.g., In(Arad) • Possible ac-ons, e.g., Go(Sibiu), Go(Zerind) • Successor func-on Result(s,a), e.g., Result(In(Arad), Go(Zerind)) = In(Zerind)
• Goal test, e.g., { In(Bucharest) } • Path cost (addi-ve), e.g., sum of distances, number of ac?ons executed, etc. – c(s; a; t) is the step cost, assumed to be ≥ 0
• A solu-on is a sequence of ac-ons leading from the ini-al state to a goal state
2015-‐01-‐16 Lisa Yan 18
State Space
Real world is absurdly complex; State space must be abstracted for problem solving. • States: the various ci-es you could be located in. – We are ignoring the low level details of driving, states where you are on the road between ci-es, etc.
• Ac-ons: drive between neighboring ci-es – Ignoring a complex set of possible routes, detours, rest stops, etc.
Abstrac-on makes it “easier” than the original problem!
2015-‐01-‐16 Lisa Yan 19
Genera-ng ac-on sequences • An informal descrip-on of the GENERAL-‐SEARCH
algorithms: generate successors of already-‐explored states (a.k.a. expand “states”) Func-on GENERAL-‐SEARCH( problem, strategy) returns a solu-on, or failure
ini-alize the search tree using the ini-al state of problem loop do if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solu-on else expand the node and add the resul-ng nodes to the search tree end
2015-‐01-‐16 Lisa Yan 20
Search tree
Figure 2 Par-al search tree for route finding from Arad to Bucharest. 2015-‐01-‐16 Lisa Yan 21
Data structures for search trees
• state: in the state space to which the node corresponds; • node: in the search tree that generated this node (this is called the parent node); • operator/ac/on: applied to generate the node; • number of nodes on the path from the root to this node (the depth of the node); • path cost of the path from the ini-al state to the node.
2015-‐01-‐16 Lisa Yan 22
Implementa-on: states vs. nodes • A state is a (representa-on of) a physical configura-on
• A node is a data structure cons-tu-ng part of a search tree: includes parent, children, depth, path cost g(x)
2015-‐01-‐16 Lisa Yan 23
Search Strategy Criteria • When evalua-ng a search strategy, use the following metrics: – Completeness: Does the search algorithm guarantee a solu-on, when there is one?
– Op-mality: Does it find the best solu-on, if mul-ple solu-ons exist?
– Efficiency: What kind of -me and/or space does it take in finding a solu-on?
2015-‐01-‐16 Lisa Yan 24
Search Strategy Criteria (cont’d) Time and space complexity are measured in terms of: • b: maximum branching factor of the search tree
• d: depth of the least-‐cost solu-on • m: maximum depth of the state space (may be ∞)
2015-‐01-‐16 Lisa Yan 25
Uninformed Searches
A search strategy is called uninformed if it has no other knowledge about the search space, other than the successive states at each stage, i.e.: • taking a road trip without a map/plan
2015-‐01-‐16 Lisa Yan 26
Uninformed Search Strategies
Uninformed search is less effec-ve than informed search. But, s-ll important! • Many problems give no addi-onal informa-on to consider. Strategies do not take into account any domain specific informa-on about the par-cular search problem.
• Rule does not change irrespec-ve of the search problem being solved
2015-‐01-‐16 Lisa Yan 27
Uninformed Search Strategies
Dis-nguished by the order in which nodes are expanded, uninformed search strategies are, for example as follows, different in a great deal. • BFS: Breadth-‐first search • UCS: Uniform cost search • DFS: Depth-‐first search • Depth-‐Limited • Itera-ve-‐Deepening depth-‐first search 2015-‐01-‐16 Lisa Yan 28
Breadth-‐first Search (BFS)
• The root node is expanded first, then all the nodes generated by the root node are expanded next, and then their successors, and so on. – considers all the paths of length 1 first, then all those of length 2, and so on
– all the nodes at depth d in the search tree are expanded before the nodes at depth d + 1.
• Implementa-on: a FIFO queue of fron-er (collec-on of nodes that are wai-ng to be expanded)
2015-‐01-‐16 Lisa Yan 29
Binary Tree: BFS
Figure 3 Breadth-‐first search trees amer 0, 1, 2, and 3 node expansions.
Progress of the search on a simple binary tree:
2015-‐01-‐16 Lisa Yan 30
BFS Example
2015-‐01-‐16 Lisa Yan 31
BFS
• If there is a solu-on, breadth-‐first search is guaranteed to find it
• and if there are several solu-ons, breadth-‐first search will always find the shallowest goal state first.
• In terms of the four criteria, breadth-‐first search is complete.
Why is BFS not always the strategy of choice? 2015-‐01-‐16 Lisa Yan 32
BFS Evalua-on
• b : branching factor (of the search tree) • suppose that the solu-on path length of d Then the maximum number of nodes generated before finding a solu-on is
b + b2 + b3 + … + bd • an exponen-al complexity bound: O(bd) – Space complexity is dominated by the size of fron?er O(bd)
2015-‐01-‐16 Lisa Yan 33
Breadth-‐first Search (BFS)
Two major problem for BFS: • memory requirements • execu-on -me i.e. If your problem has a solu-on at depth 16, then (given our assump-ons: 1000byte/node, 1 million nodes/second) it will take 350 years for an uninformed search to find it. • In general, exponen?al complexity search problems cannot be solved for any but the smallest instances.
2015-‐01-‐16 Lisa Yan 34
Summary Breadth-‐first Search (BFS)
• Breadth-‐first search expands the start state first, and then expands successive states, one level at a -me.
• Slow, but guaranteed to find the closest solu-on (if one exists)
• Complexity analysis: – Time: O(bd) – Space: O(bd)
A
B C D
G H J L M
N O P
F E
Q R
I
S
K
Expanded nodes:
A B C D E F G H I J K L M
N O P Q R S
2015-‐01-‐16 Lisa Yan 35
Uniform Cost Search
• Breadth-‐first search assumes that all transi-ons have a uniform path cost.
• Uniform cost search(UCS) expands unexplored states with the lowest path cost from the start state
• Given uniform path costs, this varia-on behaves just like breadth-‐first.
• Originated from Dijkstra’s algorithm for finding the past cost between two points
2015-‐01-‐16 Lisa Yan 36
UCS Example
2015-‐01-‐16 Lisa Yan 37
UCS Example
2015-‐01-‐16 Lisa Yan 38
UCS
• UCS is op-mal: uniform-‐cost search expands nodes in order of their op-mal path cost; thus, the first goal node selected for expansion must be the op-mal solu-on.
• In terms of the four criteria, breadth-‐first search is complete, if b is finite.
• Complexity? 2015-‐01-‐16 Lisa Yan 39
UCS Complexity
UC Search guided by path costs rather than depths, so its complexity is not directly characterized in b,d. • Let C* be the cost of op-mal solu-on, and assume that every ac-on costs at least ε, so the worst-‐case -me and space complexity is: O(b1+[C*/ε]) (note: [C*/ε] : lower([C*/ε]) ; b : branching factor)
2015-‐01-‐16 Lisa Yan 40
UCS vs. BFS O(b1+[C*/ε]) can be much greater then bd: – UCS can explore large trees of small steps before exploring path involving large and perhaps useful steps
– When all step costs are equal: • b1+[C*/ε] equals to bd+1; • UCS is similar to BFS, except: BFS stops as soon as it generates a goal; whereas, UCS examines all the nodes at the goal’s depth to see if a lower cost exists. Thus, UCS does strictly more work by expanding nodes at the depth d unnecessarily.
2015-‐01-‐16 Lisa Yan 41
Summary Uninform-‐Cost Search
• UCS expands the lowest path cost • guaranteed to find op-mal solu-on (if b is
finite, no infinite sequence of zero-‐cost ac-ons)
• Complexity analysis: – Time: O(b1+[C*/ε]) – Space: O(b1+[C*/ε])
2015-‐01-‐16 Lisa Yan 42
Depth-‐first Search (DFS)
• Expand deepest node in the current fron-er of the search tree
• Implementa-on: – Fron-er is a LIFO queue, i.e., new successors go at front
2015-‐01-‐16 Lisa Yan 43
DFS Example
2015-‐01-‐16 Lisa Yan 44
Depth-‐first Search Evalua-on • Complete? Guarantee to find a solu-on if exists?
NO: fails in infinite-‐depth spaces or spaces with loops • Op-mal? No. – Return a depth-‐first solu-on may exist in the other part of subtree.
• Time? – Bounded by the size of state space (maybe infinite) – O(bm) m: max depth of any node
• Note that if m is much larger than d (d: the depth of shallowest solu-on), and if infinite, terrible!
• but if solu-ons are dense, may be much faster than breadth-‐first search
Why include DFS? 2015-‐01-‐16 Lisa Yan 45
DFS Complexity
DFS’s advantage: space complexity • Space? – O(bm) – store only a single path root to leaf, linear space!
2015-‐01-‐16 Lisa Yan 46
Summary Depth-‐first Search (DFS) • Depth-‐first search expands states down a single branch of the search tree un-l the goal or a dead end is reached (requires backtracking)
• Faster, but dangerous. Can explore far past solu-on depth, and the first solu-on isn’t guaranteed to be the best possible.
• Complexity analysis: – Time: O(bm) – Space: O(bm)
A
B C D
G H J L M
N O P
F E
Q R
I
S
K
Expanded nodes:
A B E N O P F G C H I Q R J D K S L M 2015-‐01-‐16 Lisa Yan 47
Comparison
Criterion BFS UCS DFS Complete? Y(i) Y(ii) N Op-mal? Y Y N Time O(bd) O(b1+[C*/ε]) O(bm) Space O(bd) O(b1+[C*/ε]) O(bm)
i: complete if b is finite; ii: complete if step costs ≥ ε (posi-ve ε)
2015-‐01-‐16 Lisa Yan 48
b: maximum branching factor of the search tree d: depth of the least-‐cost solu-on m: maximum depth of the state space
(may be ∞)
Readings
• Russell & Norvig – Chapter 3.1-‐3.4
2015-‐01-‐16 Lisa Yan 49