Artificial Intelligence: The Search Method: Introduction To Cognitive Science
Artificial Intelligence: The Search Method: Introduction To Cognitive Science
<2,0,right>
<2,1,left>
<3,0,left> X
<3,3,left>
START
How to go from START to GOAL?
Some different Search Techniques
The previous slide illustrates that in search, we
are trying to find a path from the start state to the
goal state.
Some different techniques to do this:
Forward (or goal-directed) search: Start at the start
state, and try and work your way to the goal state
Backward search: Start at the goal state, and find
your way to the start state
Bidirectional search: Do forward and backward
search at the same time.
Subgoaling: Try and identify some intermediate
states that a solution is likely to go through, and that
would divide the problem into several smaller ones
Search Trees
Further differences in search strategies are in how paths
are explored, e.g. do you just randomly try and jump
from state to state, or do you try and explore the search
space more systematically?
One common way to try and systematically explore the
search space is through a search tree:
Start at the START state (or Goal state, or both): this is the root
of the tree, or level 0
See which states you can reach from that state: these will be
your branches at level 1
In general, from each state at level n we can see what other
states can be reached, which will be at level n + 1
Note that a state at some level may reoccur at some
later level. But obviously, we only need to explore each
state only once, so repeats can be ignored.
Illegal states are dead ends as well.
Example Search Tree
<3,3,left>
Etc.
Depth-First and Breadth-First
Search trees can be explored in different
ways as well:
Depth-First search: explore one possible
branch at a time, and only go back to explore
an earlier state and possible new branch
when you get stuck
Breadth-First search: explore all possible
branches at the same time (i.e. move from
level to level, finding all possible branches at
each level before moving on to the next level)
Example Depth-First Search
<3,3,left>
1
<1,3,right>
2
3
<3,3,left> <2,3,left> The numbers indicate the order in
repeat which branches/states are explored
4 5
<2,1,right> <0,3,right>
X 6
etc
Example Breadth-First Search
<3,3,left>
1a 1e
1b 1c 1d
Etc.
Some Advantages and
Disadvantages of these Methods
Breadth-First Search has one obvious disadvantage in
that if it takes, say, a minimum of n moves to get from
the Start state to the Goal state, and if at each level,
each state has an average of m next states (this is
called the branching factor of the tree), then before a
path is finally found, we have generated approximately
mn states. Such an exponential number can become
very large very quickly, i.e. breadth-first search can take
a *lot* of time.
Depth-first search does not have this problem, as it may
hit on the right path without having to explore all the
others. Then again, it is also possible that there may be
a very short path from Start to Goal, but that the Depth-
First method is exploring some very long paths (some
infinite!) instead. So in that case, breadth-first would
quickly find a solution, but depth-first might take much
longer, or not find a solution at all.
Example: Eight Puzzle
In the 8-puzzle, numbers can be 6 5 3
1 4 7 Start
moved left, right, up, or down
8 2
into the empty spot. The goal is
to line up all numbers.
6 5 3 6 5 3
1 4 7 1 4
8 2 8 2 7
6 5 3 6 5 3 6 5 3 6 5 6 5 3 6 5 3
1 4 7 1 7 1 4 7 1 4 3 1 4 1 4 7
8 2 8 4 2 8 2 8 2 7 8 2 7 8 2
Etc.
Note that with a branching factor of about 3, and given that in this
particular set up, we know that it must take a minimum of 12 moves
1 2 3 (since the 6 must be moved at least 3 times to get into the right
Goal: 4 5 6 spot, the 5 at least 1 time, etc.) to get to the goal, breadth-first
7 8 search will explore something like 312 (appr. 1 million) states!
Blind vs Informed Search
With the size of search trees (and the search
space) being large for even pretty simple
problems (just think of the search space for
filling in Sudoku puzzles!!), search techniques
need to get smarter in handling such big search
spaces.
One intuitive and useful heuristic for search is
that as you are exploring different states, pick
the one that gets you closest to the goal.
Search techniques that use heuristics like this
are called informed search, whereas search
techniques without any further heuristics as to
guide their search are called blind search
techniques.
Hill-Climbing
Hill-climbing is a very straightforward way
to make depth-first search a little smarter:
as you reach a new branch, generate all of
its next states, and then pick from those
the one that is most promising.
As usual with depth-first, go back when
you get stuck.
Best-First Search
A slightly more involved strategy is to keep
track of all states that you have generated
so far, and pick from all those the best
one to explore.
Thus, you are not committed to exploring
one branch, and you can jump between
different branches.
This method is called best-first search: it
is sort of between depth-first and breadth-
first, but with heuristics to guide its search.
Example: Hill-Climbing and
Best-First Search
We score every state by counting the 6 5 3
minimum number of moves that need to 1 4 7 Start
be made in order to get to the goal 8 2 12
6 5 3 6 5 3
1 4 7 1 4
8 2 13 8 2 7 11
Current state
Player 1s turn:
A B
Player 2s turn:
In other words: Player 1 can either make a risky move (A) or a more safe
Move (B). Player 1 may be attracted to A, because if player 2 isnt careful,
player 1 wins. However, if player 2 is careful, player 1 will actually lose. So,
what to do? Take the risk and hope that your opponent does something stupid,
or play it safe?
The Max-Min Strategy
One possible strategy in choosing moves is to assume
that the opponent never does something stupid, and in
fact always makes the move that is best for him/her/it.
The Max-Min strategy is based on this assumption:
Generate the search tree as far as you can
Now use some kind of scoring rubric to assign a score to the
very last states: the better it is for player 1, the higher the score
Now work your way back up the tree, and score each of the
earlier states as follows:
If it is player 1s turn, then the score is the maximum of the scores of
the states immediately below it (i.e. pick the best move for player 1)
If it is player 2s turn, then the score is the minimum of the scores of
the states immediately below it (i.e. pick the best move for player 2)
Example Max-Min Strategy
x Only some of the
Tic-Tac-Toe: o to play o
x Branches are shown!
Pick max
x x
o o
x o min = 0 x o So pick this one!
Pick min
i.e. will lead to loss
x x x
o max = 0 x o
x o x o max = 1
Pick max
x x x x o x
o o o x o
x o o min = 0 x o min = 0 x o Score = 1
Pick min
x x x x x
x o o o
x o o Score = 0 x o Score = 0
Chess, Combinatorial Explosion,
and Computers
It is estimated that the average number of
moves that one can make during a chess game
is about 30. Also, typical games of chess take
about 80 moves. So, the search tree for chess
would have about 3080 states which is about
10120 board states!!
Deep Blue, the chess computer that beat
Kasparov, was able to look about 8 moves
ahead, which means that it would consider
about 308, which is about 1012 (1 trillion),
possible board positions. Deep Blue was able to
do this because of its enormous speed.
Search and
Human Problem Solving
It is unlikely that Kasparov contemplates 1 trillion board
positions during every of his turns, and yet Kasparov can
still play almost as good as Deep Blue. So, either
Kasparov uses some very powerful heuristics that
drastically prune the search-tree, or Kasparov doesnt
use any search at all.
Many cognitive scientists believe that we heavily rely on
certain patterns that tell us that if you are in a situation
that looks like this-or-that, then make such-and-so a
move. For example, just a few of such rules allow one
to play perfect tic-tac-toe without doing any search at all.
Some cognitive scientists estimate that someone like
Kasparov has thousands of such abstract patterns
stored in his brain.
The Monk and the Mountain
Problem
One day, a monk walks to the top of a mountain, starting
at noon in the valley, walking at various speeds, and
taking various stops at various times. The next day, the
monk walks back to the valley, again starting at noon,
and using the same path, but again using various
speeds and stops.
Question: is there a point in time during the second day
at which the monk is at an exact point on the mountain
where the monk was exactly 24 hours earlier as well?
Answer: Yes, there has to be such a point. Imagine the
two walks not happening 24 hours apart, but happening
at the same time. Then at some point the monk walking
up must meet his imaginary counterpart walking down.
That very point on the mountain path must therefore be
the point we were looking for!
Insight Problems
The Monk-and-the-Mountain problem is what is
called an insight problem: solving it requires
some kind of insight.
Indeed, it is hard to see how one could try and
solve this problem using a search strategy: what
would the search space even look like?!
At this point, AI (and cognitive science) is really
at a loss explaining how insight works and how
it can be formalized.
Indeed, some people believe that AI will never
be able to capture this (much like the Lady
Lovelace argument).
The Monkey and the Banana
In one study on monkeys problem-solving powers,
experimenters hung a banana from the ceiling in a room,
where there was also a box and a stick.
The banana was placed at such a height, that the
monkey could only reach the banana by placing the box
right under the banana, standing on the box, and
swinging the stick at the banana.
Some monkeys solved this problem, but not all.
How would an AI do?
Well, suppose we were to provide the AI with the
following operators: move-box-under-banana, grab-
stick, climb-on-box, and swing-stick-at-banana. Would
an AI search algorithm find the solution?
The Mutilated Chess-Board
Problem
Can you place dominoes onto this
mutilated chessboard such that all
squares are covered?
START GOAL
A move consists of taking a disc from the top of a pile of discs on
any peg and move it on top of a pile of discs on any other peg.
You can never have a disc on top of a larger disc.
13 12 32 31 13 12 23 21
? ?
HW 2: The Towers of Hanoi
Depth-First Use this order:
13
13
12
23
21
32
31
13 12
13 12 23
?
X X X