Upload
sangeeta-bansal
View
216
Download
0
Embed Size (px)
Citation preview
7/30/2019 Production Rules
1/57
1
PRODUCTION SYSTEMS
Production systems (ps) Provide a scheme for
structuring AI programs and performing the search
process.A PS consists of
A collection of condition action pairs called
production rules A database of state information
A procedure for invoking the production rules
7/30/2019 Production Rules
2/57
2
A PS is a model for solving an AI
problem Typical PS s
Expert system shells
which provide environmentsfor the construction of
knowledge based ES
General problem solving
architectures for problem
solving (SOAR)
7/30/2019 Production Rules
3/57
3
SIMPLE EXAMPLE OF A
PRODUCTION SYSTEMAccept an integer x and produce its roman numeral
representation
1. PRODUCTION RULES(a) If x is null then prompt the user and read x.
(b) If x is not null and is bigger than 39 then
print too big and make x null.(c) If x is not null and is between 10 and 39
then print x and reduce x by 10.
7/30/2019 Production Rules
4/57
4
(d) If x is not null and is equal to 9 then print IXand reduce x to 0.
(e) If x is not null and is between 5 and 8 then print V and reduce x by 5.
(f) If x is not null and is equal to 4 then print IV
and reduce x to 0.(g) If x is not null and is between 1 and 3 then print
I and reduce x by 1.
(h) If x is not null and is equal to 0 then print an end
of line and make x null.
7/30/2019 Production Rules
5/57
5
2. Database : The value of the sole variable x
3. Control Scheme : Test conditions in an
arbitrary order until one is true; execute
corresponding action; repeat indefinitely.
7/30/2019 Production Rules
6/57
6
;Lisp program to convert integer to Roman numerals
(Defun Roman (x))
loop
(cond
((null x)(print enter number)(setq x (read)))
(greaterp x 39) (print too big)(setq x wil))
((greaterp x 9) (print x)(setq x (diference x 10)))
((equal x 9) print ix)(setq x 0)
((greaterp x 4) (print v)(setq x (diference x 5)))
((equal x 4) print iv)(setq x 0)
((greaterp x 0) (print I) (setqx (sub1 x )))
((zerop x) (setq x nil )
)
(Go loop))
7/30/2019 Production Rules
7/57
7
CONTROL STRATEGIES
Whether the problem is solved or not, how
quickly the solution is arrived depends on
the control strategy. If more than one rulematches the left side of the current state,
which one to choose ?
7/30/2019 Production Rules
8/57
8
Requirements of a good control strategy
- IT Must Cause MotionControl strategies that do not cause motion
will never lead to a solution.
Example : In the water jug problem thestrategy of choosing the first applicable rule
from the top of the list of rules would
continuously fill the 4-gallon jug. It wouldnever solve the problem.
7/30/2019 Production Rules
9/57
9
- Control strategy must be systematic
Example : In the water jug problem,choosing a rule at random from among the
applicable rules causes motion, but same
state may be arrived several times, thusmany steps are needed than necessary.
A systematic Control Strategy causes global
as well as local motion
7/30/2019 Production Rules
10/57
10
Two systematic control strategies
1. Depth-first search
2. Breadth-first search
Depth-first search - Method :
Construct a tree with initial state as root
Generate its offspring
Pursue the branch until it yields a solution or it is
a dead end i.e. no child can be generated If a dead end is reached, back tracking occurs, i.e.the most recently visited state is expanded andnodes are revisited
7/30/2019 Production Rules
11/57
11
ALGORITHM : DFS1. If the initial state is a goal stats quit
and return success.
2. Otherwise do the following untilsuccess or failure is signaled.
(a) Generate a successor E of the initialstate. If there are no more successors,
signal failure.
(b) Call DFS with E as the initial state
(c) If success is returned,signal success otherwise continuein this loop.
A depth first search tree (DFS) for water jug problem.
7/30/2019 Production Rules
12/57
12
BREADTHFIRST SEARCHMETHOD :
Construct a tree with initial state (IS) as root
Generate offsprings by applying each of the
applicable rules to IS
For each leaf node generate its successors
Continue the process until some ruleproduces the goal state
7/30/2019 Production Rules
13/57
13
ALGORITHM (BFS)
1. Create a variable called node-listand set it to initial state.
2. Until a goal state is found or
node-list is empty do(a) Remove the first element from
node-list and call it E.
If node-list was empty quit.
(b) For each way that each rule
can match E, do : Two Levels of BFS for water jug problem
(i) Apply the rule to generate a new state
(ii) If the new state is a goal state, quit and return this state.
(iii) Otherwise, add the new-state to the end of node-list
7/30/2019 Production Rules
14/57
14
Example : Consider a map of cities ofFrance, Transformed into a graph, which is
an explicit representation of a state space.
The implicit state space would be generated
by applying the operators rather than pre-
existing.
7/30/2019 Production Rules
15/57
7/30/2019 Production Rules
16/57
16
(defun extract-path (n)
(cond ((null n) nil)
(t (append (extract-path (get n pointer))
(list n ) )) ) )
defun successors (N) (GET N ADJCNT)
(defun ((null L1 L2)
(cond ((Null L1) nil )
(( MEMBER (CAR (CDR L1 L2))
(( T cons (car L1) (set-diff (cdr L1) L2)))))
for bfs step 5 i.e. (setq L (set-diff L closed))
(setq open (append L (set-diff open L))) is replaced with(setq L (set-diff(set-diff L open) closed))
(setq open (append open L ))
(new nodes are put on the end of open)
7/30/2019 Production Rules
17/57
17
Adjacency data (For eachcity, the other citiesdirectly, connected to it)
(putprop brest (rennes)adhct)
(putrop rennes (laen parisbrist
nantes) adjct)
(putprop paris (Calais nancy)
Dijon limoges rennes
Caen) adjct :Depth-first-search remes
aviiur)
Given the round about route(rennes caen, calajs nancystrasdooy Dijon lyongrendble avignon)
7/30/2019 Production Rules
18/57
18
BFS DFS
1. Never gets trapped exploring a path May explore a single un-
which does not lead to a solution. fruitful path for a long time.
2. Guaranteed to find a solution if it May find a long path
exits. If multiple solutions exists a when a shorter path exists
minimal one will be found
3. Requires more memory Requires lessmemory
(All the tree that has so far been (Only the nodes on the
visited must be stored) current path are to
be stored)
4. All nodes in level n must be By chance a solution may be
examined before any node found without examiningmuch
on level n + 1 can be of the nodes
examined
5. Only the best solution is found Can stop when any one
solution is found
7/30/2019 Production Rules
19/57
19
THE TRAVELLING
SALESPERSON PROBLEM A list of cities a sales persons has to visit
exactly once.
Direct routs between each pair of cities.
The salesperson has to start at any one of
the cities and make a round trip .
Find the shortest route
7/30/2019 Production Rules
20/57
20
The number of paths among N different cities is
N-1, N-2, 3.2.1 = (N-1) !
The time to examine a single path is proportional
to N The total tine to perform the search is proportional
to N !
If N = 10, 10! =3, 625, 800If N = 25, the number will be very large
This phenomenon is called combinatorial explosion
7/30/2019 Production Rules
21/57
21
BRANCH AND BOUND TECHNIQUE
Generate complete paths keeping track of
the shorted path found so far
Stop exploring any path, as soon as itspartial length exceeds the shortest path
found so far
The method is efficient but still requiresexponential time.
7/30/2019 Production Rules
22/57
22
HEURISTIC SEARCH Control strategy to solve hard problems efficiently
Need not cause motion and need not be systematicbut provides a very good solution; the solution
may not be the best A heuristic is a rule of thumb or judgementaltechnique used in problem solving
Heuristic methods lead to a solution some of the
time but provide no guarantee of success They reduce the number of a alternatives, and
thereby obtain a solution in a tolerable amount oftime
7/30/2019 Production Rules
23/57
23
SOLUTION OF TRAVELLING
SALESPERSON PROBLEM
USING HEURISTIC SEARCH
1. Arbitrarily select a start city
2. To select the next city, look at all citiesnot yet visited and select the one closest tothe current city, go to it next
Repeat step2 until all cities have beenvisited
Execution time = 1+2+3+ . +(N-1)+N =N(N+1)/2 = 0(N2)
7/30/2019 Production Rules
24/57
24
Some special purpose heuristicsProblem :Discovering interesting ideasconsider a function
Y = f ( x , y) = x + yHeuristic : Two arguments are identicalleads to the idea of squaring
Y = f (x, y) = x U y
The heuristic leads to the idea of identifyfunction
7/30/2019 Production Rules
25/57
25
REASONS FOR USING HEURISTICS
Without heuristics we end up in a combinatorial explosion
Rarely we need the optimum solution; a goodapproximation usually serves well.
People when they solve problems are not optimizers butsatisfiers. As soon as they find a good solution, they quit
Example : Searching for a parking space
The approximations produced by heuristics may not be
very good in the worst case, worst cases rarely arise in thereal world.
7/30/2019 Production Rules
26/57
26
In a rule based search process, heuristic
knowledge can be incorporated In the rules
themselves as in a chess playing system not simply the set of
legal moves, but a set of sensible moves
determined by the rule writer may be described.
As a heuristic function that evaluates problem
states and determines how desirable they are. The
heuristic function is evaluated to a number.
7/30/2019 Production Rules
27/57
27
PROBLEM
CHARACTERISTICSHeuristic Search is a general method to
solve a large class of problems. To choose a
specific appropriate method for a problem,it is necessary to analyse the problem along
several key dimensions.
1. Is the problem decomposable into a set ofindependent smaller or easier sub-
problems?
7/30/2019 Production Rules
28/57
28
Example of a decomposable problem
7/30/2019 Production Rules
29/57
29
Example of a non-decomposable problem
Consider the BLOCKS WORLD problem
7/30/2019 Production Rules
30/57
30
Available operators:
1. If block x has nothing on it, pick up x and put
it on table
CLEAR (x) ON (x, TABLE)2. CLEAR (x) and CLEAR (y) ON (x,y)
The goal state can be represented as ON(B,C)
and ON(A,B)
To achieve ON(B,C) from start state we can
apply ON (C,TABLE) and ON(B,C)
7/30/2019 Production Rules
31/57
31
Example of a non-decomposable problem
contd..
7/30/2019 Production Rules
32/57
32
Example of a non-decomposable problem
contd..
While achieving the second sub-goal, the
first sub-goal is not achieved, as the two
sub-problems are not independent.They interact and these interactions must
be considered in order to arrive at a solution
for the entire problem.
7/30/2019 Production Rules
33/57
33
2.Can solution steps be ignored or undone?
Mathematical theorem proving :
- Suppose we prove a lemma, but it is not useful
- We prove another lemma which is useful toprove the theorem
- We didn't lose anything except some effort
- Simple control strategy to solve the problem
7/30/2019 Production Rules
34/57
7/30/2019 Production Rules
35/57
35
Can solution steps be ignored or undone? Contd..
suppose we slide 5 into empty cell.
To slide 6 into the empty cell, we need to undo the
previous step.To undo an incorrect step, you need to record the
order in which operations are performed.
Mistakes can be recovered but not easily.
Slightly more complicated control strategy
7/30/2019 Production Rules
36/57
36
Can solution steps be ignored or undone? Contd..
Problem of playing chess
A great deal of effort for making each decision
A stupid move realized after a couple of movescannot be corrected.
Cannot play as though it had never made astupid move
Ignorable problemssolution steps can be ignored
Recoverable problems solution steps can be
undoneIrrecoverable problems solution steps cannot beundone
7/30/2019 Production Rules
37/57
37
3. Is the Universe predictable ?
8 Puzzle problem : A certain outcome problemis one in which we can plan a sequence of movesto reach a resulting state
Planning can be used to generate a sequence ofoperations that guarantee to lead to a solution
Playing Bridge is an uncertain outcome problem Cannot exactly know where all the cards are and
what the other player will do on his turn
7/30/2019 Production Rules
38/57
38
Probabilities of various outcomes are used tochoose a plan
Planning can generate a sequence of operators
with a good probability of leading to a solution. A number of solution paths have to be explored
Hardest problems -Irrecoverable, uncertain outcome
Other examples : controlling a robot arm
- Obstacles into the path
- Gears might stick
-Error may cause the arm to knock over astack of things
Helping a lawyer decide how to defend his clientagainst murder case.
7/30/2019 Production Rules
39/57
39
4. Is a good solution absolute or relative ?
Consider the following database of facts
1. Marcus was a man
2. Marcus was a Pompeian
3. Marcus was born in 40 A.D
4. All men are mortal5. All Pompeian's died when the volcano erupted
in 79 A.D
6. No mortal lives longer than 150 years
7. It is now 2003 A.D
7/30/2019 Production Rules
40/57
40
Consider the question Is Marcus alive?
There are two reasoning paths leading to theanswerMarcus is dead.
Path1 Axioms used
8. Marcus is mortal 1,4
9. Marcuss age is 1963 years 3,7
10.Marcus is dead 8,9,6
Reasoning path- 2
11.All Pompeian's are dead now 7,5
12.Marcus is dead 11,2
7/30/2019 Production Rules
41/57
41
Comments :
We are interested in only the answer to
the question
- it does not matter which path we
follow
If one path leads successfully to the
answer, there is no need of exploring the
other path
7/30/2019 Production Rules
42/57
42
Now consider the following table of distances
(Km) for traveling sales person problem :
New Delhi Bombay Madras Calcutta
New Delhi - 2200 2350 2800
Bombay 2200 - 3000 2500Madras 2350 3000 - 1200
Calcutta 2800 2500 1200 -
Th l i t fi d th h t t th th t i it
7/30/2019 Production Rules
43/57
43
The goal is to find the shortest path that visits
each city exactly once.
First Path is not definitely the solution. This example
illustrates any-path problem or best-path problem.
7/30/2019 Production Rules
44/57
44
5. Is the solution a state or a path to a state?
consider the sentence The bank president
ate a dish of pasta salad with the fork.
In interpreting the sentence, some of thesources of ambiguity are
7/30/2019 Production Rules
45/57
45
Is the solution a state or a path to a state?
Contd..
7/30/2019 Production Rules
46/57
46
Is the solution a state or a path to a state?
Contd..
PASTA SALAD SALAD contains pasta or not? Dogfood does not contain dog
With the fork modifies the verb eat;
He ate with vegetables or He ate with friends, thenstructure would be different.
Thus search would be required for complete
interpretation for the sentence.For the above NLU problem, no need to record the
processing by which the interpretation was found.
7/30/2019 Production Rules
47/57
47
Is the solution a state or a path to a state?
Contd..
In the water jug problem, it is not sufficient
to say that the final state is (2,0), but the
path or a sequence of operations leading tothe goal state are required .
NLU problem- solution is a state
Water jug problempath to a state
7/30/2019 Production Rules
48/57
48
6. What is the role of knowledge ?
Playing Chess requires rules for determining the legalmoves and control mechanism to implement search.
Additional knowledge as good strategy and tactics help
to constrain the search and speed up the execution.Consider the problem of scanning daily newspapers and todecide which paper supports which party.
- For this problem, a great deal of knowledge as namesof candidates in each party, opposing government meanssupporting opposition party etc. is required.
7/30/2019 Production Rules
49/57
49
7. Does the task require interaction with a
person?
Does the task require interaction with a person?
Theorem proving is a solitary problem. : The
program is capable of finding a proof withoutinteraction
Expert system is a conversational problem
.Communication is required either to provide
additional assistance to computer or to provideadditional information to the user.
7/30/2019 Production Rules
50/57
50
Types of Productive (PS) systems
Monotonic production system :
The application of a rule prevents the
application of another rule that could alsohave been applied at the time the first rule
was selected. A PS which is not monotonic
is called non monotonic.
7/30/2019 Production Rules
51/57
51
Partially commutation (PS) :
It is a PS with the property if the sequence of rulestransforms state x into state y, then anypermutation of these rules also transforms state xinto state y.
A commutative PS is one that is monotonic andpartially commutative. Formally all kinds ofproblems can be solved by all kinds of system.Practically there is a relationship between thekinds of problems and kinds of systems.
7/30/2019 Production Rules
52/57
52
Examples :
Monotonic No monotonic
Partiallycommutative
Theoremproving
Robotnavigation
blocks word
8-puzzle
Not Partiallycommutative
Chemicalsynthesis
Bridge
7/30/2019 Production Rules
53/57
53
Monotonic & partially commutative systems arefor ignorable problems
Non Monotonic & partially commutative systemsare for recoverable problems.
Issues in the design of search problems :
Search process can be viewed as a traversal oftree.Each node represents a problem state andeach arc represents a relationship between thestates.
In practice, most of the tree need not be exploredfor reaching a solution.
Most search programs represent the tree implicitlyin the rules and generate explicitly those parts
that they decide to explore.
7/30/2019 Production Rules
54/57
54
Issues in search technique :
The direction in which to conduct the test
forward versus backward reasoning (to search
from start state to goal state or from goal to start)
How to select applicable rules or how to match
rules against states How to represent each node of the search process
(knowledge representation problem).
The search space may be an arbitrary directed
graph rather than a tree as same nodes may be
generated as part of several paths.
7/30/2019 Production Rules
55/57
55
Search trees versus search graphs
7/30/2019 Production Rules
56/57
56
Search trees versus search graphs contd..
Using tree search requires no book keeping
but lot of effort is wasted in expanding the same
nodes.
By traversing a directed graph, the waste of effort
can be avoided with additional book keeping. BFS
keeps track of nodes generated, but DFS does not
DFS could be modified with the expense ofadditional storage.
7/30/2019 Production Rules
57/57
57
Algorithm to search duplicate
nodes in search graph1. Examine the set of nodes generated to see if
the new node already exists.
2. If it does not, add it to the graph
3. If it does already exists, do the following :a) Set the node being expanded to point to
the already existing node.
b) If the new path is better than the oldpath, record the new path and propagate
the change.