AI PDF
AI PDF
AI PDF
Chapter-1
Outline
What is AI?
Foundation
A brief history
The state of the art
AI – Why so Important?
• Alan Turing (1950) : Wrote this paper “Computing machinery and intelligence"
• “Can machines think?“ , “Can machines behave intelligently?"
• Operational test for intelligent behavior: the Imitation Game
3. Automated Reasoning: To use the stored information to answer questions and to draw new
conclusions;
4. Machine Learning: To adapt to new circumstances and to detect and extrapolate patterns;
• Once we have a sufficiently precise theory of the mind, it becomes possible to express the theory as a computer
program.
• If the program’s input–output behavior matches corresponding human behavior, that is evidence that some of
the program’s mechanisms could also be operating in humans.
• Example: Allen Newell and Herbert Simon, who developed GPS, the “General Problem Solver” (Newell and Simon,
1961), were not content merely to have their program solve problems correctly. They were more concerned with
comparing the trace of its reasoning steps to traces of human subjects solving the same problems.
• The interdisciplinary field of cognitive science brings together computer models from AI and experimental
techniques from psychology to construct precise and testable theories of the human mind.
Cognitive Revolution
• The cognitive revolution is the name for an
intellectual movement in the 1950s that began what
are known collectively as the cognitive sciences. It
began in the modern context of greater
interdisciplinary communication and research. The
relevant areas of interchange were the combination of
psychology, anthropology, and linguistics .
• Deep Blue defeated the reigning world chess champion Garry Kasparov in 1997
• Proved a mathematical conjecture (Robbins conjecture) unsolved for decades
• No hands across America (driving autonomously 98% of the time from Pittsburgh to
San Diego)
• During the 1991 Gulf War, US forces deployed an AI logistics planning and
scheduling program that involved up to 50,000 vehicles, cargo, and people
• NASA's on-board autonomous planning program controlled the scheduling of
operations for a spacecraft
• Proverb solves crossword puzzles better than most humans
State of the art
• AI recently took the spotlight when IBM's Watson
supercomputer routed human competitors on the game
show Jeopardy.
• 2 Finance
• Banks use artificial intelligence systems to organize operations, invest
in stocks, and manage properties. In August 2001, robots beat humans
in a simulated financial trading competition.[4]
• Financial institutions have long used artificial neural network systems
to detect charges or claims outside of the norm, flagging these for
human investigation.
• Creative Virtual has deployed artificial intelligence customer support
systems, or automated online assistants, at E*TRADE, HSBC, Intuit
and Lloyds Banking Group, to assist financial services customers with
services such as checking an account balance, signing up for a new
credit card or retrieving a forgotten password.
Applications of AI
• 3 Hospitals and medicine
• A medical clinic can use artificial intelligence systems to
organize bed schedules, make a staff rotation, and provide
medical information.
• 4 Heavy industry
• Robots have become common in many industries. They are often given
jobs that are considered dangerous to humans. Robots have proven
effective in jobs that are very repetitive which may lead to mistakes or
accidents due to a lapse in concentration and other jobs which humans
may find degrading. Japan is the leader in using and producing robots
in the world. In 1999, 1,700,000 robots were in use worldwide.
Applications of AI
• 5 Online and telephone customer service
• Artificial intelligence is implemented in automated online assistants
that can be seen as avatars on web pages . It can avail for enterprises to
reduce their operating and training cost . A major underlying
technology to such systems is natural language processing.
• 7 Telecommunications
• Many telecommunications companies make use of heuristic search in
the management of their workforces, for example BT Group has
deployed heuristic search in a scheduling application that provides the
work schedules of 20,000 engineers.
Applications
• 8 Toys and games of AI
• The 1990s saw some of the first attempts to mass-produce domestically aimed types of
basic Artificial Intelligence for education, or leisure. This prospered greatly with the
Digital Revolution, and helped introduce people, especially children, to a life of dealing
with various types of Artificial Intelligence, specifically in the form of Tamagotchis and
Giga Pets, the Internet (example: basic search engine interfaces are one simple form), and
the first widely released robot, Furby. A mere year later an improved type of domestic
robot was released in the form of Aibo, a robotic dog with intelligent features and
autonomy. AI has also been applied to video games.
• 9 Music
• The evolution of music has always been affected by technology. With
AI, scientists are trying to make the computer emulate the activities of
the skillful musician. Composition, performance, music theory, sound
processing are some of the major areas on which research in Music and
Artificial Intelligence are focusing.
Applications of AI
• 10 Aviation
• The Air Operations Division AOD, uses AI for the rule based expert
systems. The AOD has use for artificial intelligence for surrogate
operators for combat and training simulators, mission management
aids, support systems for tactical decision making, and post processing
of the simulator data into symbolic summaries.
• The use of artificial intelligence in simulators is proving to be very
useful for the AOD. Airplane simulators are using artificial intelligence
in order to process the data taken from simulated flights. Other than
simulated flying, there is also simulated aircraft warfare. The
computers are able to come up with the best success scenarios in these
situations. The computers can also create strategies based on the
placement, size, speed, and strength of the forces and counter forces.
Pilots may be given assistance in the air during combat by computers.
Applications of AI
• 10 Aviation
• The system used by the AOD in order to measure performance was the
Interactive Fault Diagnosis and Isolation System, or IFDIS. It is a rule
based expert system put together by collecting information from TF-30
documents and the expert advice from mechanics that work on the
TF-30. This system was designed to be used to for the development of
the TF-30 for the RAAF F-111C. The performance system was also
used to replace specialized workers. The system allowed the regular
workers to communicate with the system and avoid mistakes,
miscalculations, or having to speak to one of the specialized workers.
• Rational Agent: For each possible percept sequence, a rational agent should
select an action that is expected to maximize its performance measure, given
the evidence provided by the percept sequence and whatever built-in
knowledge the agent has.
Requirements for a Rational agent
• Playing soccer.
• Exploring the subsurface oceans of Titan.
• Shopping for used AI books on the Internet.
• Playing a tennis match.
• Practicing tennis against a wall.
• Performing a high jump.
• Knitting a sweater.
• Bidding on an item at an auction.
Environment types
For example, to evaluate a taxi driver in simulated traffic, we would want to run
many simulations with different traffic, lighting, and weather conditions. If we
designed the agent for a single scenario, we might be able to take advantage of
specific properties of the particular case but might not identify a good design for
driving in general.
ENVIRONMENT GENERATOR
For example, the vacuum environment generator initializes the dirt pattern and agent
location randomly. We are then interested in the agent’s average performance over
the environment class. A rational agent for a given environment class maximizes this
average performance.
Agent functions and programs
•
Table Driven Agent: A Failure
•
Agent types
RULES:
(1) If small moving object,
then activate SNAP
(2) If large moving object,
then activate AVOID and inhibit SNAP
ELSE (not moving) then NOOP
needed for
completeness Action: SNAP or AVOID or
NOOP
Model-based reflex agents
start
• Knowing about the current state of the environment is not always enough to
decide what to do; additionally sort of goal information which describes
situations that are desirable is also required. This allows the agent a way to
choose among multiple possibilities , selecting the one which reaches a goal
state.
Goal-based agents
• Conclusion
● Goal-based agents are less efficient
● but more flexible
● Agent Different goals different tasks
● Search and planning
● two other sub-fields in AI
● to find out the action sequences to achieve its goal
A model based - Goal based agent
• Goal based agents only distinguish between goal states and non-goal states.
• It is possible to define a measure of how desirable a particular state is. This
measure can be obtained through the use of a utility function which maps a
state to a measure of the utility of the state. So, utility function maps a state
onto a real number, which describes the associated degree of happiness.
• It uses a model of the world along with a utility function that measures its
preferences among states of the world. Then it chooses an action that leads to
the best expected utility.
Utility-based agents
Learning Agents
• Components:-
• Learning element:- responsible for making improvements.
• Performance elements:- responsible for selecting actions.
• Problem-solving agents
• Problem types
• Problem formulation
• Example problems
• Basic search algorithms
95
Problem solving agent
• The simplest agents are the reflex agents, which base their actions on a direct
mapping from states to actions. Such agents cannot operate well in
environments for which this mapping would be too large to store and would
take too long to learn.
• Goal-based agents, on the other hand, consider future actions and the
desirability of their outcomes.
• There are some Informed search algorithms which on the other hand, can do
quite well given some guidance on where to look for solutions
Problem solving agent
State space forms a graph in which the nodes are states and the arcs between nodes are
actions. (It defines all the possible configurations of the relevant objects associated with
the problem.)
• Goal test :- It determines whether a given state is a goal state.
• Path cost :- A path in the state space is a sequence of states connected by a sequence of
actions. A path cost function assigns a numeric cost to each path. The problem-solving
agent chooses a cost function that reflects its own performance measure.
Path cost = ∑Step costs => Sum of the costs of the individual actions along the path.
(Step cost of taking action a to go from state x to state y is denoted by c(x, a, y) )
99
Problem solving…
• These four components that define a problem can be gathered together into a
single data structure that is given as input to a problem-solving algorithm.
101
Example: Romania
• On holiday in Romania; currently in Arad.
• Formulate goal:
• To be in Bucharest
• Formulate problem:
• states: various cities
• actions: drive between cities
• Find solution:
• sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest 102
Romania with step costs in km
Selecting a state space
• Real world is absurdly complex
state space must be abstracted for problem solving
• (Abstract) state = set of real states
• (Abstract) action = complex combination of real actions
• e.g., "Arad Zerind" represents a complex set of possible routes, detours, rest stops, etc.
• For guaranteed realizability, any real state "in Arad“ must get to some real state "in Zerind"
• (Abstract) solution =
• set of real paths that are solutions in the real world
• Each abstract action should be "easier" than the original problem 104
Problem formulation for Toy problems
• states?
• actions?
• goal test?
• path cost?
106
Simple vacuum world problem
(State space graph)…
• states?
• actions?
• goal test?
• path cost?
108
The 8-puzzle problem…
109
8-Queen problem
There are two main kinds of formulation. An incremental
formulation involves operators that augment the state
description, starting with an empty state; for the 8-queens
problem, this means that each action adds a queen to the state.
A complete-state formulation starts with all 8 queens on the
board and moves them around. In either case, the path cost is
of no interest because only the final state counts. The first
incremental formulation one might try is the following:
8-Queen problem…
Knuth’ s Number Generation
Problem formulation for Real world problems
116
SEARCHING FOR SOLUTIONS
118
Tree search example
119
Tree search example
120
Informal Tree search algorithm
• Basic idea:
• offline, simulated exploration of state space by generating
successors of already-explored states (a.k.a.~expanding states)
121
Informal Graph search algorithms
Some examples of Graph search
State vs. node
• A state is a (representation of) a physical configuration
• A node is a data structure constituting part of a search tree includes
state, parent node, action, path cost g(x), depth
• The Expand function creates new nodes, filling in the various fields
and using the SuccessorFn of the problem to create the
corresponding states.
124
Node Details
Implementation: general tree search
126
Implementation of nodes in search algorithm
• A node is a bookkeeping data structure used to represent the search tree. A state
corresponds to a configuration of the world. Thus, nodes are on particular paths, as
defined by PARENT pointers, whereas states are not. Furthermore, two different
nodes can contain the same world state if that state is generated via two different
search paths.
• Now that we have nodes, we need somewhere to put them. The frontier needs to be
stored in such a way that the search algorithm can easily choose the next node to
expand according to its preferred strategy. The appropriate data structure for this is a
queue.
Implementation of nodes in search algorithm
• The operations on a queue are as follows:
• EMPTY?(queue) returns true only if there are no more elements in the queue.
• POP(queue) removes the first element of the queue and returns it.
• INSERT(element, queue) inserts an element and returns the resulting queue.
• Queues are characterized by the order in which they store the inserted nodes.
• Three common variants are:
• FIFO queue, which pops the oldest element of the queue;
• LIFO queue (also known as a stack), which pops the newest element of the queue;
• Priority queue, which pops the element of the queue with the highest priority according to
some ordering function
Evaluating Search strategies
• Performance of search strategies are evaluated along the following dimensions:-
• Completeness: does it always find a solution if one exists?
• d: the depth of the shallowest goal node (i.e., the number of steps along the path from the root)
129
• m: the maximum length of any path in the state space (may be ∞)
Evaluating Search strategies…
• Time is often measured in terms of the number of nodes generated during the
search, and space in terms of the maximum number of nodes stored in memory.
• For the most part, we describe time and space complexities for search on a tree; for
a graph, the answer depends on how “redundant” the paths in the state space are.
• To assess the effectiveness of a search algorithm, we can consider just the search
cost— which typically depends on the time complexity but can also include a term
for memory usage.
• Or we can use the total cost, which combines the search cost and the path cost of
the solution found (also sometimes called solution cost).
Search strategies
They are of 2 types:-
• Uninformed search / Blind search
Blind search has no additional information about the states
beyond that provided in the problem definition. All they can
do is generate successor and distinguish a goal state from a
non-goal state.
• Informed search / Heuristic search
Informed search identifies whether one non-goal state is
“more promising” than another one.
All search strategies are distinguished by the order in which nodes are expanded. 131
Uninformed search strategies
• Uninformed search strategies use only the information available in the
problem definition. Popular ones are:
• Breadth-first search (BFS)
• Uniform-cost search (UCS)
• Depth-first search (DFS)
• Depth-limited search (DLS)
• Iterative deepening search (IDS)
132
• Bidirectional search (BDS)
Breadth-first search
• It is a strategy in which the root node is expanded first, then all the successors
of the root node are expanded, then their successors. At a given depth in the
search tree, all the nodes are expanded before any node at the next level is
expanded.
• A FIFO queue is used i.e, new successors join the tail of the queue.
133
Breadth Fast Search Algorithm
Breadth-first search algorithm
135
Breadth-first search algorithm
B. For each rule ( from the rule set ) whose L.H.S matches with the
state described in V
Do
I. Apply the rule to generate a new state.
II. If the new state is a goal state then quit and return the state.
III. Otherwise add the new state to the end of the NODE-LIST.
136
Breadth-first search
137
Breadth-first search
• When all step costs are equal, breadth-first search is optimal because it always
expands the shallowest unexpanded node.
• frontier ←a priority queue ordered by PATH-COST, with node as the only element
• loop do
• Both of these modifications come into play in the next example where the
problem is to get from Sibiu to Bucharest in the Romania Touring problem.
Uniform cost search (UCS)…
Uniform cost search (UCS)…
• The successors of Sibiu are Rimnicu Vilcea and Fagaras, with costs 80 and 99, respectively.
• The least-cost node, Rimnicu Vilcea, is expanded next, adding Pitesti with cost 80 + 97=177.
• The least-cost node is now Fagaras, so it is expanded, adding Bucharest with cost 99+211=310.
• Now a goal node has been generated, but uniform-cost search keeps going, choosing Pitesti for
expansion and adding a second path to Bucharest with cost 80+97+101= 278.
• Now the algorithm checks to see if this new path is better than the old one; it is, so the old one is
discarded. Bucharest, now with g-cost 278, is selected for expansion and the solution is returned.
• It is easy to see that uniform-cost search is optimal in general. Uniform-cost search expands nodes in
order of their optimal path cost. (It is because step costs are nonnegative and paths never get shorter
as nodes are added.)
• Hence, the first goal node selected for expansion must be the optimal solution.
Uniform-cost search
• Expand least-cost unexpanded node
• Implementation:
• fringe = queue ordered by path cost
• Then the algorithm’s worst-case time and space complexity is O(b1 + ceiling(C*/ ε) ) ), which can
be much greater than bd. This is because uniform cost search can explore large trees of small
steps before exploring paths involving large and perhaps useful steps.
• When all step costs are equal, b1 + ceiling(C*/ ε) is just bd+1 i.e. when all step costs are the same,
uniform-cost search is similar to breadth-first search, except that the latter stops as soon as it
generates a goal, whereas uniform-cost search examines all the nodes at the goal’s depth to
see if one has a lower cost.
• Thus uniform-cost search does strictly more work by expanding nodes at depth d
unnecessarily.
Depth-first search( DFS)
201
Depth-first search( DFS)
2. Until the stack is empty or the goal node is found out, repeat the
following:-
1. Remove the first element from the stack. If it is the goal node announce
success, return.
2. If not, add the first element’s children if any, to the top of the stack.
202
Depth-first search( DFS)
• Depth-first search always expands the deepest node in the current frontier of the search tree.
• The progress of the search is illustrated next. (Assume A to be Initial node and M to be Goal
node.)
• The search proceeds immediately to the deepest level of the search tree, where the nodes
have no successors. As those nodes are expanded, they are dropped from the frontier, so then
the search “backs up” to the next deepest node that still has unexplored successors.
• A LIFO queue means that the most recently generated node is chosen for expansion. This
must be the deepest unexpanded node because it is one deeper than its parent—which, in turn,
was the deepest unexpanded node when it was selected.
Depth-first search
• Expand deepest unexpanded node
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
204
• Expand deepestDepth-first search
unexpanded node
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
205
Depth-first search
• Expand deepest unexpanded node
• Implementation:
• fringe = LIFO queue, i.e., put successors at fron
206
Depth-first search
• Expand deepest unexpanded node
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
207
Depth-first search
208
Depth-first search
209
Depth-first search
210
Depth-first search
211
Depth-first search
212
Depth-first search
213
Depth-first search
214
Depth-first search
215
Properties of depth-first search
• We may modify the algorithm to avoid repeated states along the path
DFS is complete in finite spaces.
• Time? The number of nodes generated is of the order of O(bm) . It is terrible if m is much larger than d
• Space? It only stores the unexpanded nodes. So it requires 1 +b + b +b ….. m times = O(bm), i.e., linear
space!
• Optimal? No. If it makes a wrong choice, it may go down a very long path and finds a solution, where as there
may be a better solution at a higher level in the tree.
216
Recursive Depth First Search with Depth Limit
Note: it is possible that w2 was unvisited when we recursively visit w1, but became visited
by the time we return from the recursive call.
u
v w3
w1 w2
DFS Algorithm
Flag all vertices as not
visited
8 1 F -
2 F -
source 2 3 F -
9
4 F -
1
5 F -
3 7 6 F -
6 7 F -
4
5 8 F -
9 F -
Pred
Initialize visited
table (all False)
Initialize Pred to -1
Example
Adjacency List Visited Table (T/F)
0 0 F -
1 F -
8 2 T -
3 F -
source 2 9 4 F -
1 5 F -
6 F -
3 7
7 F -
6
4 8 F -
5 9 F -
Pred
Mark 2 as visited
RDFS( 2 )
Now visit RDFS(8)
Example
Adjacency List Visited Table (T/F)
0
0 F -
8 1 F -
2 T -
source 2 9 3 F -
1 4 F -
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 F -
Pred
Mark 8 as visited
Recursive
calls RDFS( 2 )
RDFS(8) mark Pred[8]
2 is already visited, so visit RDFS(0)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 F -
2 T -
source 2 9 3 F -
1 4 F -
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 F -
Pred
Mark 0 as visited
Recursive
calls RDFS( 2 )
RDFS(8) Mark Pred[0]
RDFS(0) -> no unvisited neighbors, return
to call RDFS(8)
Example
Back to 8
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 F -
2 T -
source 2 9 3 F -
1 4 F -
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 F -
Pred
Recursive
calls RDFS( 2 )
RDFS(8)
Now visit 9 -> RDFS(9)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 F -
2 T -
source 2 9 3 F -
1 4 F -
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 T 8
Pred
Mark 9 as visited
Recursive
calls RDFS( 2 )
RDFS(8) Mark Pred[9]
RDFS(9)
-> visit 1, RDFS(1)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 F -
1 4 F -
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 T 8
Pred
Mark 1 as visited
Recursive
calls RDFS( 2 )
RDFS(8) Mark Pred[1]
RDFS(9)
RDFS(1)
visit RDFS(3)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 T 1
1 4 F -
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 T 8
Pred
Mark 3 as visited
Recursive
calls RDFS( 2 )
RDFS(8) Mark Pred[3]
RDFS(9)
RDFS(1)
RDFS(3)
visit RDFS(4)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 T 1
1 4 T 3
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 T 8
Pred
RDFS( 2 ) Mark 4 as visited
Recursive RDFS(8)
calls RDFS(9) Mark Pred[4]
RDFS(1)
RDFS(3)
RDFS(4) STOP all of 4’s neighbors have been visited
return back to call RDFS(3)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 T 1
1 4 T 3
5 F -
3 7 6 F -
6 7 F -
4
5 8 T 2
9 T 8
Back to 3
Pred
RDFS( 2 )
Recursive RDFS(8)
calls RDFS(9)
RDFS(1)
RDFS(3)
visit 5 -> RDFS(5)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 T 1
1 4 T 3
5 T 3
3 7 6 F -
6 7 F -
4
5 8 T 2
9 T 8
Pred
RDFS( 2 )
Recursive RDFS(8) Mark 5 as visited
calls RDFS(9)
Mark Pred[5]
RDFS(1)
RDFS(3)
RDFS(5)
3 is already visited, so visit 6 -> RDFS(6)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 T 1
1 4 T 3
5 T 3
3 7 6 T 5
6 7 F -
4
5 8 T 2
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9) Mark 6 as visited
calls
RDFS(1) Mark Pred[6]
RDFS(3)
RDFS(5)
RDFS(6)
visit 7 -> RDFS(7)
Example
Adjacency List Visited Table (T/F)
0
0 T 8
8 1 T 9
2 T -
source 2 9 3 T 1
1 4 T 3
5 T 3
3 7 6 T 5
6 7 T 6
4
5 8 T 2
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9) Mark 7 as visited
calls
RDFS(1) Mark Pred[7]
RDFS(3)
RDFS(5)
RDFS(6)
RDFS(7) -> Stop no more unvisited neighbors
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9)
calls
RDFS(1)
RDFS(3)
RDFS(5)
RDFS(6) -> Stop
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9)
calls
RDFS(1)
RDFS(3)
RDFS(5) -> Stop
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9)
calls
RDFS(1)
RDFS(3) -> Stop
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9)
calls
RDFS(1) -> Stop
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 )
RDFS(8)
Recursive RDFS(9) -> Stop
calls
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 )
RDFS(8) -> Stop
Recursive
calls
Example
Adjacency List Visited Table (T/F)
0 0 T 8
1 T 9
8
2 T -
3 T 1
source 2 9 4 T 3
1 5 T 3
3 7 6 T 5
7 T 6
6
4 8 T 2
5
9 T 8
Pred
RDFS( 2 ) -> Stop
Recursive
calls
Example
0 Adjacency List Visited Table (T/F)
8 0 T 8
1 T 9
source 2 2 T -
9
3 T 1
1
4 T 3
3 7 5 T 3
6 6 T 5
4
5 7 T 6
8 T 2
9 T 8
Pred
Check our paths, does DFS find valid paths? Yes.
• Once a node has been expanded, it can be removed from memory as soon as
all its descendants have been fully explored.
• For a state space with branching factor b and maximum depth m, depth-first
search requires storage of only O(bm) nodes.
Depth-first search
• This has led to the adoption of depth-first tree search as the basic
workhorse of many areas of AI.
• For problems with large state descriptions, such as robotic assembly, these
techniques are critical to success.
Depth-limited search
• The problem with DFS is that the search can go down an infinite branch and
thus never return. Depth limited search avoids this problem by imposing a
depth limit l which effectively terminates the search at that depth. That is ,
nodes at depth l are treated as if they have no successors.
• The choice of depth parameter l is an important factor. If l is too deep , it is
wasteful in terms of both time and space. But if l < d (the depth at which
solution exists) i,e the shallowest goal is beyond the depth limit, then this
algorithm will never reach a goal state.
246
Depth-limited search
247
Properties of depth- limited search
• Time? O(b l ).
• Optimal? No.
248
Iterative deepening search
250
Iterative deepening search l =0
251
Iterative deepening search l =1
252
Iterative deepening search l =2
253
Iterative deepening search l =3
254
Iterative deepening search
255
Iterative deepening search
• For b = 10, d = 5,
• NBFS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
• NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456
• Overhead = (123,456 - 111,111)/111,111 = 11%
we can see that compared to the overall number of expansions , the total is not
substantially increased.
256
Properties of iterative deepening search
262
Bidirectional Search (BDS)
BDS (contd…)
•The time complexity of bidirectional search using breadth-first searches in both
directions is O(bd/2). The space complexity is also O(bd/2). This is because search
stops in the midway as soon as any one of the search paths from initial state
(forward search) meets with any one of the search paths from goal state
(backward search).
•For the similar condition, the time complexity of breadth first search from initial
state to goal state is O(bd). The space complexity is also O(bd). It is because
searching proceeds only in one direction i.e. from initial state to goal state (only
forward search).
• The motivation is that bd/2 + bd/2 is much less than bd, or in the figure, the area of
the two small circles is less than the area of one big circle centered on the start
and reaching to the goal.
Comparing Uninformed Search Strategies
Repeated states
270
Repeated states
271
Repeated states
272
Repeated states
3. Don’t generate any state that is the same as any state generated
before. This requires that every state is kept in memory. (space
complexity is O(bd ) )
273
Graph search
274
Summary
• Iterative deepening search uses only linear space and not much more time than
other uninformed algorithms
275
Informed Search Strategy
Informed Search Strategy
(Best-first search)
Heuristic search techniques
• Blind searches (uninformed searches)are normally
very inefficient. By adding domain knowledge we can
improve the search process.
• The idea behind the heuristic search is that we explore
the node that is most likely to be nearest to a goal
state.
• A heuristic function has some knowledge about the
problem so that it can judge how close the current
state is to the goal state.
• A heuristic function h(n) = estimated cost of the
cheapest path from the state at node n to a goal state.
Informed Search Strategy
(Heuristic functions)
• The choice of f determines the search strategies.
• Most best first algorithms include as a component of f a heuristic function,
denoted h(n)
• h(n) = estimated cost of the cheapest path from the state at node n to a goal
state.
• h(n) takes a node as input, unlike g(n) in UCS, it depends only on the state
at that node.
• For example, in Romania, one might estimate the cost of the cheapest path
from Arad to Bucharest via the straight-line distance from Arad to
Bucharest.
Heuristic functions (contd…)
• Heuristic functions are the most common form in which additional knowledge
of the problem is imparted to search algorithm.
• Implementation:
Order the nodes in fringe or sequence in decreasing order of desirability.
• Two special cases of Best-first search where h(n) is used as f(n) to guide search:
• Greedy best-first search [only h(n) is used as f(n)]
• A* search [h(n) + g(n) is used as f(n)]
Greedy best-first search
• CLOSED
• It contains nodes that have already been expanded. ( it is
used to ensure that the same node is not expanded more
than once.)
Greedy best-first search
• Complete? No – can get stuck in loops, e.g., Iasi Neamt Iasi Neamt
….
• Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) )
• Time? Exponential
• Space? Keeps all nodes in memory
• Optimal? Yes if h(n) is admissible.
Admissible heuristics
• A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach the
goal state from n.
• A heuristic is consistent if for every node n, every successor n' of n generated by any action a,
h(n) ≤ c(n,a,n') + h(n')
• If h is consistent, we have
• h1(S) = ?
• h2(S) = ?
Admissible heuristics
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
8-puzzle heuristics: explanation
8-puzzle heuristics: explanation (contd…)
Beyond Classical Search
Chapter-4
Local Search Algorithms and Optimization
Problems
• Systematic Search problems:
• The search algorithms that we have seen so far are designed to explore search
spaces systematically. This systematicity is achieved by keeping one or more paths
in memory and by recording which alternatives have been explored at each point
along the path. When a goal is found, the path to that goal also constitutes a
solution to the problem (a sequence of actions from initial state to goal state).
• For example, in the 8-queens problem what matters is the final configuration of
queens, not the order in which they are added.
Local Search Algorithms and Optimization
Problems
• The same general property holds for(contd…)
many important applications as indicated
below:
• Integrated-circuit design
• Factory-floor layout
• Job-shop scheduling
• Automatic programming
• Telecommunications network optimization
• Vehicle routing
• Portfolio management
The family of local search algorithms includes: Hill Climbing, Simulated
Local Search Algorithms and Optimization
Problems (contd…)
• If the path to the goal does not matter, we might consider a different class of
algorithms, ones that do not worry about paths at all.
• Local search algorithms operate using a single current node (rather than multiple
paths) and generally move only to neighbors of that node. Typically, the paths
followed by the search are not retained. Although local search algorithms are not
systematic, they have two key advantages:
• In addition to finding goals, local search algorithms are useful for solving pure
optimization problems, in which the aim is to find the best state according to an
objective function.
• Many optimization problems do not fit the “standard” search model (both
uninformed and informed).
• If elevation corresponds to cost, then the aim is to find the lowest valley—a global
minimum;
• if elevation corresponds to an objective function, then the aim is to find the highest peak—a
global maximum.
• We can convert from one to the other just by inserting a minus sign.
• Local search algorithms explore this landscape. A complete local search algorithm always
finds a goal if one exists; an optimal algorithm always finds a global minimum/maximum.
Local Search Algorithms and Optimization
Problems (contd…)
Hill climbing
• Hill climbing ( basic or steepest-ascent) search algorithm is a
local search algorithm.
II. If it is not a GS but better than the CS, then consider it as the
current state(i,e CS NS) and proceed.
• Solution of ridges:-
• Apply several operators before doing the evaluation
Hill-climbing search (via ridge)
Hill-climbing search
• Problem: depending on initial state, can get stuck in either Local Maxima or Plateau (which also
includes Shoulder) or Ridges.
Note: 1) Plateau is also known as “Flat local maximum”.
2) Shoulder is a type of Plateau having uphill rising scope.
Hill-climbing search: 8-queens problem
• h = number of pairs of queens that are attacking each other, either directly or indirectly
• h = 17 for the above state
The best moves (or successors) having h = 12 are marked
Hill-climbing search: 8-queens problem
• 3. Random-restart hill climbing adopts the well-known adage, “If at first you
don’t succeed, try, try again.” It conducts a series of hill-climbing searches from
randomly generated initial states, until a goal is found.
(The success of hill climbing depends very much on the shape of the state-space
landscape: if there are few local maxima and plateaus, random-restart hill climbing
Simulated Annealing
• A hill-climbing algorithm that never makes “downhill” moves toward states with
lower value (or higher cost) is guaranteed to be incomplete, because it can get
stuck on a local maximum.
• Therefore, it seems reasonable to try to combine hill climbing with a random walk
in some way that yields both efficiency and completeness.
• To explain simulated annealing, we switch our point of view from hill climbing to
gradient descent (i.e., minimizing cost) and imagine the task of getting a
ping-pong ball into the deepest crevice in a bumpy surface.
• If we just let the ball roll, it will come to rest at a local minimum. If we shake the
surface, we can bounce the ball out of the local minimum. The trick is to shake just
hard enough to bounce the ball out of local minima but not hard enough to
dislodge it from the global minimum.
•
Simulated Annealing Algorithm (contd…)
• The local beam search algorithm, which is a path-based algorithm keeps track of k states rather than
just one. It begins with k randomly generated states.
• At each step, all the successors of all k states are generated. If any one is a goal, the algorithm halts.
Otherwise, it selects the k best successors from the complete list and repeats.
• At first sight, a local beam search with k states might seem to be nothing more than running k random
restarts in parallel instead of in sequence.
• In a local beam search, useful information is passed among the parallel search threads. In effect, the
states that generate the best successors say to the others, “Come over here, the grass is greener!” The
algorithm quickly abandons unfruitful searches and moves its resources to where the most progress is
being made.
Local Beam Search (contd…)
• In its simplest form, local beam search can suffer from a lack of
diversity among the k states—they can quickly become concentrated
in a small region of the state space, making the search little more
than an expensive version of hill climbing.
• The analogy to natural selection is the same as in stochastic beam search, except
that now we are dealing with mimicking the natural real life reproduction rather
than asexual reproduction as in stochastic beam search. (Later normally does not
happen in real life).
• Like beam searches, GAs begin with a set of k randomly generated states, called
the population. Each state, or individual, is represented as a string over a finite
alphabet—most commonly, a string of 0s and 1s.
• For example, an 8-queens state must specify the positions of 8 queens, each in a
column of 8 squares, and so requires 8 × log28 bits.
• Alternatively, the state could be represented as 8 digits, each in the range from 1 to
8.
Genetic Algorithms (contd…)
2 4 7 4 8 5 5 2 3 2 7 5 2 4 1 1
(24 non-attacking pairs of queens) (23 non-attacking pairs of queens)
Genetic Algorithms (contd…)
• (a) shows a population of four 8-digit strings representing 8-queens states.
• In (b), each state is rated by the objective function, or (in GA terminology) the fitness function. A
fitness function should return higher values for better states.
• So, for the 8-queens problem, we use the number of nonattacking pairs of queens, which has a
value of 28 for a solution.
• The values of the given four states are 24, 23, 20, and 11.
• In this particular variant of the genetic algorithm, the probability of being chosen for reproducing is
directly proportional to the fitness score, and the percentages are shown next to the raw scores.
Genetic Algorithms (contd…)
• In Figure (c), two pairs are selected at random for reproduction, in accordance with
the probabilities in (b). It is to be noticed that one individual is selected twice and
one not at all.
• For each pair to be mated, a crossover point is chosen randomly from the
positions in the string. In Figure, the crossover points are after the third digit in
the first pair and after the fifth digit in the second pair.
• In Figure (d), the offspring themselves are created by crossing over the parent
strings at the crossover point. For example, the first child of the first pair gets the
first three digits from the first parent and the remaining digits from the second
parent, whereas the second child gets the first three digits from the second parent
and the rest from the first parent. The 8-queens states involved in this reproduction
step are shown in the next figure.
Genetic Algorithms (contd…)
• The example shows that when two parent states are quite different, the crossover operation can
produce a state that is a long way from either parent state.
• It is often the case that the population is quite diverse early on in the process, so crossover (like
simulated annealing) frequently takes large steps in the state space early in the search process
and smaller steps later on when most individuals are quite similar.
• Finally, in Figure (e), each location is subject to random mutation with a small independent
probability.
• One digit was mutated in the first, third, and fourth offspring.
• In the 8-queens problem, this corresponds to choosing a queen at random and moving it to a
random square in its column.
• Genetic Algorithms (contd…)
function GENETIC-ALGORITHM(population,
FITNESS-FN) returns an individual
• inputs: population, a set of individuals
• function REPRODUCE(x , y) returns an individual
• FITNESS-FN, a function that measures the fitness of an
• inputs: x , y, parent individuals
individual
• n←LENGTH(x ); c←random number from 1 to n
• repeat
• return APPEND(SUBSTRING(x, 1, c), SUBSTRING(y, c + 1, n))
• new population ←empty set
• for i = 1 to SIZE(population) do
• x ←RANDOM-SELECTION(population, FITNESS-FN)
• y ←RANDOM-SELECTION(population, FITNESS-FN)
• child ←REPRODUCE(x , y)
(A genetic algorithm. The algorithm is
• if (small random probability) then child ←MUTATE(child
the same as the one diagrammed in
)
Figure, with one variation: in this more
• add child to new population
popular version, each mating of two
• population ←new population parents produces only one offspring, not
• until some individual is fit enough, or enough time has two.)
elapsed
• return the best individual in population, according to
FITNESS-FN
Chapter 5: Adversarial
Search
■ Multi-agent environments:
■ Each agent needs to consider the actions of other agents and
how they affect its own welfare
■ The unpredictability of these other agents can introduce
possible contingencies into the agent’s problem-solving
process
■ cooperative vs. competitive multi-agents
■ Adversarial search problems (often known as Games):
Deals with competitive multi-agents which have conflicting
goals
Games vs. Search Problems
"Unpredictable" opponent
■specifying a move for every possible
opponent reply
•Time limits
■unlikely to find goal, must approximate
Go
AI and Games
■ Or, the total payoff to all players is the same for every instance of the game
(constant sum)
History of Game Playing
■ A game with 2 players (MAX and MIN, MAX moves first, turn-taking) can be defined as a
search problem with:
•
■ Game tree of the game =
initial state + legal moves for each side
• Next slide shows an example on Game tree for tic-tac-toe (noughts and crosses)
Tic-tac–toe Game tree
• The number on each leaf node indicates the utility value of the terminal state
from the point of view of MAX.
• High values are assumed to be good for MAX and bad for MIN (which is how
the players get their names).
• It is MAX’s job to use the search tree (particularly the utility of terminal
states) to determine the best move.
Optimal strategies
• In a normal search problem, the optimal solution would be a sequence of moves
leading to goal state – a terminal state that is a win.
• In a game, on the other hand, MIN has something to say about it.
• MAX therefore must find a contingent strategy, which specifies MAX’s move in
the initial state, then MAX’s moves in the states resulting from every possible
response by MIN, then MAX’s moves in the states resulting from every possible
response by MIN to those moves, and so on.
• Roughly speaking, an optimal strategy leads to outcomes at least as good as any
other strategy when one is playing an infallible opponent.
Optimal strategies (contd…)
Optimal strategies (contd…)
Optimal strategies & Minimax Value
Minimax Value
A Partial Game Tree for Tic-Tac-Toe
Some analysis on Minimax
Some analysis on Minimax (contd…)
Some analysis on Minimax (contd…)
The Minimax algorithm
The Minimax algorithm (contd…)
The Minimax algorithm (contd…)
Properties of Minimax Algorithm
Optimal decisions in multiplayer games
Optimal decisions in multiplayer games
(contd…)
Optimal decisions in multiplayer games
(contd…)
Optimal decisions in multiplayer games
(contd…)
Alpha-beta Pruning
• The problem with minimax search is that the number of game states it has
to examine is exponential in the number of moves.
• Unfortunately we can’t eliminate the exponent, but we can effectively cut
it in half.
• It is possible to compute the correct minimax decision without looking at
every node in the game tree.
• A particular pruning technique called alpha-beta pruning can eliminate
large part of the tree from consideration.
• When applied to a standard minimax tree, it returns the same move as
minimax would, but prunes away branches that can not possibly influence
the final decision.
Alpha-beta Pruning…
• Stages in the calculation of the optimal decision for the game tree in
Figure 5.2:
• (a) The first leaf below B has the value 3. Hence, B, which is a MIN node, has a value of at most 3.
• (b) The second leaf below B has a value of 12; MIN would avoid this move, so the value of B is still
at most 3.
• (c) The third leaf below B has a value of 8; we have seen all B’s successor states, so the value of B is
exactly 3. Now, we can infer that the value of the root is at least 3, because MAX has a choice worth 3
at the root.
• (d) The first leaf below C has the value 2. Hence, C, which is a MIN node, has a value of at most 2.
But we know that B is worth 3, so MAX would never choose C. Therefore, there is no point in looking
at the other successor states of C. This is an example of alpha–beta pruning.
• (e) The first leaf below D has the value 14, so D is worth at most 14. This is still higher than MAX’s
best alternative (i.e., 3), so we need to keep exploring D’s successor states. Notice also that we now
have bounds on all of the successors of the root, so the root’s value is also at most 14.
• (f) The second successor of D is worth 5, so again we need to keep exploring. The third successor is
worth 2, so now D is worth exactly 2. MAX’s decision at the root is to move to B, giving a value of 3.
A simple formula for Minimax
Basic Idea of α-β
From the point of view of the search algorithm, each state is atomic, or indivisible—a
black box with no internal structure.
However, there is a way to solve a wide variety of problems more efficiently. We use a
factored representation for each state: a set of variables, each of which has a value. A
problem is solved when each variable has a value that satisfies all the constraints on the
variable.
The main idea is to eliminate large portions of the search space all at
once by identifying variable/value combinations that violate the
constraints.
Constraint Satisfaction Problems
(contd…)
Each domain Di consists of a set of allowable values, {v1, . . . , vk} for variable Xi.
For example, if X1 and X2 both have the domain {A,B}, then the
constraint saying the two variables must have different values can be
written as <(X1,X2), [(A,B), (B,A)]> or as <(X1,X2), X1!= X2>.
Constraint Satisfaction Problems (Summary)
• Summary:
• Here the goal is to discover some problem state that satisfies a given set of
constraints.
•A constraint satisfaction problem (CSP) is defined by a set of variables X1,
X2,…..Xn and a set of constraints C1,C2,….Cm.
• Each variable Xi has a nonempty domain Di of possible values.
• Each constraint Ci involves some subset of the variables and specifies the allowable
combinations of values for that subset.
Constraint Satisfaction Problems(Summary)
(contd…)
• An assignment of values to some or all of the variables that does not violate
any constraints is called a consistent or legal assignment.
• CSP:
• state is defined by variables Xi with values from domain Di
• goal test is a set of constraints specifying allowable combinations of values for subsets of
variables
• CSP allows useful general-purpose algorithms with more power than standard
search algorithms which are mostly problem specific.
Outline: Focus on next points of discussion
• The constraints require neighboring regions to have distinct colors. Since there are nine places
where regions border, there are nine constraints:
C = {SA != WA, SA != NT, SA != Q, SA != NSW, SA != V, WA != NT, NT != Q, Q
!= NSW, NSW != V}
Constraint Satisfaction Problems (contd…)
•
Constraint graph
• Consider the problem of scheduling the assembly of a car. The whole job is
composed of tasks, and we can model each task as a variable, where the value of
each variable is the time that the task starts, expressed as an integer number of
minutes.
• Constraints can assert that one task must occur before so many tasks can go on at
once.
• Constraints can also specify that a task takes a certain amount of time to complete.
• We now consider a small part of the car assembly, consisting of 15 tasks: install
axles (front and back), affix all four wheels (right and left, front and back), tighten
nuts for each wheel, affix hubcaps, and inspect the final assembly.
Example problem: Job-shop scheduling (contd…)
• The value of each variable is the time that the task starts.
Precedence constraints between individual tasks:
• Whenever a task T1 must occur before task T2, and task T1 takes duration d1 to complete, we add an
arithmetic constraint of the form:
T1 + d1 ≤ T2
Example problem: Job-shop scheduling (contd…)
• In our example, the axles have to be in place before the wheels are put on, and it takes 10 minutes to install an
axle, so we write
AxleF + 10 ≤ WheelRF ; AxleF + 10 ≤ WheelLF ;
AxleB + 10 ≤ WheelRB; AxleB + 10 ≤ WheelLB .
• Next we say that, for each wheel, we must affix the wheel (which takes 1 minute), then tighten the nuts (2
minutes), and finally attach the hubcap (1 minute, but not represented yet):
WheelRF + 1 ≤ NutsRF ; NutsRF + 2 ≤ CapRF ;
WheelLF + 1 ≤ NutsLF ; NutsLF +2 ≤ CapLF ;
WheelRB + 1 ≤ NutsRB; NutsRB + 2 ≤ CapRB;
WheelLB + 1 ≤ NutsLB; NutsLB + 2 ≤ CapLB .
Example problem: Job-shop scheduling (contd…)
Disjunctive constraint:
• Suppose we have four workers to install wheels, but they have to share one tool that
helps put the axle in place. We need a disjunctive constraint to say that AxleF and
AxleB must not overlap in time; either one comes first or the other does:
(AxleF + 10 ≤ AxleB) or (AxleB + 10 ≤ AxleF)
• This looks like a more complicated constraint, combining arithmetic and logic. But
it still reduces to a set of pairs of values that AxleF and AxleB can take on.
Example problem: Job-shop scheduling (contd…)
•
Variations on the CSP formalism
A) Discrete variables:
Discrete finite domains:
Examples: 1) Map-coloring problems
2) Job scheduling with time limits
3) 8-queens problem [This can also be viewed as a finite-domain
CSP, where the variables Q1, . . . ,Q8 are the positions of each queen in
columns 1, . . . , 8 and each variable has the domain Di = {1, 2, 3, 4, 5, 6, 7,
8}.]
[n variables, domain size d O(dn) = no. of possible complete assignments
e.g. Finite domain CSPs include Boolean CSPs, whose variables can be
either true or false. ]
Discrete variables…
• Example: In the map-coloring problem it could be the case that South Australians won’t
tolerate the color green; we can express that with the unary constraint <(SA),SA != green>
Binary constraint:
• Example: SA != NSW is a binary constraint. (A binary CSP is one with only binary
constraints; it can be represented as a constraint graph).
[There are also higher-order constraints such as Ternary constraint.
Example: Asserting that the value of Y is between X and Z, with the ternary constraint
Between(X, Y, Z).]
Variations on the CSP formalism (contd…)
Global Constraints:
• One of the most common global constraints is Alldiff , which says that all of the
variables involved in the constraint must have different values.
Examples:
• Variables: F T U W R O
• Domains: {0,1,2,3,4,5,6,7,8,9}
• A hypergraph consists of
ordinary nodes (the circles
in the figure) and
hypernodes (the squares),
which represent n-ary
constraints.
Cryptarithmatic Problems (contd…)
Example: cryptarithmetic problem
C4 C3 C2 C1
S E N D
+ M O R E
________________
M O N E Y
1. D + E = 10 * C1 + Y
2. C1 + N + R = 10 * C2 + E
3. C2 + E + O = 10 * C3 + N
4. C3 + S + M = 10 * C4+ O
C4 C3 C2 C1
S E N D
Initial state
+ M O R E
-----------------------
M O N E Y M=1 (As C4 =1)
S=8 OR 9
O=0 OR 1 O=0
N=E OR E+1 N=E+1
C2=1
D=Y+5 N+R>8
E=2
R=8 E<>9
E=5 , E = 2, 3, 4 ends with conflict
D=7
N=6 R=9
C3= 0 AND S=9 Contradiction
R=9 - C1 as S=9
C1=1
5+D=Y ORC1=0
5+D=10 + Y
Y= 2
SOLUTION: {S=9, E=5, N=6, D=7, M=1, O=0, R=8, Y=2} and { C1 =1, C2 = 1, C3
=0, C4 = 1 }
One of the solutions f0r this example
C4 C3 C2 C1 1 0 1 1
-------------------- --------------------
S E N D 9 5 6 7
+ M O R E + 1 0 8 5
______________ ______________
M O N E Y 1 0 6 5 2
SOME MORE CRYPTARITHMETIC
PROBLEMS
• MATH + MYTH = HARD
• ODD + ODD = EVEN
• CROSS + ROADS = DANGER
• TWO + TWO = FOUR
• BASE + BALL = GAMES
• TOUGH + DOUGH = RHYME
• YOUR + YOU = HEART
• FOUR + ONE = FIVE
Real-world CSPs
• Assignment problems
• e.g., who teaches what class
• Timetabling problems
• e.g., which class is offered when and where?
• Transportation scheduling
• Factory scheduling
(Notice that many real-world problems involve real-valued
variables)
Real-world CSPs (contd…)
• The constraints we have described so far have all been absolute constraints, violation of
which rules out a potential solution.
• Many real-world CSPs include preference constraints indicating which solutions are
preferred.
• For example, in a university class-scheduling problem, there are absolute constraints that no
professor can teach two classes at the same time. But we also may allow preference
constraints: Prof. R might prefer teaching in the morning, whereas Prof. N prefers teaching
in the afternoon. A schedule that has Prof. R teaching at 2 p.m. would still be an allowable
solution but would not be an optimal one.
• With this formulation, CSPs with preferences can be solved with optimization search
methods, either path-based or local. We call such a problem a constraint optimization
problem, or COP.
Real-world CSPs (contd…)
• In regular state-space search, an algorithm can do only one thing:
search.
•
Standard search formulation (incremental)
• Depth-first search for CSPs with single-variable assignments is called backtracking search
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
Constraint propagation
• Forward checking propagates information from assigned to unassigned variables,
but doesn't provide early detection for all failures:
• Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies
• Example:- if it is raining
then take an umbrella
weather(raining) take(umbrella)
premise/antecedent conclusion/consequent
Knowledge-based agents
• Wife(x,y) female(x)
• INFERENCING:
• Husband(Rajiv , Sonia) Wife(Sonia, Rajiv)
Knowledge-based agents
• There must be a way to add new sentences to the knowledge base and a way
to query what is known.
• The standard names for these operations are TELL and ASK respectively.
• Both operations may involve inference—that is, deriving new sentences from
old.
• Inference must obey the requirement that when one ASKs a question of the
knowledge base, the answer should follow from what has been told (or
TELLed) to the knowledge base previously.
A simple knowledge-based agent
• Like all agents, it takes a percept as input and returns an action. The agent
maintains a knowledge base, KB, which may initially contain some
background knowledge.
• Each time the agent program is called, it does three things. First, it TELLs
the knowledge base what it perceives. Second, it ASKs the knowledge base
what action it should perform. In the process of answering this query,
extensive reasoning may be done about the current state of the world, about
the outcomes of possible action sequences, and so on. Third, the agent
program TELLs the knowledge base which action was chosen, and the
A simple knowledge-based agent
• The details of the representation language are hidden inside three functions that implement
the interface between the sensors and actuators on one side and the core representation and
reasoning system on the other.
• MAKE-ACTION-QUERY constructs a sentence that asks what action should be done at the
current time.
• The details of the inference mechanisms are hidden inside TELL and ASK.
A simple knowledge-based agent
• The agent program shown above appears quite similar to the agents with internal state
described in earlier chapter. Because of the definitions of TELL and ASK, however, the
knowledge-based agent is not an arbitrary program for calculating actions. It is amenable to a
description at the knowledge level, where we need specify only what the agent knows and
what its goals are, in order to fix its behavior.
• For example, an automated taxi might have the goal of taking a passenger from San Francisco
to Marin County and might know that the Golden Gate Bridge is the only link between the
two locations. Then we can expect it to cross the Golden Gate Bridge because it knows that
that will achieve its goal.
• Notice that this analysis is independent of how the taxi works at the implementation level.
• It doesn’t matter whether its geographical knowledge is implemented as linked lists or pixel
maps, or whether it reasons by manipulating strings of symbols stored in registers or by
propagating noisy signals in a network of neurons.
A simple knowledge-based agent
• A knowledge-based agent can be built simply by TELLing it what it needs to
know.
• Then it can Ask itself what to do - answers should follow from the KB
• Agents can be viewed at the knowledge level
i.e., what they know, regardless of how implemented
• Environment
• Squares adjacent to wumpus are smelly
• Squares adjacent to pit are breezy
• Glitter iff gold is in the same square
• Shooting kills wumpus if you are facing it
• Shooting uses up the only arrow
• Grabbing picks up gold if in same square
• Releasing drops the gold in same square
• As for the locations of the pits and the wumpus: we could treat them as unobserved parts of
the state that happen to be immutable—in which case, the transition model for the
environment is completely known; or we could say that the transition model itself is
unknown because the agent doesn’t know which Forward actions are fatal—in which case,
discovering the locations of pits and wumpus completes the agent’s knowledge of the
transition model.
• The agent perceives a stench in [1,2], resulting in the state of knowledge shown in Figure
7.4(a).
• The stench in [1,2] means that there must be a wumpus nearby. But the wumpus cannot be in
[1,1], by the rules of the game, and it cannot be in [2,2] (or the agent would have detected a
stench when it was in [2,1]). Therefore, the agent can infer that the wumpus is in [1,3]. The
notation W! indicates this inference.
• Moreover, the lack of a breeze in [1,2] implies that there is no pit in [2,2]. Yet the agent has
already inferred that there must be a pit in either [2,2] or [3,1], so this means it must be in
[3,1].
• This is a fairly difficult inference, because it combines knowledge gained at different times in
different places and relies on the lack of a percept to make one crucial step.
Knowledge-based Wumpus Agent
• The agent has now proved to itself that there is neither a pit nor a wumpus in [2,2], so it is
OK to move there.
• Agent’s state of knowledge at [2,2] has not been shown; it is just assumed that the agent turns
and moves to [2,3], giving us Figure 7.4(b).
• In [2,3], the agent detects a glitter, so it should grab the gold and then return home.
• It must be noted that in each case for which the agent draws a conclusion from the available
information, that conclusion is guaranteed to be correct if the available information is correct.
• No safe actions
• Smell in (1,1)
• Cannot move
• For example, the semantics for arithmetic specifies that the sentence “x + y =4” is true in a
world where x is 2 and y is 2, but false in a world where x is 1 and y is 1.
• In standard logics, every sentence must be either true or false in each possible world—there is
no “in between.”
Logic…
α |= β
• If α is true, then β must be true. But if α is true, but β is false, then entailment relation
fails.
• Example:
Say, KB contains following two sentences:
• “Cleveland won”
• “Dallas won”
Then the sentence “Either Cleveland won or Dallas won” is entailed by KB.
• Examples:
1. x + y = 4 entails 4 = x + y
2. x = 0 entails xy = 0
Logic…
• A model is a formally structured world with respect to which truth
can be evaluated.
• If a sentence α is true in model m, we say that m satisfies α or
sometimes m is a model of α.
• We use the notation M(α) to mean the set of all models of α.
• The preceding example not only illustrates entailment but also shows how the definition of entailment
can be applied to derive conclusions—that is, to carry out logical inference.
• The inference algorithm illustrated in the previous figures is called model checking, because it
enumerates all possible models to check that α is true in all models in which KB is true, that is,
• Soundness
• i is sound if…
• whenever KB |-i α is true, KB |= α is true
• An inference algorithm that derives only entailed sentences is called sound or truth preserving.
• Completeness
• i is complete if
• whenever KB |= α is true, KB |-i α is true
• An inference algorithm is complete if it can derive any sentence that is entailed.
• If KB is true in the real world, then any sentence α derived from KB by a sound inference procedure is also true in the
real world
Logic…
Logic…
• Grounding is the connection between logical reasoning processes and the real environment
in which the agent exists. In particular, how do we know that KB is true in the real world?
(After all, KB is just “syntax” inside the agent’s head.). A simple answer is that the agent’s
sensors create the connection.
• For example, our wumpus-world agent has a smell sensor. The agent program creates a
suitable sentence whenever there is a smell. Then, whenever that sentence is in the
knowledge base, it is true in the real world. Thus, the meaning and truth of percept
sentences are defined by the processes of sensing and sentence construction that produce
them.
• What about the rest of the agent’s knowledge, such as its belief that wumpuses cause smells
in adjacent squares?
• This is not a direct representation of a single percept, but a general rule—derived, perhaps,
from perceptual experience but not identical to a statement of that experience. General rules
like this are produced by a sentence construction process called learning.
Propositional Logic
[A BNF (Backus–Naur Form) grammar of sentences in propositional logic, along with operator precedences,
from highest to lowest.]
Propositional Logic
P Q ¬P P∧Q P∨Q P⇒Q P⇔Q
• Modus Ponens
• Given: S1 ⇒ S2 and S1, we can derive or infer S2
• And-Elimination
• Given: S1 ∧ S2, we can derive or infer S1
• Given: S1 ∧ S2, we can derive or infer S2
• DeMorgan’s Law
• Given: ¬( A ∨ B) derive ¬A ∧ ¬B
• Given: ¬( A ∧ B) derive ¬A ∨ ¬B
AI: Chapter 7: Logical Agents 557
Inference and proofs - Reasoning Patterns …
•All of the logical equivalences mentioned previously
can be used as inference rules.
•For example, the equivalence for biconditional
elimination yields the following two inference rules:
• 1) If α ⇔ β, we can derive or infer (α ⇒ β) ∧ (β
⇒ α)
• 2) If (α ⇒ β) ∧ (β ⇒ α), we can derive or infer α
⇔β
• .
Inference and proofs - Reasoning Patterns …
• Example Problem:
How these inference rules and equivalences can be used in the Wumpus World: We start with the knowledge base
containing R1 through R5 and show how to prove ¬P1,2, that is, there is no pit in [1,2].
• First, we apply biconditional elimination to R2 (R2: B1,1 ⇔ (P1,2 ∨ P2,1) to obtain
R6: (B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1) .
• Then we apply And-Elimination to R6 to obtain
R7: ((P1,2 ∨ P2,1) ⇒ B1,1) .
• Logical equivalence for contrapositives gives
R8: (¬B1,1 ⇒ ¬(P1,2 ∨ P2,1)) .
• Now we can apply Modus Ponens with R8 and the percept R4 (i.e., ¬B1,1), to obtain
R9 : ¬(P1,2 ∨ P2,1) .
• Finally, we apply De Morgan’s rule, giving the conclusion
R10 : ¬P1,2 ∧ ¬P2,1 .
• That is, neither [1,2] nor [2,1] contains a pit.
Evaluation of Deductive Inference
• Sound
• Yes, because the inference rules themselves are sound. (This can be proven using a
truth table argument).
• Complete
• If we allow all possible inference rules, we’re searching in an infinite space, hence not
complete
• If we limit inference rules, we run the risk of leaving out the necessary one…
• Monotonic
• If we have a proof, adding information to the DB will not invalidate the proof
AI: Chapter 7: Logical Agents 560
Resolution
• Resolution allows a complete inference mechanism (search-based) using only
one rule of inference
• Resolution rule:
• Given: P1 ∨ P2 ∨ P3 …∨ Pn, and ¬P1 ∨ Q1 …∨ Qm
• Conclude: P2 ∨ P3 …∨ Pn ∨ Q1 …∨ Qm
Complementary literals P1 and ¬P1 “cancel out”
• Why it works:
• Consider 2 cases:
AI: Chapter 7: Logical Agents
P1 is true, and P1 is false 561
Resolution in Wumpus World
• This is proof by contradiction: if we prove that KB ∧ ¬P derives a contradiction (empty clause) and
we know KB is true, then ¬P must be false, so P must be true!
• To carry out the proof, need a search mechanism that will enumerate all possible resolutions.
3. Replace implication (A ⇒ B) by ¬A ∨ B
(¬B22 ∨ ( P21 ∨ P23 ∨ P12 ∨ P32 )) ∧ (¬(P21 ∨ P23 ∨ P12 ∨ P32 ) ∨ B22)
4. Distributive Law
(¬B22 ∨ P21 ∨ P23 ∨ P12 ∨ P32 ) ∧ (¬P21 ∨ B22) ∧ (¬P23 ∨ B22) ∧ (¬P12 ∨ B22) ∧ (¬P32 ∨ B22)
• Avoid loops
• Check if new subgoal is already on the goal stack
• Logics are formal languages for representing information such that conclusions can be drawn
• E.g., the KB containing “the Giants won” and “the Reds won” entails “Either
the Giants won or the Reds won”
• E.g., x+y = 4 entails 4 = x+y
• Entailment is a relationship between sentences (i.e., syntax) that is based on
semantics
Models
• Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated
¬ P1,1
¬B1,1
B2,1
• "Pits cause breezes in adjacent squares"
B1,1 ⇔ (P1,2 ∨ P2,1)
B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1)
Logical equivalence
• Model checking
• truth table enumeration (always exponential in n)
• improved backtracking
• And-elimination
α ∧ β
α
• Elimination of complementary literals
α ∨ β , ~α ∨ γ
β∨γ
Resolution algorithm
From rule:- 2
1 2 3 4
R4. (B1,1 ⇒ (P1,2∨ P2,1)) ∧ ((P1,2∨ P2,1) ⇒ B1,1)
Resolution example
Applying end elimination on R4
R5. ((P1,2∨ P2,1) ⇒ B1,1 )
Applying contra-positive law to R5 :-
R6:~ B1,1 ⇒ ~ (P1,2∨ P2,1)
Applying modus ponence to R6 and R2
R7:~ (P1,2∨ P2,1)
Applying D’morgan’s rule to R7:
R8: ~ P1,2 ∧ ~P2,1. applying end elimination to R8:
R9: ~ P1,2 and ~P2,1 are true.
So, there is no pit in either [1,2] or [2,1]
Resolution example
Q2. Prove that there is no pit in [2, 2]
and no pit in [3,1].
Ans:-
From the KB we have:-
from observation: 4
R10: B1,2 , 3
R11: S2,1
R12: ~B2,1 2
From rule:- 1
R13: (B1,2 ⇔ (P1,1∨ P2,2 ∨ P1,3 )) 1 2 3 4 R14. (B2,1 ⇔ (P1,1∨ P2,2 ∨ P3,1 ))
R15. (B2,1 ⇔ (P1,1∨ P2,2 ∨ P3,1 )) ∧ ((P1,1∨ P2,2 ∨ P3,1 ) ⇒ B2,1)
Applying end elimination on R15
Resolution example
R16. ((P1,1∨ P2,2 ∨ P3,1 ) ⇒ B2,1)
Applying contra-positive law to R16 :-
R17:~ B2,1 ⇒ ~ (P1,1∨ P2,2 ∨ P3,1 )
Applying modus ponence to R17 and R12
R18:~ (P1,1∨ P2,2 ∨ P3,1 )
Applying D’morgan’s rule to R18:
R19: ~ P1,1 ∧ ~P2,2. ∧ ~P3,1
Applying end elimination to R19:
R20: ~ P1,1 and ~P2,2 and ~P3,1 are true.
So, there is no pit in [1,1] , [2,2] or [3,1]
Ans:- from observation:-
R1: ~ S1,2
R2: S2,1
Resolution example
R3: ~ W1,1 , ~ W1,2 , ~ W2,1
From rule:-
R4: S1,2 ⇔ (W1,1∨ W2,2 ∨ W1,3)
R5: S2,1 ⇔ (W1,1∨ W2,2 ∨ W3,1)
R6: S1,2 ⇒ (W1,1∨ W2,2 ∨ W1,3) ∧ ((W1,1∨ W2,2 ∨ W1,3) ⇒ S1,2)
Resolution
Applying end elimination on R6 example
R7. ((W1,1∨ W2,2 ∨ W1,3) ⇒ S1,2)
Applying contra-positive law to R7 :-
R8:~ S1,2 ⇒ ~ (W1,1∨ W2,2 ∨ W1,3)
Applying modus ponence to R1 and R8
R9:~ (W1,1∨ W2,2 ∨ W1,3)
Applying D’morgan’s rule to R9:
R10: ~ W1,1 ∧ W2,2. ∧ ~ W1,3
Applying end elimination to R10:
R11: ~ W1,1 and ~W2,2 and ~ W1,3 are true.
Applying bi-conditional elimination to R5:-
R12: (S2,1 ⇒ (W1,1∨ W2,2 ∨ W3,1) )∧ ((W1,1∨ W2,2 ∨ W3,1) ⇒ S2,1)
Resolution example
Applying end elimination on R12
R13. A (S2,1 ⇒ (W1,1∨ W2,2 ∨ W3,1) )
Applying modus ponence to R2 and R13
R14: (W1,1∨ W2,2 ∨ W3,1)
Applying end elimination to R14 and ~ W1,1 :
R15: ( W2,2 ∨ W3,1)
Applying end elimination to R15 and ~ W2,2 :
R15: W3,1
So there is wumpus in [3,1].
Resolution by contradiction example
• This process is also called “data-driven” inference since input data is used to guide the direction
of the inference process.
Forward chaining
• Idea: fire any rule whose premises are satisfied in the KB,
• add its conclusion to the KB, until query is found
Forward chaining algorithm
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Proof of completeness
¬P1,1
¬W1,1
Bx,y ⇔ (Px,y+1 ∨ Px,y-1 ∨ Px+1,y ∨ Px-1,y)
Sx,y ⇔ (Wx,y+1 ∨ Wx,y-1 ∨ Wx+1,y ∨ Wx-1,y)
W1,1 ∨ W1,2 ∨ … ∨ W4,4
¬W1,1 ∨ ¬W1,2
¬W1,1 ∨ ¬W1,3
…