CS B551: E LEMENTS OF A RTIFICIAL I NTELLIGENCE Instructor: Kris Hauser 1
R ECAP Brief history and philosophy of AI What is intelligence? Can a machine act/think intelligently? Turing machine, Chinese room 2
A GENDA Problem Solving using Search Search Algorithms 3
E XAMPLE : 8-P UZZLE Initial stateGoal state State: Any arrangement of 8 numbered tiles and an empty tile on a 3x3 board
S UCCESSOR F UNCTION : 8-P UZZLE SUCC(state) subset of states The successor function is knowledge about the 8-puzzle game, but it does not tell us which outcome to use, nor to which state of the board to apply it.
6 Across history, puzzles and games requiring the exploration of alternatives have been considered a challenge for human intelligence: Chess originated in Persia and India about 4000 years ago Checkers appear in 3600-year-old Egyptian paintings Go originated in China over 3000 years ago So, it’s not surprising that AI uses games to design and test algorithms
E XPLORING A LTERNATIVES Problems that seem to require intelligence usually require exploring multiple alternatives Search: a systematic way of exploring alternatives 7
8-Q UEENS P ROBLEM State repr. 1 Any non-conflicting placement of 0-8 queens State repr. 2 Any placement of 8 queens 8
D EFINING A S EARCH P ROBLEM 9 State space S Successor function: x S SUCC (x) 2 S Initial state s 0 Goal test: x S GOAL? (x) =T or F Arc cost S
S TATE G RAPH 10 Each state is represented by a distinct node An arc (or edge) connects a node s to a node s’ if s’ SUCC (s) The state graph may contain more than one connected component
S OLUTION TO THE S EARCH P ROBLEM A solution is a path connecting the initial node to a goal node (any one) The cost of a path is the sum of the arc costs along this path An optimal solution is a solution path of minimum cost There might be no solution ! 11 I G
P ATHLESS P ROBLEMS Sometimes the path doesn’t matter A solution is any goal node Arcs represent potential state transformations E.g. 8-queens, Simplex for LPs, Map coloring 12 I G
R EPRESENTATION 1 State: any placement of 0-8 queens Initial state: 0 queens Successor function: Place queen in empty square Goal test: Non-conflicting placement of 8 queens # of states ~ 64x63x…x57 ~ 3x
R EPRESENTATION 2 State: any placement of non- conflicting 0-8 queens in columns starting from left Initial state: 0 queens Successor function: A queen placed in leftmost empty column such that it causes no conflicts Goal test: Any state with 8 queens # of states =
P ATH P LANNING 15 What is the state space ?
F ORMULATION #1 16 Cost of one horizontal/vertical step = 1 Cost of one diagonal step = 2
O PTIMAL S OLUTION 17 This path is the shortest in the discretized state space, but not in the original continuous space
F ORMULATION #2 18 Cost of one step: length of segment
F ORMULATION #2 19 Cost of one step: length of segment Visibility graph
S OLUTION P ATH 20 The shortest path in this state space is also the shortest in the original continuous space
W HAT IS A S TATE ? A state does: Represent all information meaningful to the problem at a given “instant in time” – past, present, or future Exist in an abstract, mathematical sense A state DOES NOT: Necessarily exist in the computer’s memory Tell the computer how it arrived at the state Tell the computer how to choose the next state Need to be a unique representation 21
W HAT IS A S TATE S PACE ? An abstract mathematical object E.g., the set of all permutations of (1,…,8,empty) Membership should be trivially testable E.g., S = { s | s is reachable from the start state through transformations of the successor function } is not easily testable Arcs should be easily generated Again: the state space does NOT contain information about which arc to take (or not to take) in a given state 22
5- MINUTE Q UIZ Formulate 2x2 Tic-Tac-Toe, where you play both X and O’s actions, as a search problem. The goal state is any state with two in a line. Assume O goes first. Draw entire state graph. For compactness’s sake, eliminate symmetrical states Indicate initial and goal states on this graph Suppose one side is allowed to pass. How does the state graph change? Do you need to change anything to the problem definition? 23
E XAMPLE : 8-P UZZLE Initial stateGoal state State: Any arrangement of 8 numbered tiles and an empty tile on a 3x3 board
15-P UZZLE Introduced (?) in 1878 by Sam Loyd, who dubbed himself “America’s greatest puzzle- expert” 25
15-P UZZLE Sam Loyd offered $1,000 of his own money to the first person who would solve the following problem: ?
But no one ever won the prize !! 27
H OW BIG IS THE STATE SPACE OF THE ( N 2 - 1)- PUZZLE ? 8-puzzle ?? states 28
H OW BIG IS THE STATE SPACE OF THE ( N 2 - 1)- PUZZLE ? 8-puzzle 9! = 362,880 states 15-puzzle 16! ~ 2.09 x states 24-puzzle 25! ~ states But only half of these states are reachable from any given state (but you may not know that in advance) 29
P ERMUTATION I NVERSIONS Wlg, let the goal be: A tile j appears after a tile i if either j appears on the same row as i to the right of i, or on another row below the row of i. For every i = 1, 2,..., 15, let ni be the number of tiles j < i that appear after tile i (permutation inversions) N = n2 + n3 + + n15 + row number of empty tile n 2 = 0n 3 = 0n 4 = 0 n 5 = 0n 6 = 0n 7 = 1 n 8 = 1n 9 = 1n 10 = 4 n 11 = 0n 12 = 0n 13 = 0 n 14 = 0n 15 = 0 N = 7 + 4
Proposition: (N mod 2) is invariant under any legal move of the empty tile Proof: Any horizontal move of the empty tile leaves N unchanged A vertical move of the empty tile changes N by an even increment ( 1 1 1 1) s = s’ = N(s’) = N(s)
Proposition: (N mod 2) is invariant under any legal move of the empty tile For a goal state g to be reachable from a state s, a necessary condition is that N(g) and N(s) have the same parity It can be shown that this is also a sufficient condition The state graph consists of two connected components of equal size 32
S EARCHING THE S TATE S PACE It is often not feasible (or too expensive) to build a complete representation of the state graph 33
8-, 15-, 24-P UZZLES 34 8-puzzle 362,880 states 15-puzzle 2.09 x states 24-puzzle states 100 millions states/sec sec ~ 55 hours > 10 9 years
I NTRACTABILITY Constructing the full state graph is intractable for most interesting problems n-puzzle: (n+1)! states k-queens: k k states 35 Tractability of search hinges on the ability to explore only a tiny portion of the state graph!
S EARCHING 36
S EARCHING THE S TATE S PACE 37 Search tree
S EARCHING THE S TATE S PACE 38 Search tree
S EARCHING THE S TATE S PACE 39 Search tree
S EARCHING THE S TATE S PACE 40 Search tree
S EARCHING THE S TATE S PACE 41 Search tree
S EARCHING THE S TATE S PACE 42 Search tree
S EARCH N ODES AND S TATES If states are allowed to be revisited, the search tree may be infinite even when the state space is finite If states are allowed to be revisited, the search tree may be infinite even when the state space is finite
D ATA S TRUCTURE OF A N ODE 44 PARENT-NODE STATE Depth of a node N = length of path from root to N (depth of the root = 0) BOOKKEEPING 5Path-Cost 5Depth RightAction Expanded yes... CHILDREN
N ODE EXPANSION The expansion of a node N of the search tree consists of: Evaluating the successor function on STATE(N) Generating a child of N for each state returned by the function node generation node expansion N
F RINGE OF S EARCH T REE The fringe is the set of all search nodes that haven’t been expanded yet
47 Is it identical to the set of leaves?
S EARCH S TRATEGY The fringe is the set of all search nodes that haven’t been expanded yet The fringe is implemented as a priority queue FRINGE INSERT(node,FRINGE) REMOVE(FRINGE) The ordering of the nodes in FRINGE defines the search strategy 48
S EARCH A LGORITHM #1 SEARCH#1 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,FRINGE) 3. Repeat: 4. If empty(FRINGE) then return failure 5.N REMOVE(FRINGE) 6.s STATE(N) 7.For every state s’ in SUCCESSORS(s) 8.Create a new node N’ as a child of N 9.If GOAL?(s’) then return path or goal state 10.INSERT(N’,FRINGE) 49 Expansion of N
P ERFORMANCE M EASURES Completeness A search algorithm is complete if it finds a solution whenever one exists [What about the case when no solution exists?] Optimality A search algorithm is optimal if it returns a minimum-cost path whenever a solution exists Complexity It measures the time and amount of memory required by the algorithm 50
T OPICS OF N EXT 3-4 C LASSES Blind (uninformed) Search Little or no knowledge about how to search Heuristic (informed) Search How to use extra knowledge about the problem Local Search With knowledge about goal distribution 51
R ECAP General problem solving framework State space Successor function Goal test => State graph Search is a methodical way of exploring alternatives 52
H OMEWORK Register! Readings: R&N Ch HW1 On OnCourse Writing and programming Due date: 9/6 53