You are on page 1of 41

Problem Solving & Search

Beyond Classical Search


Informatics Engineering Study Program
School of Electrical Engineering and Informatics

Institute of Technology Bandung


Contents
 Review
 Beyond Classical Search

2 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Review
 What is AI → 4 approaches
 Intelligent Agent
 Task Environment: Remember PEAS
 6 Environment Types
 Problem Solving Agent
 4 components to be defined: initial state,
operator/successor function, goal test, path cost
 Solving by Searching:
 Informed Search
 Uninformed Search
 Beyond Classical Search → TODAY

3 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Local Search

4 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Local search algorithms
 In many optimization problems, the path to the goal is
irrelevant; the goal state itself is the solution

 State space = set of "complete" configurations

 Find configuration satisfying constraints, e.g., n-queens

 In such cases, we can use local search algorithms

 Keep a single "current" state, try to improve it

5 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Hill-climbing search
 "Like climbing Everest in thick fog with amnesia"

6 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Hill-climbing search
 Problem: depending on initial state, can get stuck in local
maxima

7 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Hill-climbing search: 8-queens
problem

Each number indicates h if we move


a queen in its corresponding column

 h = number of pairs of queens that are attacking each other, either directly or
indirectly (h = 17 for the above state)

8 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Hill-climbing search: 8-queens
problem

• A local minimum with h = 1

9 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Gradient Descent

• Assume we have some cost-function: C ( x 1 , ..., x n )


and we want minimize over continuous variables X1,X2,..,Xn


1. Compute the gradient : C ( x 1 , ..., x n ) i
x i

2. Take a small step downhill in the direction of the gradient:



