2. NPTEL Links (Unit-1)
S.No Topics (Associated with Unit
-1)
NPTEL Video
Link:
1 Introduction to Artificial
Intelligence
https://nptel.ac.in/co
urses/106/105/1061
05077/
2 Intelligent Agents
3 Uninformed Search
4 Informed Search
5 Informed Search - 2
6 Two Players Games - I
3. NPTEL Links (Unit-1)
S.No Topics (Associated with Unit
-1)
NPTEL Video
Link:
7 Constraint Satisfaction
Problems 2
https://nptel.ac.in/co
urses/106/105/1061
05077/
8 Two Players Games - II
9 State Space Search
4. Course Learning Outcomes
At the end of this course:
• Knowledge and understanding
You should have a knowledge and understanding of the basic concepts
of Artificial Intelligence including Search, Game Playing, KBS (including
Uncertainty), Planning and Machine Learning.
• Intellectual skills
You should be able to use this knowledge and understanding of
appropriate principles and guidelines to synthesise solutions to tasks
in AI and to critically evaluate alternatives.
• Practical skills
You should be able to use a well known declarative language (Prolog)
and to construct simple AI systems.
• Transferable Skills
You should be able to solve problems and evaluate outcomes and
alternatives
5. Artificial Intelligence
Artificial intelligence (AI), the ability of a digital
computer or computer-controlled robot to
perform tasks commonly associated with
intelligent beings. The term is frequently applied
to the project of developing systems endowed
with the intellectual processes characteristic of
humans, such as the ability to reason, discover
meaning, generalize, or learn from past
experience.
6. Areas of AI and Some
Dependencies
Sear
ch
Visi
on
Planni
ng
Machi
ne
Learni
ng
Knowledg
e
Representa
tion
Log
ic
Expert
Syste
ms
Roboti
cs
NL
P
7. What is Artificial
Intelligence ?
• the study of computations that make it possible to
perceive, reason and act ?
• a field of study that seeks to explain and emulate
intelligent behaviour in terms of computational
processes ?
• a branch of computer science that is concerned with
the automation of intelligent behaviour ?
• anything in Computing Science that we don't yet know
how to do properly ? (!)
8. What is Artificial
Intelligence ?
• the study of computations that make it possible to
perceive, reason and act ?
• a field of study that seeks to explain and emulate
intelligent behaviour in terms of computational
processes ?
• a branch of computer science that is concerned
with the automation of intelligent behaviour ?
• anything in Computing Science that we don't yet
know how to do properly ? (!)
9. What is Artificial
Intelligence ?
Systems that act
rationally
Systems that think
like humans
Systems that think
rationally
Systems that act
like humans
THOUGHT
BEHAVIOUR
HUMAN RATIONAL
10. Systems that act like humans:
Turing Test
• “The art of creating machines that
perform functions that require
intelligence when performed by
people.” (Kurzweil)
• “The study of how to make computers
do things at which, at the moment,
people are better.” (Rich and Knight)
11. Systems that act like
humans
• You enter a room which has a
computer terminal. You have a fixed
period of time to type what you
want into the terminal, and study
the replies. At the other end of the
line is either a human being or a
computer system.
• If it is a computer system, and at the
end of the period you cannot
reliably determine whether it is a
system or a human, then the system
is deemed to be intelligent.
?
12. Systems that act like humans
• The Turing Test approach
– a human questioner cannot tell if
• there is a computer or a human
answering his question, via teletype
(remote communication)
– The computer must behave
intelligently
• Intelligent behavior
– to achieve human-level
performance in all cognitive tasks
13. Systems that act like humans
• These cognitive tasks include:
– Natural language processing
• for communication with human
– Knowledge representation
• to store information effectively &
efficiently
– Automated reasoning
• to retrieve & answer questions using
the stored information
– Machine learning
• to adapt to new circumstances
14. The total Turing Test
• Includes two more issues:
– Computer vision
• to perceive objects (seeing)
– Robotics
• to move objects (acting)
15. What is Artificial
Intelligence ?
Systems that act
rationally
Systems that think
like humans
Systems that think
rationally
Systems that act
like humans
THOUGHT
BEHAVIOUR
HUMAN RATIONAL
16. Goals of AI
• To make computers more useful by letting
them take over dangerous or tedious tasks
from human
• Understand principles of human intelligence
17. The Foundation of AI
• Philosophy
– At that time, the study of human intelligence
began with no formal expression
– Initiate the idea of mind as a machine and its
internal operations
18. The Foundation of AI
Mathematics formalizes the three main area of
AI: computation, logic, and probability
Computation leads to analysis of the problems that
can be computed
complexity theory
Probability contributes the “degree of belief” to
handle uncertainty in AI
Decision theory combines probability theory and
utility theory (bias)
19. The Foundation of AI
• Psychology
– How do humans think and act?
– The study of human reasoning and acting
– Provides reasoning models for AI
– Strengthen the ideas
• humans and other animals can be considered as
information processing machines
20. The Foundation of AI
• Computer Engineering
– How to build an efficient computer?
– Provides the artifact that makes AI application
possible
– The power of computer makes computation of
large and difficult problems more easily
– AI has also contributed its own work to computer
science, including: time-sharing, the linked list
data type, OOP, etc.
21. The Foundation of AI
• Control theory and Cybernetics
– How can artifacts operate under their own control?
– The artifacts adjust their actions
• To do better for the environment over time
• Based on an objective function and feedback from the
environment
– Not limited only to linear systems but also other
problems
• as language, vision, and planning, etc.
22. The Foundation of AI
• Linguistics
– For understanding natural languages
• different approaches has been adopted from the
linguistic work
– Formal languages
– Syntactic and semantic analysis
– Knowledge representation
23. – more powerful and more useful computers
– new and improved interfaces
– solving new problems
– better handling of information
– relieves information overload
– conversion of information into knowledge
Some Advantages of
Artificial Intelligence
24. The Disadvantages
– increased costs
– difficulty with software
development - slow and expensive
– few experienced programmers
– few practical products have
reached the market as yet.
35. AI Applications
Other application areas:
• Bioinformatics:
– Gene expression data analysis
– Prediction of protein structure
• Text classification, document sorting:
– Web pages, e-mails
– Articles in the news
• Video, image classification
• Music composition, picture drawing
• Natural Language Processing .
• Perception.
36. A Brief History of AI
The gestation of AI (1943 - 1956):
- 1943: McCulloch & Pitts: Boolean circuit model of brain.
- 1950: Turing’s “Computing Machinery and Intelligence”.
- 1956: McCarthy’s name “Artificial Intelligence” adopted.
Early enthusiasm, great expectations (1952 - 1969):
- Early successful AI programs: Samuel’s checkers,
Newell & Simon’s Logic Theorist, Gelernter’s Geometry Theorem Prover.
- Robinson’s complete algorithm for logical reasoning.
36
37. A Brief History of AI
A dose of reality (1966 - 1974):
- AI discovered computational complexity.
- Neural network research almost disappeared after
Minsky & Papert’s book in 1969.
Knowledge-based systems (1969 - 1979):
- 1969: DENDRAL by Buchanan et al..
- 1976: MYCIN by Shortliffle.
- 1979: PROSPECTOR by Duda et al..
37
38. A Brief History of AI
AI becomes an industry (1980 - 1988):
- Expert systems industry booms.
- 1981: Japan’s 10-year Fifth Generation project.
The return of NNs and novel AI (1986 -
present):
- Mid 80’s: Back-propagation learning algorithm
reinvented.
- Expert systems industry busts.
- 1988: Resurgence of probability.
- 1988: Novel AI (ALife, GAs, Soft Computing, …).
- 1995: Agents everywhere.
- 2003: Human-level AI back on the agenda.
38
39. Task Domains of AI
• Mundane Tasks:
– Perception
• Vision
• Speech
– Natural Languages
• Understanding
• Generation
• Translation
– Common sense reasoning
– Robot Control
• Formal Tasks
– Games : chess, checkers etc
– Mathematics: Geometry, logic, Proving properties of
programs
• Expert Tasks:
– Engineering ( Design, Fault finding, Manufacturing
planning)
– Scientific Analysis
– Medical Diagnosis
– Financial Analysis
39
40. AI Technique
• Intelligence requires Knowledge
• Knowledge possesses less desirable properties such as:
– Voluminous
– Hard to characterize accurately
– Constantly changing
– Differs from data that can be used
• AI technique is a method that exploits knowledge that should be
represented in such a way that:
– Knowledge captures generalization
– It can be understood by people who must provide it
– It can be easily modified to correct errors.
– It can be used in variety of situations
40
41. The State of the Art
Computer beats human in a chess game.
Computer-human conversation using speech
recognition.
Expert system controls a spacecraft.
Robot can walk on stairs and hold a cup of
water.
Language translation for webpages.
Home appliances use fuzzy logic.
41
42. Examples of Problems: Towers of
Hanoi
• 3 pegs A, B, C
• 3 discs represented as
natural numbers (1, 2, 3)
which correspond to the
size of the discs
• The three discs can be
arbitrarily distributed
over the three pegs,
such that the following
constraint holds:
di is on top of dj → di < dj
• Initial status: ((123)()())
• Goal status: (()()(123))
3
2
1
A B C
Operators:
Move disk to peg
Applying: Move 1 to C (1 → C)
to the initial state ((123)()())
a new state is reached
((23)()(1))
Cycles may appear in the
solution!
43. Examples of Problems:
Blocksworld
• Objects: blocks
• Attributes (1-ary
relations):
cleartop(x),
ontable(x)
• Relations: on(x,y)
• Operators:
puttable(x) where x
must be cleartop;
put(x,y), where x
and y must be
cleartop
E
A
B
C
D
Goal State
E A B C
D
Initial State
• Initial state:
– ontable(E), cleartop(E)
– ontable(A), cleartop(A)
– ontable(B), cleartop(B)
– ontable(C)
– on(D,C), cleartop (D)
• Applying the move
put(E,A):
– on(E,A), cleartop(E)
– ontable(A)
– ontable(B), cleartop(B)
– ontable(C)
– on(D,C), cleartop (D)
45. Search Space Representation
• Representing the search
space is the first step to enable
the problem resolution
• Search space is mostly
represented through graphs
• A graph is a finite set of nodes
that are connected by arcs
• A loop may exist in a graph,
where an arc lead back to the
original node
• In general, such a graph is not
explicitly given
• Search space is constructed
during search
Loop
Node
Arc
46. Search Space Representation
• A graph is undirected if arcs
do not imply a direction,
direct otherwise
• A graph is connected if
every pair of nodes is
connected by a path
• A connected graph with no
loop is called tree
• A weighted graph, is a
graph for which a value is
associated to each arc
undirect direct
connected disconnected
tree
weighted
1
2
4
1
5
6
2
1
1
47. Example: Towers of Hanoi*
3
2
1
A B C
3
2
A B C
3
2
A B C
1 1
* A partial tree search space representation
3
A B C
1
2 3
2
A B C
1
…
3
A B C
1
2
A B C
1
2 3
3
A B C
1
2
…
…
3
A B C
1 2
…
3
A B C
1
2 3
A B C
1
2
…
…
…
… …
…
These nodes
are equals
48. Example: Towers of Hanoi*
* A complete direct graph representation
[http://en.wikipedia.org/wiki/Tower_of_Hanoi]
49. Search Methods
• A search method is defined by picking the order of node
expansion
• Strategies are evaluated along the following dimensions:
– completeness: does it always find a solution if one exists?
– time complexity: number of nodes generated
– space complexity: maximum number of nodes in memory
– optimality: does it always find the shortest path solution?
• Time and space complexity are measured in terms of
– b: maximum branching factor of the search tree
– d: depth of the shortest path solution
– m: maximum depth of the state space (may be ∞)
50. Search Methods
• Uninformed techniques
– Systematically search complete graph,
unguided
– Also known as brute force, naïve, or blind
• Informed methods
– Use problem specific information to guide
search in promising directions
52. Uninformed Search
• A class of general purpose algorithms that operates in a brute force way
– The search space is explored without leveraging on any information on the problem
• Also called blind search, or naïve search
• Since the methods are generic they are intrinsically inefficient
• E.g. Random Search
– This method selects randomly a new state from the current one
– If the goal state is reached, the search terminates
– Otherwise the methods randomly select an other operator to move to the next state
• Prominent methods:
– Depth-First Search
– Breadth-First Search
– Uniform-Cost Search
53. Depth-First Search
• Depth-First Search (DFS) begins at the root node and exhaustively search
each branch to it maximum depth till a solution is found
– The successor node is selected going in depth using from right to left (w.r.t. graph
representing the search space)
• If greatest depth is reach with not solution, we backtrack till we find an
unexplored branch to follow
• DFS is not complete
– If cycles are presented in the graph, DFS will follow these cycles indefinitively
– If there are no cycles, the algorithm is complete
– Cycles effects can be limited by imposing a maximal depth of search (still the
algorithm is incomplete)
• DFS is not optimal
– The first solution is found and not the shortest path to a solution
• The algorithm can be implemented with a Last In First Out (LIFO) stack or
recursion
54. Depth-First Search: Algorithm
List open, closed, successors={};
Node root_node, current_node;
insert-first(root_node,open)
while not-empty(open);
current_node= remove-first(open);
insert-first (current_node,closed);
if (goal(current_node)) return current_node;
else
successors=successorsOf(current_node);
for(x in successors)
if(not-in(x,closed)) insert-first(x,open);
endIf
endWhile
N.B.= this version is not saving the path for simplicity
55. Depth-First Search: Example
S
A B
S B
S A D
F
F
1
2
3
4
5
6
A C D
F
open={S} closed ={}
0. Visit S: open={A,B}, closed={S}
1.Visit A: open={S,B,F,B}, closed={A,S}
2.Visit S: open={B,F,B}, closed={S,A,S}
3.Visit B: open={S,A,F,D,F,B}, closed={B,S,A,S}
4.Visit S: open={A,F,D,F,B}, closed={S,B,S,A,S}
5.Visit A: open={F,D,F,B}, closed={A,S,B,S,A,S}
6.Visit F: GOAL Reached!
57. Depth-First Search: Complexity
• Time Complexity
– assume (worst case) that
there is 1 goal leaf at the
RHS
– so DFS will expand all
nodes
=1 + b + b2+ ......... +
bm
= O (bm)
– where m is the max depth of
the tree
• Space Complexity
– how many nodes can be in
the queue (worst-case)?
– at each depth l < d we have
b-1 nodes
– at depth m we have b nodes
– total = (d-1)*(b-1) + b =
O(bm)
d=0
d=1
m=d=2
G
d=
0
d=
1
d=2
d=3
m=d=4
58. Breadth-First Search
• Breadth-First Search (BFS) begins at the root
node and explore level-wise al the branches
• BFS is complete
– If there is a solution, BFS will found it
• BFS is optimal
– The solution found is guaranteed to be the shortest
path possible
• The algorithm can be implemented with a First In
First Out (FIFO) stack
59. Breadth-First Search: Algorithm
List open, closed, successors={};
Node root_node, current_node;
insert-last(root_node,open)
while not-empty(open);
current_node=remove-first(open);
insert-last(current_node,closed);
if (goal(current_node)) return current_node;
else
successors=successorsOf(current_node);
for(x in successors)
if(not-in(x,closed)) insert-last(x,open);
endIf
endWhile
N.B.= this version is not saving the path for simplicity
60. Breadth-First Search: Example
S
A B
S B
S A D
F
F
1
2
3
4 5
open = {S}, closed={}
0. Visit S: open = {A,B}, closed={S}
1. Visit A: open={B,S,B,F}, closed={S,A}
2. Visit B: open={S,B,F,F,A,C,D}, closed={S,A,B}
3. Visit S: open={B,F,F,A,C,D}, closed={S,A,B,S}
4. Visit B: open={F,F,A,C,D,S,A,C,D},
closed={S,A,B,S,B}
5. Visit F: Goal Found!
A C D
F
62. Breadth-First Search: Complexity
• Time complexity is the
same magnitude as
DFS
– O (bm)
– where m is the depth
of the solution
• Space Complexity
– how many nodes can
be in the queue
(worst-case)?
– assume (worst case)
that there is 1 goal
leaf at the RHS
– so BFS will store all
nodes
=1 + b + b2+
......... + bm
= O (bm)
1
3
7
15
14
13
12
11
10
9
8
4 5 6
2
d=
0
d=
1
d=
2
d=
3
d=
4
G
63. Further Uninformed Search
Strategies
• Depth-limited search (DLS): Impose a cut-off (e.g. n
for searching a path of length n-1), expand nodes with
max. depth first until cut-off depth is reached (LIFO
strategy, since it is a variation of depth-first search).
• Bidirectional search (BIDI): forward search from initial
state & backward search from goal state, stop when
the two searches meet. Average effort O(bd/2) if
testing whether the search fronts intersect has
constant effort
• In AI, the problem graph is typically not known. If the
graph is known, to find all optimal paths in a graph
with labelled arcs, standard graph algorithms can be
used
64. Using knowledge on the search space to reduce search costs
INFORMED SEARCH
65. Informed Search
• Blind search methods take O(bm) in the
worst case
• May make blind search algorithms
prohibitively slow where d is large
• How can we reduce the running time?
– Use problem-specific knowledge to pick which
states are better candidates
66. Informed Search
• Also called heuristic search
• In a heuristic search each state is
assigned a “heuristic value” (h-value) that
the search uses in selecting the “best”
next step
• A heuristic is an operationally-effective
nugget of information on how to direct
search in a problem space
• Heuristics are only approximately correct
68. Cost and Cost Estimation
f(n)=g(n)+h(n)
• g(n) the cost (so far) to reach the node n
• h(n) estimated cost to get from the node to
the goal
• f(n) estimated total cost of path through n
to goal
69. Informed Search: Best-First Search
• Special case of breadth-first search
• Uses h(n) = heuristic function as its evaluation function
• Ignores cost so far to get to that node (g(n))
• Expand the node that appears closest to goal
• Best First Search is complete
• Best First Search is not optimal
– A solution can be found in a longer path (higher h(n) with a
lower g(n) value)
• Special cases:
– uniform cost search: f(n) = g(n) = path to n
– A* search
69
70. Best-First Search: Algorithm
List open, closed, successors={};
Node root_node, current_node;
insert-last(root_node,open)
while not-empty(open);
current_node=remove-first (open);
insert-last(current_node,closed);
if (goal(current_node)) return current_node;
else
successors=estimationOrderedSuccessorsOf(current_node);
for(x in successors)
if(not-in(x,closed)) insert-last(x,open);
endIf
endWhile
70
N.B.= this version is not saving the path for simplicity
returns the list of
direct descendants
of the current node
in shortest cost
order
71. Best-First Search: Example
71
S
A B
S B
S A D
F
F
1
2
3
open = {S}, closed={}
0. Visit S: open = {A,B}, closed={S}
1. Visit A: open={B,F,B,S},
closed={S,A}
2. Visit B: open={F,B,S,F,A,C,D},
closed={S,A,B}
3. Visit F: Goal Found!
A C D
F
h=1 h=1
h=2
h=2
h=2 h=2
h=2
h=2
h=2
In this case we estimate the cost as the distance from the root node (in term of nodes)
72. Best-First Search: Example
72
S
A B
S B
S A D
F
F A C D
F
Result is: S->A->F!
If we consider real costs, optimal
solution is:
S->B->F
h=1, w=2 h=1, w=1
h=2, w=4
h=2
h=2 h=2
h=2, w=7
h=2
h=2
73. A*
• Derived from Best-First Search
• Uses both g(n) and h(n)
• A* is optimal
• A* is complete
74. A* : Algorithm
List open, closed, successors={};
Node root_node, current_node, goal;
insert-back(root_node,open)
while not-empty(open);
current_node=remove-front(open);
insert-back(current_node,closed);
if (current_node==goal) return current_node;
else
successors=totalEstOrderedSuccessorsOf(current_node);
for(x in successors)
if(not-in(x,closed)) insert-back(x,open);
endIf
endWhile
74
N.B.= this version is not saving the path for simplicity
returns the list of
direct descendants
of the current node
in shortest total
estimation order
75. A* : Example
75
S
A B
S B
S A D
F
F
1
2
3
open = {S}, closed={}
0. Visit S: open = {B,A}, closed={S}
1. Visit B: open={A,C,A,F,D}, closed={S,B}
2. Visit A: open={C,A,F,D,B,S,F}, closed={S,B,A}
3. Visit C: open={A,F,D,B,S,F}, closed={S,B,A,C}
4. Visit A: open={F,D,B,S,F}, closed={S,B,A,C,A}
5. Visit F: Goal Found!
A C D
F
h=2,
w=1
g=3
h=2,
w=2,
g=4
In this case we estimate the cost as the distance from the root node (in term of nodes)
h=1, w=2, g=2 h=1, w=1, g=1
h=2, w=4, g=5
h=2, w=7, g=9
h=2,
w=1
g=2
h=2
w=3
g=4
h=2, w=4, g=5
4
5
76. A* : Example
76
S
A B
S B
S A D
F
F A C D
F
h=2,
w=1
g=3
h=2,
w=2,
g=4
h=1, w=2, g=2 h=1, w=1, g=1
h=2, w=4, g=5
h=2, w=7, g=9
h=2,
w=1
g=2
h=2
w=3
g=4
h=2, w=4, g=5
Result is: S->B->F!
77. Hill Climbing
• Special case of depth-first search
• Uses h(n) = heuristic function as its
evaluation function
• Ignores cost so far to get to that node (g(n))
• Expand the node that appears closest to goal
• Hill Climbing is not complete
– Unless we introduce backtracking
• Hill Climbing is not optimal
– Solution found is a local optimum
78. Hill Climbing: Algorithm
List successors={}; Node root_node, current_node,
nextNode;
current_node=root_node
while (current_node!=null)
if (goal(current_node)) return current_node;
else
successors=successorsOf(current_node);
nextEval = -∞; nextNode=null;
for(x in successors)
if(eval(x)> nextEval)
nexEval=eval(x);
nextNode=x;
current_node=nextNode,
endIf
endWhile
78
N.B.= this version is not using backtracking
79. Hill Climbing: Example
79
S
A B
S B
S A D
F
F
1
2
3 0. current_node=S, successors
(A=1,B=1)
1. current_node=A, successors
(B=2,F=2,S=2)
2. current_node=B, successors
(F=1,….)
3. current_node=F: Goal Found!
A C D
F
h=1 h=1
h=2
h=2
h=2 h=2
h=2
h=2
h=3
In this case we estimate the cost as the distance from the root node (in term of nodes)
h=1
80. Hill Climbing: Example
80
S
A B
S B
S A D
F
F A C D
F
h=1 h=1
h=2
h=2
h=2 h=2
h=2
h=2
h=3
h=1
Result is: S->A->B->F!
Not optimal, more if at step 1
h(S)=2 we would have completed
without funding a solution
81. Informed Search Algorithm
Comparison
Algorithm Time Space Optimal Complete Derivative
Best First
Search
O(bm) O(bm) No Yes BFS
Hill
Climbing
O() O(b) No No
A* O(2N) O(bd) Yes Yes Best First
Search
81
b, branching factor
d, tree depth of the solution
m, maximum tree depth
83. Route Search
• Start point:
Milan
• End point:
Innsbruck
• Search
space: Cities
– Nodes:
Cities
– Arcs:
Roads
• Let’s find a
possible
route!
84. Graph Representation
• We start from
the root node,
and pick the
leaves
• The same apply
to each leaves
– But we do
not
reconsider
already used
arcs
• The first node
picked is the
first node on
the right
Innsbruck (Goal)
Milan (Root)
Piacenza
Verona
Bolzano
Trento
Merano
Landeck
Sondrio
Bergamo
Brescia
Lecco
Como
Lugano
Chiavenna
Feldkirck
20
87. Depth-First Search vs Breadth-First
search
• Distance
– DFS: 464 km
– BFS: 358 km
– Q1: Can we use an algorithm to optimize according to distance?
• Time
– DFS: 4 hours 37 mins
– BFS: 5 hours 18 mins
– Q2: Can we use an algorithm to optimize according to time?
• Search space:
– DFS: 5 expansions
– BFS: 26 expansions
– Not very relevant… depends a lot on how you pick the order of node expansion, never the
less BFS is usually more expensive
• To solve Q1 and Q2 we can apply for example and Best-First Search
– Q1: the heuristic maybe the air distance between cities
– Q2: the heuristic maybe the air distance between cities x average speed (e.g. 90km/h)
91. Variants to presented algorithms
• Combine Depth First Search and Breadth First Search, by
performing Depth Limited Search with increased depths until a goal
is found
• Enrich Hill Climbing with random restart to hinder the local maximum
and foothill problems
• Stochastic Beam Search: select w nodes randomly; nodes with
higher values have a higher probability of selection
• Genetic Algorithms: generate nodes like in stochastic beam search,
but from two parents rather than from one
93. Summary
• Uninformed Search
– If the branching factor is small, BFS is the best
solution
– If the tree is depth IDS is a good choice
• Informed Search
– Heuristic function selection determines the efficiency
of the algorithm
– If actual cost is very expensive to be computed, then
Best First Search is a good solution
– Hill climbing tends to stack in local optimal solutions
94. Motivations
• Breadth-first, depth-first, hill-climbing, best-first, and
A* assume a non-hostile search space.
• The goals just sit there somewhere in the graph.
• The goals do not try to elude you.
• The 8-puzzle game did not try to stop you from
reaching the goal.
• Your tic-tac-toe opponents reacted to your moves
randomly.
• But in a real 2-person game, you opponent does try to
beat you and make it difficult for you to reach your
goal.
• Minimax search can be applied in an adversarial search
space.
• Alpha-beta pruning can be used to cut bad branches
(moves) in the game tree to improve minimax search
time.
95. Objectives
1. Adversarial search space: MAX vs. MIN
2. A simple game tree: Nim-7
3. Minimax on Nim-7
4. Minimax on tic-tac-toe looking 3 plies ahead
5. Alpha-beta pruning
96. Two people games
• Solved games
– Tic-tac-toe
– Four In A Line
– Checkers
• Impressive games played by robots
– Othello bot is much stronger than any human player
– Computer chess beat the human world champions
– TD-Gammon ranked among top 3 players in the
backgammon world
• Future bot challenges to humans
– Poker bots play respectfully at world-class level
– Computer bridge programs play competitively at
national level
– Go bots are getting more serious in the amateur
ranking
97. Complete game tree for Nim-7
• 7 coins are placed on a
table between the two
opponents
• A move consists of
dividing a pile of coins
into two nonempty piles
of different sizes
• For example, 6 coins can
be divided into piles of 5
and 1 or 4 and 2, but not
3 and 3
• The first player who can
no longer make a move
loses the game
P1 starts
P2 replies
P1
P2
P1
P2 loses
P1 loses
P2 loses
98. Node score =
0 means MIN
wins.
1 means MAX
wins.
Bold edges
indicate
forced win for
MAX, Player2.
moves first to minimize
to maximize
MAX wins
MIN wins
MIN vs. MAX in a Nim game
MIN wins
The best that MIN (Player1)
can do is to lose unless
Player2 makes a mistake.
99. Minimax to fixed ply depth
• Instead of Nim-7, image the chess game tree.
• Chess game tree is too deep.
– cannot expand the current node to terminating (leaf)
nodes for checkmate.
• Use fixed ply depth look-ahead.
– Search from current position to all possible positions
that are, e.g., 3-plies ahead.
• Use heuristic to evaluate all these future positions.
– P=1, N=B=3, R=5, Q=9
– Assign certain weight to certain features of the position
(dominance of the center, mobility of the queen, etc.)
– summarize these factors into a single number.
• Then propagating the scores back to the current node.
100. Use heuristic h(n) for each of these future positions.
Back
propagate
the scores up
the tree.
= current node score
MAX calculates the current node
score
hopes for the best
also hopes for the best
Look 3 plies ahead.
A stronger heuristic will beat a weaker heuristic.
A farther look-ahead will beat a near-sighted look-ahead.
Computer chess routinely uses complex heuristics analyzing
material and positional advantages and looks 40 plies ahead.
102. Tic-tac-toe, MAX vs MIN, 2-ply look-
ahead
MIN tries
his best to
minimize.
MIN tries his
best to
minimize.
MIN tries his
best to
minimize.
MAX hopes
to win by
maximizing.
Fig. 4.23
MAX's score at the opening is 1. So
according to this heuristic, Play 1
has advantage.
103. MAX makes his first move
MAX hopes
to win by
maximizing.
But MIN then
builds another
minimax tree with
2 plies look-ahead
from here and
decided to reply
with
MAX though
MIN's best
reply was
105. MAX's 3rd move: look ahead analysis
−∞ means MIN wins.
+∞ means MAX wins.
Fig. 4.25
106. Alpha-beta pruning example
Unevaluated nodes
Minimax without pruning
Depth-first search
Visit C, A, F,
Visit G, heuristics evaluates to 2
Visit H, heuristics evaluates to 3
Back up {2,3} to F. max(F)=3
Back up to A. β(A)=3. Temporary min(A) is 3.
3 is the ceiling for node A's score.
Visit B according to depth-first order.
Visit I. Evaluates to 5.
Max(B)>=5. α(B)=5.
It does not matter what the value of J is, min(A)=3. β-prune J.
Alpha-beta pruning improves search efficiency of minimax without
sacrificing accuracy.
F
G H I
J
107. Alpha-beta pruning
• Proceed in a depth-first fashion in the n-ply look-ahead search tree.
• Find the score for the top of this tree.
• During the search, creates two values alpha and beta
• α-value associated with MAX can never decrease
– MAX's eventually score is at least as good as the current α-value
• β-value associated with of MIN can never increase
– MIN's eventually score is at least as good as the current β-value
• α-prune: -value <= -value of a MAX ancestor
• β -prune: Any MAX node having -value <= -value of any
MIN ancestor
min(A) = -1
max(S) must >= -1
Lower bound: -value
of S = -1
h(C) = -2
min (B) <= -2
Upper bound: -value =
-2
Final value of B can never
exceed current value of
S. We can prune the
other children of B.
-1
A
B
S
1 0 -1 1 -2
M
AX
C
-value = -2
min(B)≤-2
-value of S = -1
max(S)≥-1
MIN
α-prune
108. Conclusion
• Minimax search is designed for the adversarial search space, MAX
vs MIN.
• Before MAX makes a move, he looks n plies ahead in a DFS
manner.
• Apply heuristic function for the states at the end of the look
ahead level.
• Propagate these values back up to the current state.
– Use alpha-beta pruning to cut bad branches (moves) in the game tree
to improve search time.
• Choose the move that maximizes the current node score.
• Then it is MIN's turn of doing similar look-ahead and pruning to
decide his move.
• The players alternate until game over.
109. Part I : The idea of Alpha Beta
Search
Part II: The details of Alpha Beta
Search
Part III: Results of using Alpha Beta
Alpha Beta Search
110. 110
Reminder
• We consider 2 player perfect
information games
• Two players, Min and Mx
• Leaf nodes given definite score
• backing up by MiniMax defines score
for all nodes
• Usually can’t search whole tree
– Use static evaluation function instead
• MiniMax hopelessly inefficient
111. 111
What’s wrong with MiniMax
• Minimax is horrendously
inefficient
• If we go to depth d,
branching rate b,
– we must explore bd nodes
• but many nodes are wasted
• We needlessly calculate the
exact score at every node
• but at many nodes we don’t
need to know exact score
• e.g. outlined nodes are
irrelevant
Max
score=3
Max
score=2
Min
score=2
Bestmove=Right
Max
score=1
Max
score= ?
Max
score=?
Min
score=?<2
Bestmove=?
Max
score=2
Bestmove=Left
112. 112
The Solution
• Start propagating costs as soon as leaf nodes
are generated
• Don’t explore nodes which cannot affect the
choice of move
– I.e. don’t explore those that we can prove are no
better than the best found so far
• This is the idea behind alpha-beta search
113. 113
Alpha-Beta search
• Alpha-Beta =
• Uses same insight as branch and bound
• When we cannot do better than the best so far
– we can cut off search in this part of the tree
• More complicated because of opposite score
functions
• To implement this we will manipulate alpha and
beta values, and store them on internal nodes in
the search tree
114. 114
Alpha and Beta values
• At a Mx node we will store an alpha value
– the alpha value is lower bound on the exact minimax
score
– the true value might be
– if we know Min can choose moves with score <
• then Min will never choose to let Max go to a node where
the score will be or more
• At a Min node, value is similar but opposite
• Alpha-Beta search uses these values to cut search
115. 115
Alpha Beta in Action
• Why can we cut off search?
• Beta = 1 < alpha = 2 where
the alpha value is at an
ancestor node
• At the ancestor node, Max
had a choice to get a score
of at least 2 (maybe more)
• Max is not going to move
right to let Min guarantee a
score of 1 (maybe less)
Max
score = 3
Max
score = 2
Min
score = 2
Best move = Right
beta = 2
Max
score = 1
Max
score = ?
Max
score = ?
Min
score = ? < 2
Best move = ?
beta = 1
Max
score = 2
Best move = Left
alpha = 2
116. 116
Alpha and Beta values
• Mx node has value
– the alpha value is lower bound on the exact minimax
score
– with best play M x can guarantee scoring at least
• Min node has value
– the beta value is upper bound on the exact minimax
score
– with best play Min can guarantee scoring no more than
• At Max node, if an ancestor Min node has <
– Min’s best play must never let Max move to this node
• therefore this node is irrelevant
– if = , Min can do as well without letting Max get
here
• so again we need not continue
117. 117
Alpha-Beta Pruning Rule
• Two key points:
– alpha values can never decrease
– beta values can never increase
• Search can be discontinued at a node if:
– It is a Max node and
• the alpha value is the beta of any Min ancestor
• this is beta cutoff
– Or it is a Min node and
• the beta value is the alpha of any Max ancestor
• this is alpha cutoff
118. 118
Calculating Alpha-Beta values
• Alpha-Beta calculations are similar to Minimax
– but the pruning rule cuts down search
• Use concept of ‘final backed up value’ of node
– this might be the minimax value
– or it might be an approximation where search cut
off
• less than the true minimax value at a Max node
• more than the true minimax value at a Min node
• in either case, we don’t need to know the true value
119. 119
Final backed up value
• Like MiniMax
• At a Max node:
– the final backed up value is equal to the:
• largest final backed up value of its successors
• this can be all successors (if no beta cutoff)
• or all successors used until beta cutoff occurs
• At a Min node
– the smallest final backed up value is equal to the
• smallest final backed up value of its successors
• min of all successors until alpha cutoff occurs
120. 120
Calculating alpha values
• At a Mx node
– after we obtain the final backed up value of the
first child
• we can set of the node to this value
– when we get the final backed up value of the
second child
• we can increase if the new value is larger
– when we have the final child, or if beta cutoff
occurs
• the stored becomes the final backed up value
• only then can we set the of the parent Min node
• only then can we guarantee that will not increase
• Note the difference
– setting alpha value of current node as we go along
– vs. propagating value up only when it is finalised
121. 121
Calculating beta values
• At a Min node
– after we obtain the final backed up value of the
first child
• we can set of the node to this value
– when we get the final backed up value of the
second child
• we can decrease if the new value is smaller
– when we have the final child, or if alpha cutoff
occurs
• the stored becomes the final backed up value
• only then can we set the of the parent Max node
• only then can we guarantee that will not decrease
• Note the difference
– setting beta value of current node as we go along
– vs. propagating value up only when it is finalised
122. 122
Move ordering Heuristics
• Variable ordering heuristics irrelevant
• value ordering heuristics = move ordering heuristic
• The optimal move ordering heuristic for alpha-beta ..
– … is to consider the best move first
– I.e. test the move which will turn out to have best final
backed up value
– of course this is impossible in practice
• The pessimal move ordering heuristic …
– … is to consider the worst move first
– I.e. test move which will have worst final backed up value
123. 123
Move ordering Heuristics
• In practice we need quick and dirty heuristics
• will neither be optimal nor pessimal
• E.g. order moves by static evaluation function
– if it’s reasonable, most promising likely to give
good score
– should be nearer optimal than random
• If static evaluation function is expensive
– need even quicker heuristics
• In practice move ordering heuristics vital
124. 124
Theoretical Results
• With pessimal move ordering,
– alpha beta makes no reduction in search cost
• With optimal move ordering
– alpha beta cuts the amount of search to the square
root
– I.e. From bd to bd = bd/2
– Equivalently, we can search to twice the depth
• at the same cost
• With heuristics, performance is in between
• alpha beta search vital to successful computer
play in 2 player perfect information games
125. 125
Game Playing
Why do AI researchers study game playing?
1. It’s a good reasoning problem, formal and nontrivial.
2. Direct comparison with humans and other computer
programs is easy.
126. 126
What Kinds of Games?
Mainly games of strategy with the following
characteristics:
1. Sequence of moves to play
2. Rules that specify possible moves
3. Rules that specify a payment for each move
4. Objective is to maximize your payment
127. 127
Games vs. Search Problems
• Unpredictable opponent
specifying a move for every
possible opponent reply
• Time limits unlikely to find
goal, must approximate
128. 128
Opponent’s Move
Generate New Position
Generate Successors
Game
Over?
Evaluate Successors
Move to Highest-Valued Successor
Game
Over?
no
no yes
yes
Two-Player Game
129. 129
Game Tree (2-player, Deterministic,
Turns)
The computer is Max.
The opponent is Min.
At the leaf nodes, the
utility function
is employed. Big value
means good, small is bad.
computer’s
turn
opponent’s
turn
computer’s
turn
opponent’s
turn
leaf nodes
are evaluated
130. 130
Mini-Max Terminology
• utility function: the function applied to leaf nodes
• backed-up value
– of a max-position: the value of its largest successor
– of a min-position: the value of its smallest successor
• minimax procedure: search down several levels;
at the bottom level apply the utility function,
back-up values all the way up to the root node,
and that node selects the move.
131. 131
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:
132. 132
Minimax Strategy
• Why do we take the min value every other
level of the tree?
• These nodes represent the opponent’s choice
of move.
• The computer assumes that the human will
choose that move that is of least value to the
computer.
134. 134
Tic Tac Toe
• Let p be a position in the game
• Define the utility function f(p) by
– f(p) =
• largest positive number if p is a win for computer
• smallest negative number if p is a win for
opponent
• RCDC – RCDO
– where RCDC is number of rows, columns and
diagonals in which computer could still win
– and RCDO is number of rows, columns and
diagonals in which opponent could still win.
135. 135
Sample Evaluations
• X = Computer; O = Opponent
O
X
X O
rows
cols
diags
O O X
X X
X O
rows
cols
diags
137. 137
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
Need to speed it up.
138. 138
Alpha-Beta Procedure
• The alpha-beta procedure can speed up a
depth-first minimax search.
• Alpha: a lower bound on the value that a max
node may ultimately be assigned
• Beta: an upper bound on the value that a
minimizing node may ultimately be assigned
v >
v <
147. 147
Properties of α-β
• Pruning does not affect final result. This means
that it gets the exact same result as does full
minimax.
• Good move ordering improves effectiveness of
pruning
• With "perfect ordering," time complexity =
O(bm/2)
doubles depth of search
• A simple example of the value of reasoning about
which computations are relevant (a form of
metareasoning)
151. 151
Shallow Search Techniques
1. limited search for a few levels
2. reorder the level-1 sucessors
3. proceed with - minimax search
152. 152
Additional Refinements
• Waiting for Quiescence: continue the search
until no drastic change occurs from one level
to the next.
• Secondary Search: after choosing a move,
search a few more levels beneath it to be sure
it still looks good.
• Book Moves: for some parts of the game
(especially initial and end moves), keep a
catalog of best moves to make.
153. 153
Evaluation functions
• For chess/checkers, 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.
154. 154
Example: Samuel’s Checker-Playing
Program
• It uses a linear evaluation function
f(n) = a1x1(n) + a2x2(n) + ... + amxm(n)
For example: f = 6K + 4M + U
– K = King Advantage
– M = Man Advantage
– U = Undenied Mobility Advantage (number of
moves that Max has that Min can’t jump after)
155. 155
Samuel’s Checker Player
• In learning mode
– Computer acts as 2 players: A and B
– A adjusts its coefficients after every
move
– B uses the static utility function
– If A wins, its function is given to B
156. 156
Samuel’s Checker Player
• How does A change its function?
1. Coefficent replacement
(node ) = backed-up value(node) – initial value(node)
if > 0 then terms that contributed positively
are given more weight and terms that
contributed negatively get less weight
if < 0 then terms that contributed negatively
are given more weight and terms that
contributed positively get less weight
157. 157
Samuel’s Checker Player
• How does A change its function?
2. Term Replacement
38 terms altogether
16 used in the utility function at any
one time
Terms that consistently correlate
low with the function value are
removed and added to the end of
the term queue.
They are replaced by terms from the
front of the term queue.
158. 158
Kalah
P’s holes
p’s holes
KP Kp
6 6 6 6 6 6
6 6 6 6 6 6
0 0
To move, pick up all the stones in one of your holes, and
put one stone in each hole, starting at the next one,
including your Kalah and skipping the opponent’s Kalah.
counterclockwise
159. 159
Kalah
• If the last stone lands in your Kalah, you get
another turn.
• If the last stone lands in your empty hole, take all
the stones from your opponent’s hole directly
across from it and put them in your Kalah.
• If all of your holes become empty, the opponent
keeps the rest of the stones.
• The winner is the player who has the most stones
in his Kalah at the end of the game.
160. 160
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
161. 161
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.
162. 162
Games of Chance
• What about games that involve chance, such
as
– rolling dice
– picking a card
• Use three kinds of nodes:
– max nodes
– min nodes
– chance nodes
min
chance
max
163. 163
Games of Chance
c
d1
di dk
S(c,di)
chance node with
max children
expectimax(c) = ∑P(di) max(backed-up-value(s))
i s in S(c,di)
expectimin(c’) = ∑P(di) min(backed-up-value(s))
i s in S(c,di)
164. 164
Example Tree with Chance
3 5 1 4 1 2 4 5
.4 .6 .4 .6
.4 .6
max
chance
min
chance
max
leaf
1.2
165. 165
Complexity
• Instead of O(bm), it is O(bmnm)
where n is the number of chance
outcomes.
• Since the complexity is higher (both
time and space), we cannot search
as deeply.
• Pruning algorithms may be applied.
166. Assignment Questions (Unit -1)
Ques 1: Define Artificial Intelligence
Ques 2: Explain the major components of AI along with Turing
(Imitation) Test
Ques 3: Explain the various characteristics of AI problems
Ques 4: With the help of suitable examples, explain Knowledge
Pyramid in detail.
Ques 5: What is the need of Genetic Algorithm. Explain with the help
of a flow chart.
Ques 6: How do we evaluate fitness function, explain with the help of
suitable example
Ques 7: Numerical on Min-Max Algorithm
Ques 8: Numerical on Alpha-Beta Pruning