Lecture 13 Pruning Vikas Ashok Department of Computer

  • Slides: 47
Download presentation
Lecture 13 Pruning Vikas Ashok Department of Computer Science ODU Reading for This Class:

Lecture 13 Pruning Vikas Ashok Department of Computer Science ODU Reading for This Class: Chapter 7, Russell and Norvig Artificial Intelligence

Review • Last Class – Games – Adversarial Search • This Class – Pruning

Review • Last Class – Games – Adversarial Search • This Class – Pruning a Game Tree • Next Class – Knowledge-based Agent Artificial Intelligence

Imperfect Decisions • complete search is impractical for most games – Even though we

Imperfect Decisions • complete search is impractical for most games – Even though we can prune the tree • alternative: – search only part of the tree • Cutoff required • requires a cutoff-test to determine where to stop – use a heuristics-based evaluation function to estimate the expected utility of the game from a given position Artificial Intelligence

Evaluation Function • • determines the performance of a game-playing program must be consistent

Evaluation Function • • determines the performance of a game-playing program must be consistent with the utility function – values for terminal nodes must be the same • tradeoff between accuracy and time cost – without time limits, minimax could be used • • should reflect the actual chances of winning frequently weighted linear functions are used – E = w 1 f 1 + w 2 f 2 + … + w n fn – combination of features, weighted by their relevance Artificial Intelligence

Example: Tic-Tac-Toe • simple evaluation function E(s) = (rx + cx + dx) -

Example: Tic-Tac-Toe • simple evaluation function E(s) = (rx + cx + dx) - (ro + co + do) where r, c, d are the numbers of row, column and diagonal lines still available; x and o are the pieces of the two players • 1 -ply lookahead – start at the top of the tree – evaluate all 9 choices for player 1 – pick the maximum E-value • 2 -ply lookahead – also looks at the opponents possible move • assuming that the opponents picks the minimum E-value Artificial Intelligence

