Module 1
Module 1
Artificial Intelligence
Lecture I
1
IntroductIon
6
Perception
8
• The problem of understanding spoken language is a
perceptual problem.
9
Expert Tasks
2. A n a l y ze t h e p ro b l e m : Va r i o u s p o s s i b l e
techniques for solving the problem.
2. A n a l y ze t h e p ro b l e m : Va r i o u s p o s s i b l e
techniques for solving the problem.
14
dEfInIng tHE ProBLEM AS A
StAtE SPAcE SEArcH
ü Suppose we start with the problem statement
“Play Chess”.
16
ØThe legal moves can be described as a set of rule
having two parts.
17
18
19
• The problem of playing chess is defined as a problem of
moving around in a state space.
4. (x, y) ->(x, y − d)
if y > 0 Pour some water out of 3 gallon
jug
23
5. (x, y) (0, y) empty the 4 gallon jug
if x>0
8. (x, y) ->(x-(3-y), 3)
if x+y >=3 and y> 0 Pour water from 4 gallon jug to 3
gallon jug until it is full
24
9. (x, y) ->((x+y), 0)
if x+y <=4 and y> 0 Pour all water from 3 gallon jug to 3
gallon jug into 4 gallon jug
25
GALLONS IN 4 GALLON JUG GALLONS IN 3GALLON JUG RULE APPLIED
0 0 2
0 3 9
3 0 2
3 3 7
4 2 5
0 2 9
2 0 26
• To summarize to provide a formal description of a problem, we
must do the following:
2. Specify one or more states within that space that describe possible
situations from which the problem solving process may start. This is
the initial state.
27
• The problem can then be solved by using the rules
in combination with an appropriate control
strategy to move through the problem space until
a path from an initial state to a goal state is found.
28
ProductIon SYStEMS
• A production system commonly consists of following
four basic components:
29
3. A control strategy that ascertains the order in
which the rules must be applied to the available
database and a way of resolving conflicts that arise
when several rules match at once.
30
controL StrAtEgIES
a) For each way that each rule can match the state described in E do:
i. Apply the rule to generate a new state.
ii. If the new state is a goal, quit and return this state.
iii. Otherwise add the new state to the end of NODE LIST.
32
Algorithm : Depth First Search
a) For each way that each rule can match the state described in E do:
i. Apply the rule to generate a new state.
i
ii. If the new state is a goal, quit and return this state.
iii. Otherwise add the new state to the end of NODE LIST.
Advantages of Depth First Search
• Find the route the salesman should follow for the shortest possible
round trip that both starts and finished at any one of the cities.
36
• One approach is to explore all possible paths in the
tree and return the one with shortest length.
• To select the next city, look at all cities not yet visited and select the
one closest to the current city and go to it next.
38
Problem characteristics
• Heuristic search is a general method applicable to a
large class of problems.
40
41
42
2. Can solution steps be ignored or at least undone if they
prove unwise?
ü Eg : The 8-puzzle
43
3. Is the problem’s universe predictable?
45
4. Is a good solution to the problem obvious without
comparison to all other possible solutions?
46
ü The question is Marcus alive?
47
5. Is the desired solution a state of the world or a path
to the state?
ü The bank president ate a dish of pasta salad with the fork.
ü But with the case of water jug problem the solution is a path to the
state.
48
6. Is a large amount of knowledge absolutely required
to solve the problem or is knowledge important
only to constrain the search?
49
7. Can a computer that is simply given the problem return the
solution or will the solution of the problem require
interaction between the computer and a person?
50
ProductIon SYStEM
cHArActErIStIcS
• Production systems describe the operations that can be
performed in a search for a solution to a problem.
51
• A monotonic production system is a production system in
which the application of a rule never prevents the later
application of another rule that could also have been
applied at the time the first rule was applied.
53
• Partially commutative, monotonic production
systems are useful for solving ignorable problems.
55
ISSuES In HE dESIgn of
SEArcH ProgrAMS
• Every search process can be viewed as a traversal of a tree
structure in which each node represents a problem state
and each arc represents a relationship between the
states represented by the nodes.
56
• The important issues in search are:
57
HEurIStIc SEArcH tEcHnIQuES
• To solve larger problems, domain-specific knowledge
must be provided to improve the search efficiency
• Heuristic
• Any advice that is often effective but is not always
guaranteed to work
• Depth Search
• Breadth Search
• Hill climbing
• Generate-and-test
• Best-first-search
• Problem reduction
• Constraint satisfaction
59
• Means-ends analysis
gEnErAtE And tESt
• This is the simplest of all the strategies.
technique
HILL cLIMBIng
• Hill climbing is a variant of generate and test in which feedback
from the test procedure is used to help the generator
decide which direction to move in the search space.
63
SIMPLE HILL cLIMBIng
• The simplest way to implement hill climbing is as
follows:
66
67
• Both basic and steepest- ascent hill climbing may fail
to find a solution.
68
• A local maximum is a state that is better than all its
neighbours but is not better than some other states
farther away.
69
• A plateau is a flat area of the search space in which a
whole set of neighbouring states have the same
value.
70
• A ridge is a special kind of local maximum.
71
• Some ways of dealing with these problems:
3. Apply 2 or more rules before doing the test. Used for dealing with
ridges.
72
SIMuLAtEd AnnEALIng
• Simulated annealing is a variation of hill climbing in which at the
beginning of the process, some downhill moves may be made.
73
• Simulated annealing as a computational process is patterned after
the physical process of annealing in which physical substances such as
metals are melted(ie raised to high energy levels) and then gradually
cooled until some solid state is reached.
74
• Where ∆E is the positive change in the energy level , T is the
temperature, and k is boltzmann’s constant.
75
• If a slower schedule is used a uniform crystalline structure will be
formed.
76
• Here ∆E is generalized so that it represents not specifically the change
in energy but more generally the change in the value of objective
function.
knowledge engineering
• The variable k describes the correspondence between units of
temperature and the units of energy.
• Since in the analogous process, the units for both E and T are artificial.
77
• So we can incorporate k into T selecting values for T that produce
desirable behavior .
78
• The algorithm for simulated annealing is only slightly different from
the simple hill climbing procedure.
79
Algorithm: Simulated Annealing
1. Evaluate the initial state. If it is also a goal state then return it and
quit. Otherwise continue with the initial state as the current state.
80
4. Loop until a solution is found or until there are no new operators
left to be applied in the current state.
a. Select an operator that has not yet been applied to the current state
and apply it to produce a new state.
• If it not goal state but is better than current state, then make it current
state. Also set BEST- SO- FAR to this new state.
81
• If it is not better than current state, then make it current state with
probability p’.
82
BESt fIrSt SEArcH(or grAPHS)
• Best first search is a way of combining the advantages of both depth
first search and breadth first search.
• BFS is good because it does not get trapped on dead end paths.
• One way of combining the two is to follow a single path at a time but to
switch path whenever some competing paths looks more promising
than the current one.
83
• At each step of best first search we select the most promising of the
nodes we have generated so far.
• We then expand the chosen node by using the rules to generate its
successors.
• If not all those new generated nodes are added to the set of nodes
generated so far.
• Again the most promising node is selected and the process continues.
84
knowledge engineering 5-01-2015
85
• This process is similar to procedure for steepest ascent hill climbing
with two exceptions.
1. In hill climbing one move is selected and all others are rejected,
never to be re-considered.
• In best first search one move is selected but the others are kept around
so that they can be revisited later if the selected path becomes less
promising
86
2. Further in best first search, the best available state is
selected even if that state has a value that is lower than the
value of the state that was just explored.
• This contrasts with hill climbing which will stop if there are no
successor states with better values that the current state.
87
• To implement a graph search procedure we need to use 2 lists of nodes:
• OPEN :
• Nodes that have been generated and have had the
heuristic function applied to them but which have
not yet been examined.
89
90
tHE A * ALgorItHM
• The best first algorithm is a simplification of an A *
algorithm.
91
• The function h’ is an estimate of the additional cost of
getting from the current node to a goal state.
• f’= g + h’
92
Algorithm : A*
93
ü Otherwise pick the node on OPEN with lowest f’
value.
ü Call it BESTNODE, remove it from OPEN and place it
on CLOSED.
• if so call the node on CLOSED OLD and add OLD to the list of
BESTNODE’s successors .
96
• If a better path to OLD is found propagate the improvement
to OLD’s successor’s.
e. If SUCCESSOR was not already on either OPEN or
CLOSED, then put it on OPEN and add it to the
list of BESTNODE’s successors.
97
98
99
100
101
102
103
ProBLEM rEductIon
• AND – OR GRAPHS
• One AND arc may point to any number of successor nodes all of which
must be solved in order for the arc to point to a solution.
104
105
106
107
108
knowledge engineering 5-01-2015
109
MEAnS End AnALYSIS
• This method centers around the detection of differences between the
current state and the goal state.
110
• So a subproblem of getting to a state in which the operator can be
applied is set up.
• The opertor may not be producing the exact goal state that we
want.
111
• Means end analysis relies on a set of rules that can transform one
problem state into another.
• And a right hand side that describes the aspects of the problem
state that will be changed on application of the rule.
112
• A separate table called difference table indexes the rules by the
differences that they can be used to reduce.
• Example
• R1: (A V B) (B V A)
113
• R3: (A B) (¬ ¬A)
• R4: (A B) (¬A V B)
• Li = (R V (¬P Q))
• L g= (( P V Q) V R)
114
• To determine Lg from Li requires a few simple transformations.
• Li = ((¬P Q) V R) using R1
• Li = ((¬¬ P V Q) V R) using R4
115
AO* algorithm
1. Let G be a graph with only starting node INIT.
2. Repeat the followings until INIT is labeled SOLVED or h(INIT) >
FUTILITY
a) Select an unexpanded node from the most promising path
from INIT (call it NODE)
b) Generate successors of NODE. If there are none, set h(NODE)
= FUTILITY (i.e., NODE is unsolvable); otherwise for each
SUCCESSOR that is not an ancestor of NODE do the following:
i. Add SUCCESSSOR to G.
ii. If SUCCESSOR is a terminal node, label it SOLVED and set
h(SUCCESSOR) = 0.
iii. If SUCCESSPR is not a terminal node, compute its h
c) Propagate the newly discovered information up the graph by doing the
following: let S be set of SOLVED nodes or nodes whose h values have
been changed and need to have values propagated back to their
parents. Initialize S to Node. Until S is empty repeat the followings:
(2)
C
An Example
[15] A [13]
4 5
5
(4) B 2 D (8)
(2)
C
An Example
[15] A [8]
4 5
5
(4) B 2 D (3)
(2)
C 2
4
(1) E
(0) G
An Example
[15] A [9]
4 5
5
(4) B 2 D (4)
(2)
C 2
2
4
(3) E
3
(0) G
An Example
[15] A Solved
4 5
5
(4) B 2 D Solved
(2)
C 2
2
4
(3) E
3
(0) G Solved
conStrAInt SAtISfActIon
126
• OUTPUTS: it is a model where assignment of values to
variables are done so that all values val( Vi)are in dom
(Vi) and all the constraints are satisfied.
• Constraints are that no two alphaqbets can have the same value and
the values assigned should satisfy the given arithmetic equation.
129
C4C3 C2 C1
L O G I C
L O G I C +
PR O L O G
Initial state:
130
1. 2C = G or 2C = G +10
2. G is even
3. C1 + 2I = O or C1 + 2I = O+10
4. C2 + 2G = L or C2 + 2G =L +10
5. C3 +2O =O or C3 +2O = O + 10
6. C4 +2L =R +10 and P=1 or C4 +2L =R and P=0
Now this list of initial constraints is complete, now some more constraints
based on some guess need to be generated.
131
• There are 2 possible values for for O, either O= 0 or
132
133
134
gAME PLAYIng
• Game playing is a fascinating area for AI researchers.
135
• In 1960, Arthur Samuel succeded in building the first significant ,
operational game playing for checkers.
• The program could play checkers and learn more from its mistakes and
improve its performance.
136
• Multiplayer games which involve more than 2players include card games
such as bridge.
• All of these have different goals and hence different AI techniques can be
used to solve these.
• However one thing is common that the game tree needs to be generated
to find the solution for the game.
137
• Game playing is different in many aspects from other search problems.
• First the moves are not in the hands of the player. It is difficult to predict
the opponents move.
• Second, since there are 2 players there is always a time limit or there is a
chance of opponent’s win, it is advisable to select approximate move
instead of waiting for the optimal move.
138
MInIMAx SEArcH ProcEdurE
knowledge engineering
• The initial state is the board position and information
on which player move first.
knowledge engineering
terminal states.
140
• These states and legal moves forms the game’s search
tree.
• Given a minimax search tree, the optimal strategy
can be determined by examining the minimax value
of each node.
knowledge engineering
state, assuming bovh players play optimally.
MIN node
144
knowledge engineering 5-01-2015
145