Beruflich Dokumente
Kultur Dokumente
ARTIFICIAL INTELLIGENCE
11/1/2011
ARTIFICIAL INTELLIGENCE
LTPMC
3 1 0 100 4
UNIT I Introduction and Problem Solving I 9
UNIT IV Learning 9
UNIT V Applications 9
2
TEXT BOOKS:
1. Stuart Russell, Peter Norvig, Artificial Intelligence A Modern Approach, 3rd Edition, Pearson
Education / Prentice Hall of India 2010(yet to be published).
2. Nils J. Nilsson, Artificial Intelligence: A new Synthesis, Harcourt Asia Pvt. Ltd,2003.
REFERENCES:
1. Elaine Rich and Kevin Knight, Artificial Intelligence, 2nd Edition, Tata McGraw-
Hill, 2003.
2. Patrick Henry Winston, Artificial Intelligence, Pearson Education / PHI, 2004.
3
UNIT-1
SOME DEFINITIONS OF AI
The exciting new effort to make computers think machines with minds, in the full
and literal sense -- Haugeland, 1985
The art of creating machines that perform functions that require intelligence when
performed by people -- Kurzweil, 1990
The study of how to make computers do things at which, at the moment, people
are better -- Rich and Knight, 1991
The study of the computations that make it possible to perceive, reason, and act --
Winston, 1992
A field of study that seeks to explain and emulate intelligent behavior in terms of
computational processes -- Schalkoff, 1990
TURING TEST
It is proposed by Alan Turing 1950 .According to this test, a computer could be considered to be
thinking only when a human interviewer, conversing with both an unseen human being and an
unseen computer, could not determine which is which.
Description:
4
Knowledge representation: to store what it knows or hears
Automated reasoning: to use the stored information to answer questions and to draw new
conclusions
Machine learning: to adapt to new circumstances and to detect and extrapolate patterns.
Acting humanly
How do we do this
when we can prove that the results of the programmed reasoning are
correct
Example:
5
Ram is a student of III year CSE. All students are good in III year CSE.
Acting Rationally
The rational agent approach (this is what well focus on in this course)
Figure out how to make correct decisions, which sometimes means thinking
rationally and other times means having rational reflexes
- Speech Recognition
- Robotics
- Computer Vision
- Data Mining
- Genetic Algorithms
6
Linguistics knowledge representation, grammar
HISTORY OF AI:
1943 McCulloch & Pitts: Boolean circuit model of brain
INTELLIGENT AGENT:
Agent = perceive + act
Thinking
Reasoning
Planning
7
Agent: entity in a program or environment capable of generating action.
An agent uses perception of the environment to make decisions about actions to take.
The actions can depend on the most recent perception or on the entire history (percept
sequence).
An agent is anything that can be viewed as perceiving its environment through sensors and acting
upon the environment through actuators.
Human agent
Agent
E
Sensors N
PERCEPT V
S I
R
? O
N
M
ACTUATORS E
ACTION N
T
8
Agents interact with environment through sensors and actuators.
A B
Fig: practical tabulation of a simple agent function for the vacuum cleaner world
Agent Function
The agent function is a mathematical function that maps a sequence of perceptions into
action.
9
RATIONAL AGENT:
A rational agent is one that can take the right decision in every situation.
Performance measure: a set of criteria/test bed for the success of the agent's behavior.
The performance measures should be based on the desired effect of the agent on the
environment.
Rationality:
The agent's rational behavior depends on:
Definition: for every possible percept sequence, the agent is expected to take an action that
will maximize its performance measure.
Agent Autonomy:
An agent is omniscient if it knows the actual outcome of its actions. Not possible in practice.
Exploration: sometimes an agent must perform an action to gather information (to increase
perception).
10
Autonomy: the capacity to compensate for partial or incorrect prior knowledge (usually by
learning).
NATURE OF ENVIRONMENTS:
Task environment the problem that the agent is a solution to.
Includes
Performance measure
Environment
Actuator
Sensors
Taxi Driver Safe, Fast, Legal, Roads, other Steering, Camera, sonar,
Comfort, traffic, accelerators, GPS,
Maximize Profits pedestrians, brake, signal, Speedometer,
customers horn keyboard, etc
Agent sensors give complete state of the environment at each point in time
Sensors detect all the aspect that is relevant to the choice of action.
Next state of the environment is completely determined by the current state and
the action executed by the agent
11
Strategic environment (if the environment is deterministic except for the actions of
other agent.)
Agents experience can be divided into episodes, each episode with what an agent
perceive and what is the action
Semi dynamic
Partially Observable:
Ex: Automated taxi cannot see what other devices are thinking.
Stochastic:
Ex: taxi driving is clearly stochastic in this sense, because one can never predict the behavior
of the traffic exactly.
Semi dynamic:
If the environment does not change for some time, then it changes due to agents
performance is called semi dynamic environment.
An agent solving a cross word puzzle by itself is clearly in a single agent environment.
12
STRUCTURE OF AGENT:
Simple Agents:
13
Table-driven agents: the function consists in a lookup table of actions to be taken for every
possible state of the environment.
If the environment has n variables, each with t possible states, then the table
size is tn.
Only works for a small number of possible states for the environment.
Simple reflex agents: deciding on the action to take based only on the current perception
and not on the history of perceptions.
3. goal-based agent
4. utility-based agent
SRA works only if the correct decision can be made on the basis of only the current percept
that is only if the environment is fully observable.
Characteristics
no plan, no goal
14
do not know what they want to achieve
Condition-action rule
15
Algorithm Explanation:
Interpret Input:
Function generates an abstracted description of the current state from the percept.
RULE- MATCH:
Function returns the first rule in the set of rules that matches the given state description.
RULE - ACTION:
An agent which combines the current percept with the old internal state to generate
updated description of the current state.
If the world is not fully observable, the agent must remember observations about the parts
of the environment it cannot currently observe.
This usually requires an internal representation of the world (or internal state).
Since this representation is a model of the world, we call this model-based agent.
characteristics
16
Algorithm Explanation:
UPDATE-INPUT: This is responsible for creating the new internal stated description.
Goal-based agents:
The agent has a purpose and the action to be taken depends on the current state and on
what it tries to accomplish (the goal).
In some cases the goal is easy to achieve. In others it involves planning, sifting through a
search space for possible solutions, developing a strategy.
Characteristics
17
Fundamentally different from the condition-action rule.
Utility-based agents
If one state is preferred over the other, then it has higher utility for the agent
The agent is aware of a utility function that estimates how close the current state is to the agent's
goal.
Characteristics
18
Learning Agents
Agents capable of acquiring new competence through observations and actions.
Learning element
Performance element
Critic
Problem generator
19
Agent Example
Purpose: compress and archive files that have not been used in a while.
Persistence an agent's life span is not entirely dependent on a user launching and quitting
it.
20
Formulate Goal, Formulate Problem
Search
Execute
PROBLEMS
Possible Actions
State Space the state space forms a graph in which the nodes are states
and arcs between nodes are actions.
Path
Step cost
Problem formulation is the process of deciding what actions and states to consider, given a
goal
Path:
A path in the state space is a sequence of states connected by a sequence of actions.
The sequence of steps done by intelligent agent to maximize the performance measure:
Goal Formulation: based on the current situation and the agents performance measure, it is
the first step in problem solving.
Problem Formulation: it is the process of deciding what actions and states to consider, given
a goal.
Solution: A search algorithm takes a problem as input and returns a solution in the form of
an action sequence.
Execution: Once a solution is found, the actions it recommends can be carried out called execution
phase.
Solutions
21
A Solution to the problem is the path from the initial state to the final state
Optimal Solution has the lowest path cost among other solutions
An Agent with several immediate options of unknown value can decide what to do by
first examining different possible sequences of actions that lead to a state of known
value, and then choosing the best sequence Searching Process
Static
Observable
Discrete
Deterministic
Example
22
A Simplified Road Map of Part of Romania
Explanation:
Formulate goal:
be in Bucharest
Formulate problem:
Find solution:
TOY PROBLEM
Problem Formulation
States
2 x 22 = 8 states
Initial State
23
Any one of 8 states
Successor Function
Legal states that result from three actions (Left, Right, Suck)
Goal Test
Path Cost
24
State Space for the Vacuum World.
25
NP Complete
Place eight queens on a chess board such that no queen can attack another queen
Incremental formulations
Successor function: Add a queen to an empty square. Add a queen to any square in the leftmost
empty column such that it is not attacked by any other queen. 2057 sequences to investigate
26
Goal Test: 8 queens on the board and none are attacked. 64*63**57 = 1.8*1014 possible
sequences.
Logistics
VLSI layout
Robot navigation
Learning
Robotic assembly:
States: real-valued co ordinates of robot joint angels part of the object to be assembled.
Route-finding
Find the best route between two cities given the type & condition of existing roads & the drivers
preferences
Used in
computer networks
path cost
money
seat quality
time of day
type of airplane
Each city is visited exactly once and finishing the city started from.
27
However, the total tour cost must be minimum, where the total cost is the sum of the individual
cost of each city visited in the tour.
Given a road map of n cities, find the shortest tour which visits every city on the map exactly
once and then return to the original city (Hamiltonian circuit)
(Geometric version):
Its an NP Complete problem no one has found any really efficient way of solving them for large
n. Closely related to the Hamiltonian-cycle problem.
VLSI layout
The decision of placement of silicon chips on breadboards is very complex. (or standard
gates on a chip).
This includes
cell layout
channel routing
Finding the best way to route the wires between the chips becomes a search problem.
28
Generating action sequences
What do we know?
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
BREADTH-FIRST SEARCH
Definition:
29
The root node is expanded first, and then all the nodes generated by the node are expanded.
Implementation:
Properties of Breadth-First Search
30
Complete
Time
1 + b + b2 + + bd + b(bd-1) = O(bd+1)
exponential in d
Space
O(bd+1)
This is the big problem; an agent that generates nodes at 10 MB/sec will produce
860 MB in 24 hours
Optimal
Given:
31
Task: Find the route from S to G using BFS.
Step1:
Step 2:
Step3:
32
Step4:
Answer : The path in the 2nd depth level that is SBG (or ) SCG.
Time complexity
1+b+b+..+
O )
Definition:
Expand one node to the depth of the tree. If dead end occurs, backtracking is done to the next
immediate previous node for the nodes to be expanded
Enqueue nodes on nodes in LIFO (last-in, first-out) order. That is, nodes used as a stack data
structure to order nodes.
It needs to store only a single path from the root to a leaf node, along with remaining
unexpanded sibling nodes for each node on a path
Implementation:
33
34
35
Properties of Depth-First Search
Complete
36
Time
O(bm)
But if the solutions are dense, this may be faster than breadth-first search
Space
O(bm)linear space
Optimal
No
When search hits a dead-end, can only back up one level at a time even if the problem
occurs because of a bad operator choice near the top of the tree. Hence, only does
chronological backtracking
Advantage:
If more than one solution exists or no of levels is high then dfs is best because exploration is
done only a small portion of the white space.
Disadvantage:
No guaranteed to find solution.
Step 1:
37
Step 2:
Step 3:
A B C
Step 4:
A B C
38
Answer: Path in 3rd level is SADG
DEPTH-LIMITED SEARCH
Definition:
A cut off (Maximum level of the depth) is introduced in this search technique to overcome the
disadvantage of Depth First Search. The cut off value depends on the number of states.
DLS can be implemented as a simple modification to the general tree search algorithm or the
recursive DFS algorithm.
Yes if l < d
39
Time
N(IDS)=(d)b+(d-1)b+..+(1)
O(bl)
Space
O(bl)
Optimal
No if l > d
Advantage:
Cut off level is introduced in DFS Technique.
Disadvantage:
No guarantee to find the optimal solution.
B C
D E
The number of states in the given map is five. So it is possible to get the goal state at the maximum
depth of four. Therefore the cut off value is four.
1. 2. 3. 4.
A A A A
B C B C B C
40
D D
Answer: Path = ABDE Depth=3
Definition:
Iterative deepening depth-first search It is a strategy that steps the issue of choosing the
best path depth limit by trying all possible depth limit
Implementation:
41
Properties of Iterative Deepening Search:
Complete
Yes
Time : N(IDS)=(d)b+(d-1)b2++(1)bd
O(bd)
Space
O(bd)
Optimal
Advantages:
This method is preferred for large state space and when the depth of the search is not
known.
42
Disadvantages:
Many states are expanded multiple times.
If branching factor is b and solution is at depth d, then nodes at depth d are generated once,
nodes at depth d-1 are generated twice, etc.
If b=4, then worst case is 1.78 * 4d, i.e., 78% more nodes searched than exist at
depth d (in the worst case).
In general, iterative deepening search is the preferred uninformed search method when
there is a large search space and the depth of the solution is not known
A F
B C
Limit=0 D E G
A
Limit=1
B C F
Limit=2
1.
A
B C F 43
2.
3.
A
B C F
A-B-D-E-G Limit 4 G
A B D-E-G G
A-C-E-G Limit 3
A-F-G- Limit 2
Answer: Since it is a IDS tree the lowest depth limit (i.e.) A-F-G is selected as the solution path.
BI-DIRECTIONAL SEARCH
Definition:
It is a strategy that simultaneously searches both the directions (i.e) forward from the initial state
and backward from the goal state and stops when the two searches meet in the middle.
44
Alternate searching from the start state toward the goal and from the goal state toward the
start.
Works well only when there are unique start and goal states.
3. Complete: Yes
4. Optimal: Yes
Advantages:
Reduce time complexity and space complexity
Disadvantages:
The space requirement is the most significant weakness of bi-directional search.
If two searches do not meet at all, complexity arises in the search technique. In backward search
calculating predecessor is difficult task. If more than one goal state exists then explicitly, multiple
state searches are required.
B C
45
D E
Task: Find a path from A to E
B C
E
E
D C
Completeness
Time
46
Often represented as the number of nodes searched
Space
Optimal
47
UNIT-2
PROBLEM SOLVING-II
INFORMED SEARCH STRATEGIES:
Heuristic / Informed
It uses additional information about nodes (heuristics) that have not yet been explored to decide
which nodes to examine next
Can find solutions more efficiently than search strategies that do not use domain specific
knowledge.
Best-first search: node is selected for expansion based on an evaluation function f(n)
Evaluation function incorporate the problem specific knowledge in the form of h(n)
Implementation:
48
Use of hSLD, Straight Line Distance Heuristic
Definition:
A best first search that uses to select next node to expand is called greedy search.
Ex:
Given,
75 99 F 211
A 140 B
S
118 101
80
T R P
97
f(n)=h(n)
A 366 R 193
B-0 S 253
F 178 T 329
P 98 Z 374
Solution:
From the given graph and estimated cost the goal state is estimated as B from A.
1. A
2. Zh=374
A
S
h=253
T
49
h=329
3. S is selected for next level of expansion since h(n) is minimum from S, when comparing T & Z.
h=374
Z
h=178
F
A
S A
h=253 h=366
T h=329 Rh =193
h=374 h=253
S
3 Z
F
h=178
A
S A B
h=253 h=366 h=0
T h=329 R h=193
From F goal state B is reached. Therefore the path from A to B using greedy search is A-S-F-B = 450
(i.e.) (140+99+211).
50
Greedy search example:
Assume that we want to use greedy search to solve the problem of travelling from Arad to
Bucharest.
Arad
Sibiu(253)
Timisoara(329) Zerind(374)
51
If Sibiu is expanded we get:
Goal reached !!
52
Properties of greedy best-first search:
Complete? No can get stuck in loops, e.g., Iasi Neamt Iasi Neamt
Optimal? No
A* SEARCH
f(n)=g(n) + h(n)
h(n) the estimated cost of the cheapest path from n to the goal
f(n) the estimated cost of the cheapest solution through the node n
Admissible heuristics
An admissible heuristic never overestimates the cost to reach the goal from a given state,
i.e., it is optimistic
53
Example: hSLD(n) (never overestimates the actual road distance)
A* Search
Definition:
A best first search using f as an evaluation function and an admissible h function is known as A*
search.
f(n)=g(n)+h(n)
Ex: Given,
75 99 F 211
A 140 B
S
118 101
80 97
T R
P
Straight line distance to B from A
A 366 R 193
B-0 S 253
F 178 T 329
P 98 Z 374
Solution:
From the given graph and estimated cost the goal state is estimated as B from A.
1. A
f=0+366=366
2. Zf=75+374=449
A
S
f=140+253=393
54
T
f=118+329=447
3. S is selected for next level of expansion since f(S) is minimum from S, when comparing T & Z.
f=449
Z
f=293+178=417
F
A
S A
f=393 f=280+366=646
T
f=447 R
f=220+193=413
Ex:
A-S-A
140+140=280
A-S-F
140+99=239
4. R is selected for next level of expansion since f(R) is minimum when comparing to A and F.
f=449
Z
f=417
F
A
S
f=393 f=646 A
S
f=553
Tf=447 R
f=413
f=415 P
55
5. P is selected for next level of expansion since f(P) is minimum.
Z
f=449 f=417
F
A f=646
A
S f=393
S f=553
Tf=447 R
f=413 f=317+193=510
R
f=415 B
f=418+0=418
From P, goal state B is reached. Therefore the path from A to B using A* search is A-S-R-P-B = 418
(i.e.) (40+80+97+101).
A* search example:
f(Arad) = c(??,Arad)+h(Arad)=0+366=366
f(Sibiu)=c(Arad,Sibiu)+h(Sibiu)=140+253=393
56
f(Timisoara)=c(Arad,Timisoara)+h(Timisoara)=118+329=447
f(Zerind)=c(Arad,Zerind)+h(Zerind)=75+374=449
f(Arad)=c(Sibiu,Arad)+h(Arad)=280+366=646
f(Fagaras)=c(Sibiu,Fagaras)+h(Fagaras)=239+179=415
f(Oradea)=c(Sibiu,Oradea)+h(Oradea)=291+380=671
h(Rimnicu Vilcea)=220+192=413
f(Sibiu)=c(Rimnicu Vilcea,Sibiu)+h(Sibiu)=300+253=553
57
Expand Fagaras and determine f(n) for each node
f(Sibiu)=c(Fagaras, Sibiu)+h(Sibiu)=338+253=591
f(Bucharest)=c(Fagaras,Bucharest)+h(Bucharest)=450+0=450
f(Bucharest)=c(Pitesti,Bucharest)+h(Bucharest)=418+0=418
Optimality of A* (proof)
Suppose some suboptimal goal G2 has been generated and is in the fringe. Let n be an
unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.
58
Suppose suboptimal goal G2 in the queue.
Solution:
Ensure that optimal path to any repeated state is always first followed.
Consistency:
59
A heuristic is consistent if
If h is consistent, we have
Added:
60
2) Some nodes on the goal
Contour (f(n)=C*).
fi < fi+1.
A* Characteristics:
61
Expands nodes in the increasing order of costs
A* is optimally efficient
For a given heuristic, A* finds optimal solution with the fewest number of nodes
expansion
Any algorithm that doesnt expand nodes with f(n)<C* has the risk of missing an
optimal solution
For most problems the number of nodes with costs lesser than C* is exponential
Properties of A* Search:
Completeness: YES
Optimality: YES
IDA*
MA*
The memory requirement of A* is reduced by combining the heuristic fn with iterative depending
resulting on IDA* algorithm.
IDA* search:
Space capacity: bd
Time complexity: difficult to characterize depends on the number of different values that the
heurestic function can take on
Optimality:yes
Completeness:Yes
62
Disadvantages: It will require more storage space in complex domain (i.e)Each contour will include
only one state with the previous contour.To avoid this, We increase the f-cost limit by a fixed
amount E on each iteration.So that the total no.of.iteration is proportional to 1/E.Such an algorihm
is called E admissible.
Inputs:problem,a problem
f-limitf-cost(root)
loop do
solutions,f-limitDFS-CONTOUR (root,f-limit)
End
1.Complete:Yes
2.Time&space complexity:
3.Optimal:If enough memory is available to store the deepest solution path, otherwise it returns the
best solution that can be reached with available memory
Iterative-deepening A* (IDA*)
Keep increase the cutoff for each iteration by the smallest amount, in excess of the
current cutoff
63
Recursive best-first search
1.After expanding A,S and R the current best leaf(p) has a value that is worse then the best
alernative path(f).
infinity
A
447
393 449
S
Z
T 447
A R
646 F 415 413
P
S
417 553
2.f-limit value of each recursive call is shown on the top of each current node.
3.After expanding R,the condition f[best]>f-limit(417>415) is true and returns f[best] to that node.
infinity
447
S 64
393 449
Z
T 447
A R
646 F 415 417
S
591 450
B
Hints:
F[best]>f[limit]
True
F[best]
Here the f[best] is 450 and which is greater than the f-limit of 417.Therefore it returns and unwind
with f[best] value to that node.
infinity
447
393 449
S
Z
T 447
65
A R
646 F 450 417
P
S
B R
418 607
The best alternative path through T costs atleast 447,therefore the path through R and P is
considered as the best one.
If current f-values exceeds this alternative f-value than backtrack to alternative path.
Example:
66
RBFS evaluation
IDA* retains only one single number (the current f-cost limit)
2.SMA*(simplified MA*)
67
(simplified) memory-bounded A*:
SMA* solves this by expanding newest best leaf and deleting oldest worst leaf.
1.Complete:Yes
2.Time&space complexity:
3.Optimal:If enough memory is available to store the deepest solution path, otherwise it returns the
best solution that can be reached with available memory
0+12=12
A
B
G
8+5=13
68
C
D D
RBFS (mimics depth-first search, but backtracks if the current path is not promising and a
better path exist.
Learning to Search:
The idea is to search at the meta-level space.ach state here is a search tree. The goal is to learn from
different search strategies to avoid exploring useless parts of the tree.
69
Answer: Yes.
Each state in metalevel state space capture the internal state of a program that is searching
in an object level state space
HEURISTIC FUNCTIONS:
Heuristic function
A key compound of Best First Search algorithm is heuristic function denoted h(n)
h(n)= Estimated cost of the cheapest path from node n to a goal node
Heuristic functions are the most common form in which additional knowledge of the problem
imparted to the search algorithm.
70
A good heuristic function can reduce the search process.
h(n) = estimated cost of the cheapest path from node n to goal node.
Ex: Depth=5
N=52
N= 1+2+(2)^2+(2)^3+(2)^4+(2)^5
= 1+2+4+8+16+32= 63
From the above example, the number of nodes in effective branching factor is reduced, when
comparing to branching factor.
That is,
Difference =63-52 = 11
71
Common candidates:
h1(s)=8
h2 = the sum of the distances of the tiles from their goal positions (manhattan distance). (or) city
block distance
h2(s)=3+1+2+2+2+3+3+2=18
Is the branching factor that a uniform tree of depth d would have in order to contain
N+1 nodes.
A good value of b* is 1.
A: Yes.
If h2(n) >= h1(n) for all n (both admissible) then h2 dominates h1 and is better for search
72
Admissible heuristics can be derived from the exact solution cost of a relaxed version of the
problem:
Relaxed problem:
Relaxed problem: A problem with fewer restrictions on the action is called Relaxed Problem.
The optimal solution cost of a relaxed problem is no greater than the optimal solution cost of the
real problem.
Admissible heuristics can also be derived from the solution cost of a subproblem of a given
problem.
Pattern databases store the exact solution to for every possible subproblem instance.
Disjoint pattern databases: The problem can be divided up in such a way that each move affects
only one subproblem.
73
An inductive learning algorithm can be used to predict costs for other states that
arise during search.
Definition: Local search algorithm operates using a single current state and generally moves only to
neighbours of that state.
A landscape has
Applications:
74
Many optimization problems do not fit the standard search model outlined in
chapter 3
Local search= use single current state and move to neighboring states.
Advantages:
Hill-climbing search
Hill climbing does not look ahead of the immediate neighbors of the current state.
Hill-climbing chooses randomly among the set of best successors, if there is more than one.
Algorithm:
75
input: problem, a problem
neighbor, a node.
current MAKE-NODE(INITIAL-STATE[problem])
loop do
current neighbor
Example:
Successor function: move a single queen to another square in the same column.
Heuristic function h(n): the number of pairs of queens that are attacking each other (directly
or indirectly).
A) b)
76
a) shows a state of h=17 and the h-value for each possible successor.
Drawbacks
Plateaux = an area of the state space where the evaluation function is flat.
Hill-climbing variations:
Stochastic hill-climbing
77
The selection probability can vary with the steepness of the uphill move.
First-choice hill-climbing
cfr. stochastic hill climbing by generating successors randomly until a better one is
found.
An algorithm which combines with random walk to yield both the efficiency and completeness.
Ex:
Algorithm:
next, a node.
current MAKE-NODE(INITIAL-STATE[problem])
78
for t 1 to do
T schedule[t]
E VALUE[next] - VALUE[current]
Algorithm Expanation:
Instance X Y
1 1.0 1.5
2 1.0 4.5
3 2.0 1.5
4 2.0 3.5
5 3.0 2.5
6 5.0 6.0
1 (2.67,4.67) 2, 4, 6
14.50
(2.00,1.83) 1, 3, 5
2 (1.5,1.5) 1, 3 79
15.94
(2.75,4.125) 2, 4, 5, 6
3 (1.8,2.7) 1, 2, 3, 4, 5
7
6
5
4
3
f(x)
2
1General Considerations
0 Requires real-valued data. x
0 We must select
1 the number of2clusters present 3
in the data. 4 5 6
Works best when the clusters in the data are of approximately equal size.
80
Initially: k random states
Genetic algorithms
Operations
Basic structure
Create population
81
Children carry parts of their parents data
Fitness Function:
82
Representation
Binary representation of numbers isnt good - what happens when you crossover in
the middle of a number?
Need reasonable breakpoints for crossover (e.g. between R, xcenter and ycenter
but not within them)
Cover
General Considerations
83
The General Form:
84
An Example of Crossover
85
ONLINE SEARCH AGENT:
E.g. takes an action and then observes environments and then computes the
next action
c(s,a,s)- this step-cost cannot be used until the agent knows that s is the outcome
GOAL-TEST(s)
The agent cannot access the successors of a state except by actually trying all the actions in
that state
Assumptions
Safely Explorable space goal can be reached from any reachable state (no dead ends)
Competitive Ratio: total path cost actually traverse vs. cost agent would traverse if it knew
state space in advance.
86
best achievable CR is often unbounded
(very high, possibly infinite)
adversary argument
Better to evaluate performance relative to size of state space, rather than depth of
shallowest goal
Robot Maze
A simple maze problem , the agent start at S and must reach G ,but knows nothing of the
environment.
Adversary Arguments:
Imagine an adversary that constructs state space as agent is moving through it and can
adjust unexplored space to create worst case behavior.
The space that would be created by this adversary is a space that would yield worst-case
behavior.
Competitive Ratio:
This defines the comparison between the total pathcost with shortest complete
exploration pathcost. This ratio should be as small as possible.
Adversaries
87
Fig(a):
Two state space that might lead on online search agent into a dead end.Any given agent will
fail in atleast one of these spaces.
Fig(b):
A two dimensional environment that can cause an online search agent to follow on
arbitrarily inefficient route to the goal.
Fig:
An environment in which a random will take exponentially many steps to find the goal.
88
online search agents:
Online DFS
static: result, a table of the next state, indexed by action and state, initially empty
unexplored, a stack that lists, for each visited state, the action not yet tried
unbacktracked, a stack that lists, for each visited state, the predecessor states
to which the agent has not yet backtracked
89
if s is a new state then unexplored[s] ACTIONS(s)
result[a,s] s
else a POP(unexplored[s])
s s
return a
Task:
From S to reach G.
90
GOAL-TEST((1,1))?
s != G thus false
false
s is null?
false (s=(1,2))
result*DOWN,(1,2)+ (1,1)
UB[(1,1)] = {(1,2)}
UX[(1,1)] empty?
False
a=RIGHT, s=(1,1)
return a
91
GOAL-TEST((2,1))?
s != G thus false
True, UX[(2,1)]={RIGHT,UP,LEFT}
s is null?
false (s=(1,1))
result*RIGHT,(1,1)+ (2,1)
UB[(2,1)]={(1,1)}
UX[(2,1)] empty?
False
a=LEFT, s=(2,1)
return a
92
Online local search
An environment in which a random walk will take exponentially many steps to find the goal
Random Walks
Instead of random restart, we can consider random walks for online search
93
C(S,a,S)+H(S)
1+9 1+2
10 3(min)
So move right.
static: result, a table of next state, indexed by action and state, initially empty
94
H, a table of cost estimates indexed by state, initially empty
unless s is null
result[a,s] s
b ACTIONS(s)
s s
return a
state is a "black box any data structure that supports successor function, heuristic
function, and goal test
CSP:
Allows useful general-purpose algorithms with more power than standard search algorithms
Arc consistency:
95
Path consistency:
3 consistency means that any pair of adjacent variables can always be extended to a third
neighboring variable, this is also called path consistency
K-consistency:
Stronger forms of propagation can be defined using the notation called K-consistency.
A CSP is K-consistency if for any set of K-1 variables and for any consistent assignment to
those variables, a constant value can always be assigned to any variable.
Example: Map-Coloring
Domains Di = {red,green,blue}
96
Solutions are complete and consistent assignments, e.g., WA = red, NT = green,Q = red,NSW
= green,V = red,SA = blue,T = green
Constraint graph
97
Varieties of CSPs
Discrete variables
finite domains:
infinite domains:
e.g., job scheduling, variables are start/end days for each job
Continuous variables
Varieties of constraints:
e.g., SA green
e.g., SA WA
Example: Cryptarithmetic
98
Variables: F T U W
R O X 1 X2 X3
Domains: {0,1,2,3,4,5,6,7,8,9}
O + O = R + 10 X1
X1 + W + W = U + 10 X2
X2 + T + T = O + 10 X3
X3 = F, T 0, F 0
Where X1, X2 , X3 are auxilliary variables representing the digit (0&1) carried over into
the next column. Higher order constraint can be represented as constraint
hypergraph.
CSP:
CSP are mathematical problem where one must find states or object that satisfy a
number of constraint or criteria. A constraint is a restriction of the feasible solutions in
an optimization problem
Example
N-queen problem
Cross word puzzle
Map coloring problem
Real-world CSPs
Assignment problems
Timetabling problems
Transportation scheduling
Factory scheduling
99
States are defined by the values assigned so far
Successor function: assign a value to an unassigned variable that does not conflict with
current assignment
The result in (4) is grossly pessimistic, because the order in which values are assigned to variables
does not matter. There are only dn assignments.
Backtracking search:
It is used for depth first search that chooses the values for one variable at a time and backtracks
when a variable has no legal values left to assign.
100
b = d and there are dn leaves
Depth-first search for CSPs with single-variable assignments is called backtracking search
Algorithm explanation:
Chronological backtracking:
Backup the preceding variables and try a different value for it called chronological
backtracking.
101
Variable: WA, NT, SA, Q, NSW, V, T
We see that every values violates a constraint. So back up to T and change it color but this is solve
the problem have to introduce the new approach here
When a branch of the search fails back track to one of the set of variables that caused the
failure conflict set. the conflict set for the variable X is set of previously assigned variables that are
102
connected to X by constraints. A backtracking alg that was conflict sets defined in this way is called
conflict directed backtracking.
Constraint Learning:
It actually modifies the CSP by adding a new constraint that is induced from these conflicts.
Back jumping: this method back tracks to the most recent variable in the conflict set
Ex: Back jumping would jump over Tasmania and try a new value for V
Backtracking example
103
104
Improving backtracking efficiency
105
Tie-breaker among most constrained variables
Degree heuristic:
The MRV doesnt help at all in choosing the first region to color in Australia. Because initially
every region has three colors.
In this case, the degree heuristic used.
Used to reduce branching factor on future choices by selecting the variable that is involved
in the largest number of constraint on other unassigned variables.
Useful in tie-breaker
the one that rules out the fewest values in the remaining variables
Forward checking
106
Idea:
107
RGB RGB RGB RGB RGB RGB RGB
R GB RGB RGB TGB GB RGB
R B G R B RGB B RGB
R B G B B RGB
The progress of a map coloring search with forward checking. WA=red is assigned first; then forward
checking deletes red from the domains of the neighboring variables NT and SA. After Q=green, green
is deleted from the domain of NT, SA and NSW. After V=blue, blue is deleted from the domains is
NSW and SA, leaving SA with no legal values.
Constraint propagation
108
Constraint propagation:
consistency techniques:
Alldiff constraint
Resource constraint
Bounds propagation
Chronological backtracking
Conflict set
Back jumping
Conflict-directed back jumping
Constraint learning
m-variable
n-values
In which consistency is achieved by deleting the maximum value of any domain if it is not consistent
with minimum values of other domains.
109
Constraint no more 10 personal are assigned in total
So atmost(10,PA1,PA2,PA3,PA4)
Domain(3,4,5,6)
Bound propagation:
Domains are represented by lower bound and upper bound and are managed by bound
propagation
Used practical constraint problem
EX:
Two flights=271,272
Initial domain
Flight271[0,165]
Flight272[0,385]
Additional constraint:
Finally we say that a CSP is bound constraint if for every variable X, and both the lower bound and
upper bound values of X, there exists some value of Y, that satisfies the constraint between X and Y
for every variable Y.
Arc consistency
110
X Y is consistent iff
X Y is consistent iff
111
If X loses a value, neighbors of X need to be rechecked
112
Time complexity: O(n2d3), where n is the number of variables and d is the maximum variable
domain size, because:
Each arc can be inserted into the agenda (TDA set) at most d times
3. Some domains have more than one value => there may or may not be a solution
If the problem has a unique solution, GAC may end in state (2) or (3); otherwise, we would
have a polynomial-time algorithm to solve UNIQUE-SAT
Hill-climbing, simulated annealing typically work with "complete" states, i.e., all variables assigned
To apply to CSPs:
113
Algorithm:
for i = 1 to max_steps do
return failure
Example: 4-Queens
Given random initial state, can solve n-queens in almost constant time for arbitrary n with
high probability (e.g., n = 10,000,000)
Min-conflicts example 2
114
Use of min-conflicts heuristic in hill-climbing
Min-conflicts example 3
The algorithm moves the queen to the min-conflict square breaking ties randomly
Summary
115
states defined by values of a fixed set of variables
STRUCTURE OF PROBLEMS:
116
How can the problem structure help to find a solution quickly?
Improves performance
Tree-structured CSPs
Tree:
117
Theorem: if the constraint graph has no loops then CSP can be solved in O(nd 2) time
DEFINITION:
Any tree-structured CSP can be solved in time linear in the number of variables.
ALGORITHM:
Choose a variable as root, order variables from root to leaves such that every nodes
parent precedes it in the ordering. (label var from X1 to Xn)
Steps:
118
General constraint graph can be reduced to trees on two ways .They are
Finding the smallest cycle cut set is NP-hard but several efficient approximation algorithm
are known for this task. The overall algorithmic approach is called cut set conditioning.
Removing nodes:
This is the first approach involves assigning values to some variables so that the remaining
variables from a tree.
Tree width:
Tree decomposition techniques transform the csp into a tree of subproblem and are
efficient if the tree width of the constraint graph is small.
Conditioning:
Cutset conditioning:
Instantiate (in all ways) a set of variables such that the remaining constraint graph is
a tree
119
Tree decomposition:
CSP with constraint graphs of bounded tree width (w) are solvable in
polynomial time: O(ndw+1)
120
Summary
GAMES:
multiagent environment.
Game.
121
Game theory
1. call.
2. History of Games.
pruning.
Evaluation functions.
Pruning:
It allows us to ignore the portions of the search tree that make no difference to the final
choice.
It allows us to approximate the true utility of a state without doing a complete search.
Games component.
Optimal strategy
1. Strategy.
2. Minimax value.
3. Minimax decision.
The minimax algorithm.
1. Minimax algorithm
2. Backed up.
Multiagent, conflict
122
Easy to represent,agents restricted to small number of actions
Search no adversary
Games adversary
Historical Contributions
Babbage, 1846
Turing, 1951
Samuel, 1952-57
McCarthy, 1956
123
Types of Games
Alternate moves
Game has
Resulting state
124
Initial state plus legal moves define game tree. Tic-tac-toe: Game tree (2-
Optimal Strategy:
Find the contingent strategy for MAX assuming an infallible MIN opponent.
Given a game tree, the optimal strategy can be determined by using the minimax value of
each node:
MINIMAX-VALUE(n)=
UTILITY(n) If n is a terminal
125
Minimax maximizes the worst-case outcome for max
126
Definition of optimal play for MAX assumes MIN plays optimally:
maximizes worst-case outcome for MAX.
But if MIN does not play optimally, MAX will do even better. [proven.]
Minimax Algorithm
127
Minimax maximizes the worst-case outcome for max
Minimax-Decision:
select all the possible moves, finds the utility values returns.
Minimax-value:
The moves with high utility value returns the utility value depends on the state.
Terminal state.
Max player move in the state.
Min player move in the state.
128
Properties of minimax
Even tic-tac-toe is much too complex to diagram here, although it's small enough to
implement.
129
ALPHA-BETA PRUNING:
Alpha-Beta Pruning:
Pruning.
Alpha-Beta pruning.
Example.
Two parameters.
Effectiveness of alpha beta.
Alpha-Beta algorithm.
Transposition.
Transposition table.
Example:
130
The terminals nodes on the bottom level are already labeled with their utility value.
The first Min node labeled B has three successor with values 3,12,8,so its minimax value
3.
The root node is MAX node, its successor have minimax value 3,2,3.so its minimax value
is 3.
The outcome of is that we can identify the minimax decision without ever evaluating
two of the leaf nodes.
Another way:
Simplification the formula for MINIMAX-VALUE. let the two unevaluated successors of
node C. have values x and y and let z be the minimum of x and y. the value of root node is given
by
MINIMAX_VALUE(root)=max(min(3,12,8),min(2,x,y),min(14,5,2))
=max(3,min(2,x,y),2)
131
=max(3,2,3) where z<=2
=3
In other words the value of the root and hence the minimax decision are
independent of the values of pruned leaves x and y.
It can be applied to tree of any depth and possible to prune entire sub tree rather than
just leaves.
It updates the value of alpha and beta as it goes along and prunes the remaining nodes.
The effecitiveness of alpha and beta pruning is highly dependent on the order in which
the successors are examined.
Transposition:
Why is it called -?
is the value of the best (i.e., highestvalue)choice found sofar at any choice point along the path for
max
132
Alpha-beta pruning
The - algorithm:
Example:
133
134
135
136
137
Properties of -
doubles depth of search which can be carried out for a given level of resources.
Evaluation function
Cut off test
Evaluation functions
1. Features.
2. Expected value.
3. Material value.
4. Weighted linear function.
Cutting off search
1. Quiescence.
138
2. Quiescence search.
3. Horizon effect.
4. Singular extensions.
5. Forward pruning.
Features:
It can be determined for each category, resulting in an evaluation function that works for
any state.
The evaluation function need not return actual expected values, as long as the ordering of
the state is the same.
72% to win(+1)
20% to loss(-1)
8% to draw(0)
(0.72*+1)+(0.20*-1)+(0.08*0)=0.52
Cutting of search:
To perform a cut off test, an evaluation function should be applied to positions that are
quiexent ,that is a position that will not swing in bad value for long time in the search tree is known
as waiting for quiescence.
Quiescence search:
A search which is restricted to consider only certain type of moves such as capture moves,
that will quickly resolves the uncertainties in the position.
Standard approach:
139
cutoff test:
evaluation function
Evaluation function
Contrast with heuristic search where the evaluation function was a non-negative
estimate of the cost from the start node to a goal and passing through the given
node
The zero-sum assumption allows us to use a single evaluation function to describe the
goodness of a board with respect to both players.
140
Min-Max
A typical evaluation function is a linear function in which some set of coefficients is used to weight a
number of "features" of the board position.
e.g., w1 = 9 with f1(s) = (number of white queens) (number of black queens), etc.
141
"material", : some measure of which pieces one has on the board.
A typical weighting for each type of chess piece is shown Other types of features try to encode
something about the distribution of the pieces on the board.
Change:
into
Is selected so that the amount of time will not exceed what the rules of the game
allow.
142
12-ply Deep Blue, Kasparov
The key idea is that the more look ahead we can do, that is, the deeper in the tree we can look, the
better our evaluation of a position will be, even with a simple evaluation function. In some sense, if
we could look all the way to the end of the game, all we would need is an evaluation function that
was 1 when we won and -1 when the opponent won.
And Deep Blue is brute indeed... It had 256 specialized chess processors coupled into a 32 node
supercomputer. It examined around 30 billion moves per minute. The typical search depth was
13ply, but in some dynamic situations it could go as deep as 30.
Horizon problem:
When the program is facing a move by the opponent that causes serious damage and
ulitimately unavoidable.
Ex: A
143
M max A
-4 B0 2C D
0 -4
E F
This diagram shows the situation of horizon problem that is when one level is generated from B,it
causes bad value for B. max
A
6 0 2
B C D
6
2E F
5 6 7 6
G H I J
When one more successor level is generated from E and F and situation comes down and the value
of B is retained as a good move.
The time B is waited for this situation is called waiting for quiescence.
Singular Extensions:
Used to avoid the horizon effect without adding to much search cost.
Forward pruning:
Some moves at a given node are pruned immediately without further consideration.
The minimax algorithm generates the entire game search space,whereas the alpha-beta
algorithm allows us to prune large parts of it. However,alpha-beta still has to search all the way to
terminal states for atleast a portion of search space. Shannons 1950 paper,Programming a
computer for playing chess,proposed that programs should cut off the search earlier and apply a
144
heuristic evaluation function to states in the search,effectively turning nonterminal nodes into
terminal leaves. The basic idea is to alter minimax or alpha-beta in two ways :
(1) The utility function is replaced by a heuristic evaluation function EVAL,which gives an estimate of
the positions utility,and
(2) the terminal test is replaced by a cutoff test that decides when to apply EVAL.
Realtime decisions
What if you dont have enough time to explore entire search tree?
We cannot search all the way down to terminal state for all decision sequences
Evaluation Function
Benefits of truncation
Comparing Chess
145
Using alpha-beta 10 ply
Practical issues:
White has just rolled 5 and 6 and has four legal moves:
5-10, 5-11
5-11, 19-24
146
5-10, 10-16
5-11, 11-16
Such games are good for exploring decision making in adversarial problems involving skill
and luck.
Branches leading from each chance node denote the possible dice rolls
147
[1,1], [6,6] chance 1/36, all other chance 1/18
For a random event with N outcomes, each chance node has N distinct children; a
probability is associated with each
148
Meaning of the evaluation function
Dealing with probabilities and expected values means we have to be careful about the
meaning of values returned by the static evaluator.
Note that a relative-order preserving change of the values would not change the decision
of minimax, but could change the decision with chance nodes.
149
Expected minimax value
EXPECTED-MINIMAX-VALUE(n) =
UTILITY(n) If n is a terminal
These equations can be backed-up recursively all the way to the root of the game tree.
Left, A1 is best
Right, A2 is best
150
Outcome of evaluation function (hence the agent behavior) may change when values are
scaled differently.
151
152
153
154
Summary
Games : AI
as
grand prix racing : automobile design
Glossary of Terms
A constraint satisfaction problem is a problem in which the goal is to choose a value for
each of a set of variables, in such a way that the values all obey a set of constraints.
A constraint is a restriction on the possible values of two or more variables. For example, a
constraint might say that A=a is not allowed in conjunction with B=b.
Backtracking search is a form of DFS in which there is a single representation of the state
that gets updated for each successor, and then must be restored when a dead end is
reached.
A directed arc from variable A to variable B in a CSP is arc consistent if, for every value in the
current domain of A, there is some consistent value of B.
Backjumping is a way of making backtracking search more efficient by jumping back more
than one level when a dead end is reached.
Min-conflicts is a heuristic for use with local search on CSP problems. The heuristic says that,
when given a variable to modify, choose the value that conflicts with the fewest number of
other variables.
155
UNIT-3
KNOWLEDGE REPRESENTATION
First-order logic
Functions, which are a subset of relations where there is only one value for any
given input
Examples:
156
Functions: father-of, best-friend, second-half, one-more-than ...
Logics
Ontology
a specification of a conceptualization
Higher-order logic
First-order logic is first because you relate objects (the first-order entities that actually exist in the
world)
the number of objects belonging to a group must be a property of the group, and
not the objects themselves
Epistemological commitments
157
Formal structure of first-order logic
Represented as tuples
158
Logic What Exists Knowledge States
in World
Propositional Facts true/false/unknown
First-Order facts, objects, true/false/unknown
relations
Temporal facts, objects, true/false/unknown
relations,
times
Probability Facts degree of belief 0..1
Theory
Fuzzy Facts degree of truth 0..1
Syntax
Semantics
159
MODELS FOR FOL:
Example:
160