Tic-Tac-Toe 1 -Ply E(s 0) = Max{E(s 11), E(s 1 n)} = Max{2, 3,

Tic-Tac-Toe 1 -Ply E(s 0) = Max{E(s 11), E(s 1 n)} = Max{2, 3, 4} = 4 E(s 11) 8 X -5 =3 E(s 12) X 8 -6 =2 Artificial Intelligence E(s 13) X 8 -5 =3 E(s 14) 8 -6 X =2 E(s 15) 8 X -4 =4 E(s 16) 8 X- 6 =2 E(s 17) 8 -5 X =3 E(s 18) 8 -6 X =2 E(s 19) 8 -5 X= 3

Tic-Tac-Toe 2 -Ply E(s 0) = Max{E(s 11), E(s 1 n)} = Max{2, 3,

Tic-Tac-Toe 2 -Ply E(s 0) = Max{E(s 11), E(s 1 n)} = Max{2, 3, 4} = 4 E(s 1: 1) 8 X -5 =3 E(s 1: 2) X 8 -6 =2 E(s 1: 3) X 8 -5 =3 E(s 1: 4) 8 -6 X =2 E(s 1: 5) 8 X -4 =4 E(s 1: 6) 8 X- 6 =2 E(s 1: 7) 8 -5 X =3 E(s 1: 8) 8 -6 X =2 E(s 2: 41) 5 O X -4 =1 E(s 2: 42) O 6 X -4 =2 E(s 2: 43) O 5 X -4 =1 E(s 2: 44) 6 OX - 4 =2 E(s 2: 45) 6 X O- 4 =2 E(s 2: 46) 5 X -4 O =1 E(s 2: 47) 6 X -4 O =2 E(s 2: 48) 5 X -4 O= 1 E(s 2: 9) 5 OX -6 = -1 E(s 2: 10) XO 5 -6 = -1 E(s 2: 11) X 5 -6 O = -1 E(s 2: 12) 5 X O -6 = -1 E(s 2: 13) 5 X O-6 = -1 E(s 2: 14) 5 X -6 O = -1 E(s 2: 15) 5 X -6 O = -1 E(s 2: 16) 5 X -6 O = -1 E(s 22) X O 5 -5 =0 E(s 23) 6 X -5 O =1 E(s 24) E(s 25) 4 X 6 X O -5 O- 5 = -1 =1 E(s 26) 5 X -5 O =0 E(s 27) 6 X -5 O =1 E(s 28) 5 X -5 O= 0 E(s 21) XO 6 -5 =1 Artificial Intelligence E(s 1: 9) 8 -5 X= 3

Checkers Case Study • initial board configuration – Black – Red single on 20

Checkers Case Study • initial board configuration – Black – Red single on 20 single on 21 king on 31 single on 23 king on 22 – evaluation function E(s) = (5 x 1 + x 2) - (5 r 1 + r 2) where x 1 = black king advantage, x 2 = black single advantage, r 1 = red king advantage, r 2 = red single advantage 1 5 6 9 13 7 14 21 3 10 17 12 16 19 23 26 30 8 15 22 4 11 18 25 29 Artificial Intelligence 2 20 24 27 31 28 32

Checkers Minimax Example 3 6 10 15 18 22 25 20 23 27 1

Checkers Minimax Example 3 6 10 15 18 22 25 20 23 27 1 28 0 22 -> 26 25 -> 0 0 -4 -4 -8 -8 17 0 21 -> 2 20 -> 16 1 > 17 1 21 - 16 -> 11 -8 20 -> 16 1 > 17 31 -> 27 22 -8 21 - > 27 16 -> 11 32 30 31 - -> -> 31 1 -4 27 -> 31 > 26 31 - 6 4 1 -> 2 1 MIN MAX 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 13 6 -8 27 1 >1 6 1 1 -> 14 1 1 18 -> 2 6 221 -> 31 21 -> 17 6 -> 2 23 23 -> 262 -8 23 32 MAX 23 31 27 22 -> 30 24 -> 22 -> 29 16 19 26 20 -> 26 21 12 31 7 17 11 16 -> 14 8 31 13 7 21 -> 1 9 1 4 20 -> 16 5 2 20 -> 16 1 -8 -8

Difficulty in Evaluation Function • • Very difficult to develop an appropriate evaluation function

Difficulty in Evaluation Function • • Very difficult to develop an appropriate evaluation function Example – Two slightly different chess positions • A. black has an advantage of a knight and two pawns and will win the game • B. back will lose after white captures the queen Artificial Intelligence

Horizon Problem • moves may have disastrous consequences in the future, but the consequences

Horizon Problem • moves may have disastrous consequences in the future, but the consequences are not visible – the corresponding change in the evaluation function will only become evident at deeper levels • they are “beyond the horizon” • determining the horizon is an open problem without a general solution – only some pragmatic approaches restricted to specific games or situation Artificial Intelligence

Pruning • discards parts of the search tree – guaranteed not to contain good

Pruning • discards parts of the search tree – guaranteed not to contain good moves – high likelihood that the solution is not in the branch or subtree • results in substantial time and space savings – the leftover part of the task may still be exponential, however Artificial Intelligence

Mathematics under Pruning MINIMAX-VALUE(root) =max(min(3, 12, 8), min(2, x, y), min(14, 5, 2)) =max(3,

Mathematics under Pruning MINIMAX-VALUE(root) =max(min(3, 12, 8), min(2, x, y), min(14, 5, 2)) =max(3, min(2, x, y), 2) In such a case, regardless what value x and y will be, it wouldn’t affect the minimax value. Artificial Intelligence

Alpha-Beta Pruning • moves that with certainty won’t result in a better evaluation value

Alpha-Beta Pruning • moves that with certainty won’t result in a better evaluation value than a move further up in the tree are not considered – they would lead to a less desirable outcome • applies to moves by both players – a indicates the best choice for Max so far never decreases – b indicates the best choice for Min so far never increases • extension of the minimax approach – results in the same move as minimax, but with less overhead – prunes uninteresting parts of the search tree Artificial Intelligence

Alpha-Beta Algorithm Artificial Intelligence

Alpha-Beta Algorithm Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Alpha-Beta Pruning Example Artificial Intelligence

Exercise Artificial Intelligence

Exercise Artificial Intelligence

Exercise Artificial Intelligence

Exercise Artificial Intelligence

The general case of Alpha-Beta Pruning If m is better than n for Player,

The general case of Alpha-Beta Pruning If m is better than n for Player, we will never get to n to play This is Alpha-cutting Artificial Intelligence

Checkers Alpha-Beta Example 1 1 16 31 28 32 0 20 -> 16 -4

Checkers Alpha-Beta Example 1 1 16 31 28 32 0 20 -> 16 -4 -4 -8 -8 17 0 21 -> 16 -> 11 27 20 -> 16 0 > 17 2 21 - 31 -> 27 24 -8 20 -> 16 1 > 17 1 -8 21 - 20 -> 16 22 -> 26 25 26 20 32 -> 19 -> 22 12 16 23 30 30 > 27 16 -> 11 15 22 29 -> 31 1 -4 27 -> 31 > 26 31 - 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 26 3 10 21 0 MIN -> 262 -> 26 7 1 6 9 -> 20 -> 31 31 MAX - 6 5 21 -> 1 a b 2 -8 -8

Checkers Alpha-Beta Example 1 1 7 1 31 28 32 0 20 -> 16

Checkers Alpha-Beta Example 1 1 7 1 31 28 32 0 20 -> 16 -4 -4 -8 -8 17 0 21 -> 16 -> 11 27 20 -> 16 0 > 17 2 21 - 31 -> 27 24 -8 20 -> 16 1 > 17 1 -8 21 - 20 -> 16 22 -> 26 25 26 20 32 -> 19 -> 22 12 16 23 30 30 > 27 16 -> 11 15 22 29 -> 31 1 -4 27 -> 31 > 26 31 - 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 26 3 10 21 0 MIN -> 262 -> 26 1 16 6 9 -> 20 -> 31 31 MAX - 5 21 -> 1 a b 2 -8 -8

Checkers Alpha-Beta Example 1 - 16 24 27 31 28 32 0 -4 -4

Checkers Alpha-Beta Example 1 - 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 26 3 10 21 0 MIN -> 262 -> 26 1 6 9 -> 7 b- cutoff: no need to examine further branches 20 -> 31 31 MAX 21 -> 1 1 2 5 20 -> 16 a b 1 -8 -8

Checkers Alpha-Beta Example 1 - 16 24 27 31 28 32 0 -4 -4

Checkers Alpha-Beta Example 1 - 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 27 3 10 21 0 MIN -> 262 -> 26 7 1 6 9 -> 20 -> 31 31 MAX 21 -> 1 1 2 5 20 -> 16 a b 1 -8 -8

Checkers Alpha-Beta Example 1 - 16 24 27 31 28 32 0 -4 -4

Checkers Alpha-Beta Example 1 - 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 27 3 10 21 0 MIN -> 262 -> 26 1 6 9 -> 7 b- cutoff: no need to examine further branches 20 -> 31 31 MAX 21 -> 1 1 2 5 20 -> 16 a b 1 -8 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 27 3 10 21 0 MIN -> 262 -> 26 7 1 6 9 -> 20 -> 31 31 MAX 2 5 20 -> 16 1 1 21 -> 1 a b 1 -8 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 13 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 27 3 10 21 0 MIN -> 262 -> 26 7 1 6 9 -> 20 -> 31 31 MAX 2 5 20 -> 16 1 0 21 -> 1 a b 1 -8 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 27 3 10 21 0 MIN -> 262 -> 26 1 6 9 -> 7 a- cutoff: no need to examine further branches 20 -> 31 31 MAX 2 5 20 -> 16 1 -4 21 -> 1 a b 1 -8 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8

Checkers Alpha-Beta Example 1 16 24 27 31 28 32 0 -4 -4 -8 -8 17 0 21 -> 0 20 -> 16 2 > 17 1 21 - 16 -> 11 20 -8 20 -> 16 1 > 17 31 -> 22 26 -8 21 - 20 -> 16 22 -> 26 25 -> 22 19 32 30 > 27 16 -> 11 16 23 30 12 -> -> 31 1 -4 27 -> 31 > 26 31 - 15 22 29 11 23 23 22 -> 18 1 22 -> 6 4 1 -> 2 1 31 Artificial Intelligence 1 0 27 1 1 2 -> 1 1 31 1 7 1 1 6 -8 8 18 25 -4 7 14 17 4 27 1 >1 6 -> 14 1 1 1 -> 2 6 18 31 21 -> 221 -> 6 -> 2 23 23 MAX 17 13 27 3 10 21 0 MIN -> 262 -> 26 7 1 6 9 -> 20 -> 31 31 MAX 2 5 20 -> 16 1 -8 21 -> 1 a b 1 -8 -8

Properties of Alpha-Beta Pruning • in the ideal case, the best successor node is

Properties of Alpha-Beta Pruning • in the ideal case, the best successor node is examined first – results in O(bd/2) nodes to be searched instead of O(bd) – alpha-beta can look ahead twice as far as minimax – in practice, simple ordering functions are quite useful • assumes an idealized tree model – uniform branching factor, path length – random distribution of leaf evaluation values • requires additional information for good players – game-specific background knowledge – empirical data Artificial Intelligence

Games and Computers • state of the art for some game programs – –

Games and Computers • state of the art for some game programs – – – Chess Checkers Othello Backgammon Go Artificial Intelligence

Chess • Deep Blue, a special-purpose parallel computer, defeated the world champion, Gary Kasparov

Chess • Deep Blue, a special-purpose parallel computer, defeated the world champion, Gary Kasparov – the human player didn’t show his best game – Deep Blue used a massive data base with games from the literature Artificial Intelligence

Checkers • Chinook becomes world champion in 1994 – human opponent, Dr. Marion Tinsley,

Checkers • Chinook becomes world champion in 1994 – human opponent, Dr. Marion Tinsley, withdraws for health reasons • Chinook uses off-the-shelf hardware, alpha-beta search, end-games data base for six-piece positions Artificial Intelligence

Othello • many programs play far better than humans – smaller search space than

Othello • many programs play far better than humans – smaller search space than chess – little evaluation expertise available Artificial Intelligence

Backgammon • neural-network based program ranks among the best players in the world –

Backgammon • neural-network based program ranks among the best players in the world – improves its own evaluation function through learning techniques – search-based methods are practically hopeless • chance elements, branching factor Artificial Intelligence

Go • humans play far better – large branching factor (around 360) • search-based

Go • humans play far better – large branching factor (around 360) • search-based methods are hopeless • • rule-based systems play at amateur level $2, 000 prize for the first program to defeat a top-level player – http: //www. gameai. com/clagames. html Artificial Intelligence

Summary • • • Game Tree Alpha-Beta Pruning Different Games Artificial Intelligence

Summary • • • Game Tree Alpha-Beta Pruning Different Games Artificial Intelligence

What I want you to do • • Review Chapter 7 Work on your

What I want you to do • • Review Chapter 7 Work on your assignment Artificial Intelligence