x i → x 'i = x i −  C ( x 1 , ..., x n ) i
x i
3. Check if C ( x 1 , .., x 'i , .., x n )  C ( x 1 , .., x i , .., x n )

4. If true then accept move, if not reject.

5. Repeat.
10 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Simulated Annealing Search

11 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Simulated Annealing

12 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
So.... Simulated annealing search
 Idea: escape local maxima by allowing some "bad"
moves but gradually decrease their frequency

13 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Properties of simulated annealing
search
 One can prove: If T decreases slowly enough, then
simulated annealing search will find a global optimum
with probability approaching 1

 Widely used in VLSI layout, airline scheduling, etc

14 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Genetic algorithms
 A successor state is generated by combining two parent states

 Start with k randomly generated states (population)

 A state is represented as a string over a finite alphabet (often a


string of 0s and 1s)

 Evaluation function (fitness function). Higher values for better


states.

 Produce the next generation of states by selection, crossover,


and mutation

15 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Genetic algorithms

 Fitness function: number of non-attacking pairs of queens (min


= 0, max = (8 × 7)/2 = 28)

 24/(24+23+20+11) = 31%

 23/(24+23+20+11) = 29% etc


16 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Genetic algorithms: Cross-Over

32752411 24748552 32748552

17 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Adversarial Search (Games)

18 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Outline
 Optimal decisions
 α-β pruning
 Imperfect, real-time decisions

19 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Games vs. search problems
 "Unpredictable" opponent → specifying a move for every
possible opponent reply
 Time limits → unlikely to find goal, must approximate
 Task: Find the most optimal move → using certain
searching algorithm, with time limit can choose a good
move
 In a normal search problem, the optimal solution would
be a sequence of actions leading to a goal state—a
terminal state that is a win
 In adversarial search, opponent has something to say
about it.

20 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Game tree (2-player, deterministic,
turns)
• MAX’s job to search for a good move
• the term search tree for a tree that is superimposed on the full game tree:
• examines enough nodes to allow a player to determine what move to make

21 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Minimax
 Perfect play for deterministic games
 Idea: choose move to position with highest minimax value
= best achievable payoff against best play

 E.g., 2-ply game:

22 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Minimax algorithm

23 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Properties of minimax
 Complete? Yes (if tree is finite)
 Optimal? Yes (against an optimal opponent)
 Time complexity? O(bm)
 Space complexity? O(bm) (depth-first exploration)

 For chess, b ≈ 35, m ≈100 for "reasonable" games


→ exact solution completely infeasible

24 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
α-β pruning example

25 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
α-β pruning example

26 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
α-β pruning example

27 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
α-β pruning example

28 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
α-β pruning example

29 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Properties of α-β
 Pruning does not affect final result

 Good move ordering improves effectiveness of pruning

 With "perfect ordering," time complexity = O(bm/2)


→ doubles depth of search
→ See previous slide (from MIN point of view, the order is ‘worst’ value
first so it had to explore all the branches: {14,5,2})

30 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Why is it called α-β?
 α is the value of the best
(i.e., highest-value)
choice found so far at
any choice point along
the path for max
 If v is worse than α, max
will avoid it
→ prune that branch

 Define β similarly for


min

31 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
The α-β algorithm

32 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
The α-β algorithm

33 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Algorithm illustration with α-β value

34 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Resource limits
Suppose we have 100 secs, explore 104 nodes/sec
→ 106 nodes per move

Standard approach:

 cutoff test:
e.g., depth limit (perhaps add quiescence search: the main
motive of quiescence search is usually to get a good value
out of an imperfect evaluation function)
 evaluation function
= estimated desirability of position
35 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Evaluation functions
 For chess, typically linear weighted sum of features
Eval(s) = w1 f1(s) + w2 f2(s) + … + wn fn(s)

 e.g., w1 = 9 with
f1(s) = (number of white queens) – (number of black queens),
etc.

36 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Cutting off search
MinimaxCutoff is identical to MinimaxValue except
1. Terminal? is replaced by Cutoff?
2. Utility is replaced by Eval

Does it work in practice?


bm = 106, b=35 → m=4

4-ply lookahead is a hopeless chess player!


 4-ply ≈ human novice
 8-ply ≈ typical PC, human master
 12-ply ≈ Deep Blue, Kasparov

37 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Deterministic games in practice
 Checkers: Chinook ended 40-year-reign of human world champion Marion
Tinsley in 1994. Used a precomputed endgame database defining perfect
play for all positions involving 8 or fewer pieces on the board, a total of 444
billion positions.

 Chess: Deep Blue defeated human world champion Garry Kasparov in a


six-game match in 1997. Deep Blue searches 200 million positions per
second, uses very sophisticated evaluation, and undisclosed methods for
extending some lines of search up to 40 ply.

 Othello: human champions refuse to compete against computers, who are


too good.

 Go: human champions refuse to compete against computers, who are too
bad. In go, b > 300, so most programs use pattern knowledge bases to
suggest plausible moves.

38 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
Summary
 Games are fun to work on!
 They illustrate several important points about AI
 perfection is unattainable → must approximate
 good idea to think about what to think about

39 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
References
[1] Lathrop, R., Local Search Algorithm: Lecture Notes of
Introduction to Artificial Intelligence course in Computer Science
Department, University of California USA, can be accessed at:
http://www.ics.uci.edu/~rickl/courses/cs-271/2013-wq-cs271/2013-
wq-cs271-lecture-slides/2013wq271-05-LocalSearch.ppt
[2] Moore, A. W., Iterative Improvement Search: Statistical Data
Mining Tutorials, School of Computer Science, Carnegie Mellon
University USA, can be accessed at:
www.autonlab.org/tutorials/hillclimb02.pdf
[3] Hwee Tou Ng's (Singapore) course slides for AIMA, can be
accessed at: http://aima.eecs.berkeley.edu/slides-ppt/
[4] AISpace2 Tools for learning and understanding AI, can be accessed
at https://aispace2.github.io/AISpace2/index.html
40 IF3170/NUMand[1]and[2]and[3]/02-Sep-2019
THANK YOU

You might also like