AIML - Module1
AIML - Module1
Module1
Contents
Chapter# Title Page No
1 What is Artificial Intelligence? 2
2 Problem Spaces and search, 14
3 Heuristic search techniques 29
Dr.TGS
1
Chapter 1: What is Artificial Intelligence?
“Artificial Intelligence (AI) is the study of how to make computers do things, which
at the moment people do better”.
AI is accomplished by studying how human brain thinks and how human learn,
decide and work while trying to solve a problem and then using the outcomes of
this study as a basis of developing intelligent software and systems.
2
Q3. What are the advantages of Artificial Intelligence?
Answer: It is clear that AI will have to fill the gap of human knowledge and it will
make man’s work easier and pleasant. However, some presumed advantages of
using AI are given below.
1. AI can replace humans being in some more specific jobs for some business
store and household day to day activities and will help to sort out the
manpower.
2. AI machines can help in hospitals, providing food and medicines where
human being feared to be attacked by such disease. Robotics is good
example.
3. It is estimated that AI will help human being in aeronautics to know the
universe.
4. AI can help to unfold the fields which are not explored yet.
5. By using AI we can send machines in such areas where human being loss
is estimated. E.g. Military and Terrorism.
3
Mundane Tasks Formal Tasks Expert Tasks
• Perception • Games • Engineering
o Vision o Chess o Design
o Speech o Backer o Fault Finding
• Natural Language gammon o Manufacturin
o Understanding o Checkers- Go g Planning
o Generation • Mathematics • Scientific Analysis
o Translation o Geometry • Medical Diagnosis
• Common Sense o Logic • Financial Analysis
Reasoning o Integral
• Robot Control Calculus
o Proving
Properties of
Programs
Answer: At the heart of research in Artificial Intelligence lies what Newell and
Simon [1976] call the physical symbol hypothesis. They define a physical symbol
system as follows:
The physical symbol system consists of a set of entities called symbols which are
physical patterns that can occur as components of another entity called symbol
structure (expression). Besides these structures the system also contains a
collection of processes that operate on expressions to produce other expressions:
processes of creation, modification, reproduction and destruction. A physical
symbol system is a machine that produces through time and evolving collection of
symbol structures. Such a system exists in a world of objects wider than just this
symbolic expression themselves.
The Physical Symbol System Hypothesis: A physical symbol system has the
necessary and sufficient means for general intelligent action.
Answer:
The three programs or approaches to play tic-tac-toe are discussed below. The
programs in this series increase in:
• Their complexity
• Their use of generalizations
• The clarity of their knowledge
• The extensibility of their approach
Thus, they move toward being representations of what we call Al techniques.
5
Program 1
Data Structures
Board A nine-element vector representing the board, where the elements of the vector
correspond to the board positions as follows:
An element contains the value
• if the corresponding square is blank,
• if it is filled with an X, or
• if it is filled with an O.
Movetable A large vector of 19,683 elements (3 raise to the power 9), each element of which is a
nine-element vector. The contents of this vector are chosenspecifically to allow the
algorithm to work .
Algorithm
To make a move, do the following:
1. View the vector Board as a ternary (base three) number. Convert it to a decimalnumber.
2. Use the number computed in step I as an index into Movetable and access thevector stored there.
3. The vector selected in step 2 represents the way the board will look after the movethat should be
made. So set Board equal to that vector.
Comments : This program is very efficient in terms of time . But it takes a lot of space to store the
table that specifies the correct move to make from each board position. Possibility of errors.
Program 2
Data Structures
Board A nine-element vector representing the board, as described for Program1 . But instead
of using the numbers 0, I , or 2 in each element,we store 2 (indicating blank), 3
(indicating X), or 5 (indicating O).
Turn An integer indicating which move of the game is about to be played; 1 indicates the first
move, 9 the last.
Algorithm : The main algorithm uses three subprocedures:
Make2 Returns 5 if the center square of the board is blank, that is, if Board[5]= 2. Otherwise,
this function returns any blank no corner square( 2, 4, 6, or 8).
Posswin(p) Returns 0 if player p cannot win on his next move; otherwise, itreturns the number of
the square that constitutes a winning move.This function will enable the program both
to win and to block theopponent's win. Posswin operates by checking, one at a time,
eachof the rows, columns, and diagonals. Because of the way values arenumbered, it
can test an entire row (column or diagonal) to see if it is a possible win by multiplying
the values of its squares together.If the product is 18 (3 x 3 x 2), then X can win. If the
product is 50(5 x 5 x 2), then 0 can win. If we find a winning row, we determinewhich
element is blank, and return the number of that square.
Go(n) Makes a move in square n. This procedure sets Board[n] to 3 ifTurn is odd, or 5 if Turn is
even. It also increments Turn by one.The algorithm has a built-in strategy for each move
it may have to make. It makes theodd-numbered moves if it is playing X, the even-
numbered moves if it is playing O.
The strategy for each turn is as follows:
6
Turn=1 Go(1) (upper left comer).
Turn=2 If Board[5] is blank, Go(5), else Go( 1).
Turn=3 If Board[9] is blank, Go(9), else Go(3).
Turn=4 If Posswin(X) is not 0, then Go(Posswin(X))» [i.e., block opponent's win], else Go(Make2).
Turn=5 If Posswin(X) is not 0 then Go(Posswin(X)) [i.e., win] else if Posswin(O) is not 0, then
Go(Posswin(O)) [i.e., block win], else ifBoard[7] is blank, then Go(7), else Go(3). [Here the
program is trying to make a fork.]
Turn=6 If Posswin(O) is not 0 then Go(Posswin(O)), else if Posswin(X) isnot 0, then
Go(Posswin(X)), else Go(Make2).
Turn=7 If Posswin(X) is not 0 then Go(Posswin(X), else if Posswin(O) isnot 0, then
Go(Posswin(O)), else go anywhere that is blank.
Turn=8 If Posswin(O) is not 0 then Go(Posswin(O)), else if Posswin(X) is not0,then
Go(Posswin(X)), else go anywhere that is blank.
Turn=9 Same as Turn=7
Comments : This program is not quite as efficient in terms of time as the first one since it has to check
several conditions before making each move. But it is a lot more efficient interms of space. It is also a lot
easier to understand the program's strategy or to change the strategy if desired.
Program 2’
This program is identical to Program 2 except for one change in the representationof the board. We
again represent the board as a nine-element vector, but this time weassign board positions to vector
elements as follows:
8 3 4
1 5 9
6 7 2
Notice that this numbering of the board produces a magic square: all the rows, columns, and diagonals
sum to 15. This means that we can simplify the process of checking for a possible win. To check for a
possible win for one player, we consider each pair of squares owned by that player and compute the
difference between 15 and the sum of the two squares. If this difference is not positive or if it is greater
than 9, then the original two squares were not collinear and so can be ignored. Otherwise, if the square
representing the difference is blank, a move there will produce a win. Since no player can have more
than four squares at a time, there will be many fewer squares examined using this scheme than there
were using the more straightforward approach of Program 2. This shows how the choice of
representation can have a major impact on the efficiency of a problem-solving program.
Comments : More easier and efficient approach.
This comparison raises an interesting question about the relationship between the way people solve
problems and the way computers do. Why do people find the row-scan approach easier while the
number-counting approach is more efficient for a computer? We do not know enough about how
people work to answer that question completely. One part of the answer is that people are parallel
processors and can look at several parts of the board at once, whereas the conventional computer must
look at the squares one at a time. Sometimes an investigation of how people solve problems sheds great
light on how computers should do so. At other times, the differences in the hardware of the two seem
so great that different strategies seem best.
7
Program 3
Data Structures
Board A structure containing a nine-element vector representing the board,a list of board
positions that could result from the next move, and anumber representing an estimate
Position of how likely the board position isto lead to an ultimate win for the player to move.
Algorithm :To decide on the next move, look ahead at the board positions that result from
eachpossible move. Decide which position is best (as described below), make the move that leads to
that position, and assign the rating of that best move to the current position. To decide which of a set of
board positions is best, do the following for each of them:
1. See if it is a win. If so, call it the best by giving it the highest possible rating.
2. Otherwise, consider all the moves the opponent could make next. See which of
them is worst for us (by recursively calling this procedure). Assume the opponent
will make that move. Whatever rating that move has, assign it to the node we are
considering.
3. The best node is then the one with the highest rating.
This algorithm will look ahead at various sequences of moves in order to find asequence that leads to
a win. It attempts to maximize the likelihood of winning, whileassuming that the opponent will try to
minimize that likelihood. This algorithm is calledthe minimax procedure, and it is discussed in detail in
later.
Comments: This program will require much more time than either of the others since it must search
a tree representing all possible move sequences before making each move.But it is superior to the
other programs in one very big way: It could be extended to handle gamesmore complicated than tic-
tac-toe, for which the exhaustive enumeration approach ofthe other programs would completely fall
apart. It can also be augmented by a variety ofspecific kinds of knowledge about games and how to play
them..
Answer: The three different approaches or programs used to read in English text
and then answer questions, is discussed below. Consider the following text:
Mary went shopping for a new coat. She found a red one she really liked. When
she got it home, she discovered that it went perfectly with her favorite dress.
The three approaches discussed here will attempt to answer each of the following
questions:
Q1: What did Mary go shopping for?
Q2: What did Mary find that she liked?
Q3: Did Mary buy anything?
8
Program 1: This program attempts to answer questions using the literal input
text. It simply matches text fragments in the questions against the input text.
Data Structures
Question Patterns A set of templates that match common question forms and produce patterns
to be used to match against inputs.
Text The input text stored simply as a long character string.
Question The current question also stored as a character string.
The Algorithm
To answer a question, do the following:
1. Compare each element of Question Patterns against the Question and use all those that match
successfully to generate a set of text patterns.
2. Pass each of these patterns through a substitution process that generates alternative forms of verbs
so that, for example, "go" in a question might match "went" in the text. This step generates a new,
expanded set of text patterns.
3. Apply each of these text patterns to Text, and collect all the resulting answers.
4. Reply with the set of answers just collected.
Example : The template "What did x v" matches this question and generates the text pattern"Mary go
shopping for z." After the pattern-substitution step, this pattern is expanded to a set of patterns
including "Mary goes shopping for z," and "Marywent shopping for z." The latter pattern matches the
input text; the program,using a convention that variables match the longest possible string up to
asentence delimiter (such as a period), assigns z the value, "a new coat," whichis given as the answer.
Comments : This approach is clearly inadequate to answer the kinds of questions people could answer
after reading a simple text. Even its ability to answer the most direct questions isdelicately dependent
on the exact form in which questions are stated and on the variationsthat were anticipated in the design
of the templates and the pattern substitutions thatthe system uses. In fact, the sheer inadequacy of this
program to perform the task maymake you wonder how such an approach could even be proposed. This
program issubstantially farther away from being useful than was the initial program we lookedat for tic-
tac-toe. Is this just a strawman designed to make some other technique lookgood in comparison? In a
way, yes, but it is worth mentioning that the approach thatthis program uses, namely matching
patterns, performing simple text substitutions, andthen forming answers using straightforward
combinations of canned text and sentencefragments located by the matcher, is the same approach that
is used in one of the mostfamous "AI" programs ever written- ELlZA, which we discuss in Section 6.4.3.
But,as you read the rest of this sequence of programs, it should become clear that what we mean by the
term "artificial intelligence" does not include programs such as this exceptby a substantial stretching of
definitions.
Program 2: This program first converts the input text into a structured internal
form that attempts to capture the meaning of the sentences. It also converts
questions into that form. It finds answers by matching structured forms against
each other.
9
Data Structures
EnglishKnow A description of the words, grammar, and appropriate semantic interpretations
of a large enough subset of English to account for theinput texts that the
system will see.
InputText The input text in character form.
StructuredText A structured representation of the content of the input text.
Processing of Text will generate following slot and filler strcuture based
Semantic Representations:
Event1
instance : Finding
tense: Past
agent : Mary
object: Thing 1
Thing 1
instance: Coat
color: Red
Program 3:
This program converts the input text into a structured form that contains the
meanings of the sentences in the text, and then it combines that form with other
structured forms that describe prior knowledge about the objects and situations
involved in the text. It answers questions using this augmented knowledge
structure.
Data Structures
WorldModel A structured representation of background world knowledge. This structure
contains knowledge about objects, actions, and situations that are
described in the input text. This structure is used to construct
10
IntegratedText from the input text. For example, Figure 1 shows an example
of a structure that represents the system's knowledge aboutshopping.
11
Q9. What are the different class of AI programs?
The programs that perform tasks the way people can do can be divided into two
classes:
1. Programs that do not really fit to the definition of an AI task. They are the
problems that a computer could easily solve. Example: Elementary
Perceiver and Memorizer (EPAM).
2. Second Class of programs that attempts to model human performance fall
clearly within the definition of AI tasks. They do thinks that are not trivial
for the computer.
Turing test: Turing in 1950s published an article in the Mind Magazine, which
triggered a controversial topic “Can a Machine Think?” In that article he proposed
a game named imitation game which was later called TURING TEST. The Turing
test, is a test of a machine's ability to exhibit intelligent behavior equivalent to, or
indistinguishable from, that of a human. Turing proposed that a human evaluator
would judge natural language conversations between a human and a machine
designed to generate human-like responses. The evaluator would be aware that
one of the two partners in conversation is a machine, and all participants would
be separated from one another. The conversation would be limited to a text-only
channel such as a computer keyboard and screen so the result would not depend
on the machine's ability to render words as speech. If the evaluator cannot
reliably tell the machine from the human, the machine is said to have passed the
test. The test does not check the ability to give correct answers to questions, only
how closely answers resemble those a human would give.
In this game, we need two persons and a computer. One person is interrogator
who is in separate room from the computer and the other person. The
interrogator asks some questions by typing questions and receives responses the
same way. The interrogator has to determine which of them a person is and
which of them machine. If machine can make fool of interrogator by not
disclosing his actual nature or if interrogator cannot figure out which one of them
is machine and which is human then it can be concluded that the machine can
think.
13
Chapter 2. Problems, Problem Space and Search
Answer : In order to describe the problem of playing chess we must take into the
consideration the following:
• Specify the starting position of the chess board
• The rules that define the legal moves
• Board positions that represent a win for one side or the other
• Make explicit the previously implicit goal of not only playing a legal game of
chess but also winning the games if possible.
Starting position is described as an 8X8 array where each position contains a
symbol standing for the appropriate piece in the official chess opening positions.
14
One Way to represent the rule is
WhilePawnAt
Square (File e, Rank 2) MovePawnFrom
AND Square (File e, Rank 2)
Square (File e , Rank 3) TO
EMPTY Square (File e, Rank 4 )
AND
Square (File e, Rank 4)
EMPTY
15
Answer:
Formal Description of a Problem: In order to provide a formal description of a
problem we must do the following:
a. Define a state space that contains all possible configuration of the relevant
objects
b. Define the initial States
c. Define the Goal /Final States
d. Specify the Rules that describe the action (operators) available.
Examples:
1. The Tic Tac Toe as a State Space Search Representation
a. Configuration of the Board (State Space)
• Board is Vector of 9 squares of 3 X 3 Matrix Form
• Next Move of a Players: X or O
• Board Configuration may change accordingly to each move of the
player
b. Initial State: Board is Empty by X’s Turn
c. Final States: Three X’s in Row / Three O’s in Row / All Cells Full
d. Rules:
• At a time one square can be filled in any direction
• Initial turn is of X
• Out of X and O players who will form the row First will be the
winner
• If No Row is formed but the board is filled the Match is draw.
2. A Water Jug Problem: You are given two jugs a 4 Gallon Jug one and 3
Gallon Jug one. Neither has any measuring marker on it. There is a pump
that can be used to fill the jugs with water. How can you get exactly 2
Gallon of Water into the 4 Gallon Jug?
Solution:
a. State Space: The state space for this problem can be described as the
set of ordered pairs of integers (x, y). Where
• x represents the number of Gallons of water in the 4 Gallon
Jug, such that x = 0,1,2,3 or 4
16
• y represents the quantity of water in the 3 Gallons jug, such
that y = 0, 1, 2 or 3.
b. Initial State: The Start State is (0,0)
c. Goal State: The Final State is (2,n)
d. Rules: The Production rule for the Water Jug Problem is given below:
Gallons in the 4 Gallon Jug Gallons in the 3 Gallon Jug Rule Applied
0 0 Initial State
0 3 2
3 0 9
3 3 2
4 2 7
0 2 5 or 12
2 0 9 or 11
17
3. Travelling Salesman Problem: Enumerate the Global database
for the following TS problem and find the solution. A Salesman
must visit each of five cities ( A,B,C,D and E) as shown in the
Figure a.
The goal is to find the minimum path. The rule is to branch out from a node which
has minimal distance from the root node.
Answer:
a. State Space: All possible tours.
b. Initial State: Any City say A in the above example.
c. Goal State: Finding the Shortest tour connecting all cities.
d. Rules: The Salesman must visit all the given cities once and return to the
original city.
Solution: Let A be selected as the starting node. We can specify the global
database in the form of a graph. The minimal path is A->C->D->E->B->A and cost =
34. Figure b shows the global database for the TSP.
18
Q4. With a neat diagram Explain what is Production
System. Describe all the major components of AI
production system.
Answer : A production system (or production rule system) is a computer
program typically used to provide some form of artificial intelligence, which
consists primarily of a set of rules about behavior. These rules, termed
productions, are a basic representation found useful in automated planning,
expert systems and action selection. A production system provides the
mechanism necessary to execute productions in order to achieve some goal for
the system.
Productions consist of two parts: A sensory precondition (or "IF" statement) and
an action (or "THEN"). If a production's precondition matches the current state of
the world, then the production is said to be triggered. If a production's action is
executed, it is said to have fired. A production system also contains a database,
sometimes called working memory, which maintains data about current state or
knowledge, and a rule interpreter. The rule interpreter must provide a
mechanism for prioritizing productions when more than one is triggered. A
production system control loop until working memory pattern no longer matches
the conditions of any production.
S1→A1
S2→A2
S3→A3
Working Memory S4→A4
Pattern -----------
Pattern → Action
----------
Sn→An
19
A production system consists of rules and factors. Knowledge is encoded in a
declarative form which comprises of a set of rules of the form:
Situation → Action
i. A Global database: The goal database is the central data structure used by an
AI production system. It consists of one or more knowledge databases that
contain whatever information is appropriate for the particular task. Some parts of
the database may be permanent, while others may temporary and only exist
during the solution of the current problem. The information in the databases may
be structured in any appropriate manner.
ii. A set of production rules: A set of production rules, which are of the form
A→B. Each rule consists of left hand side constituent that represent the current
problem state and a right-hand side that represent an output state. A rule is
applicable if its left-hand side matches with the current problem state. A set of
rules of the form Ci → Ai where Ci is the condition part and Ai is the action part.
The condition determines when a given rule is applied, and the action determines
what happens when it is applied.
iv. Rule Applier: A rule applier which is the computational system that
implements the control strategy and applies the rules. A rule applier, which
checks the capability of rule by matching the content state with the left-hand side
of the rule and finds the appropriate rule from database of rules. The important
roles played by production systems include a powerful knowledge representation
scheme. A production system not only represents knowledge but also action. It
20
acts as a bridge between AI and expert systems. Production system provides a
language in which the representation of expert knowledge is very natural. We can
represent knowledge in a production system as a set of rules of the form
If (condition) THEN (condition)
along with a control system and a database. The control system serves as a rule
interpreter and sequencer. The database acts as a context buffer, which records
the conditions evaluated by the rules and information on which the rules act. The
production rules are also known as condition – action, antecedent – consequent,
pattern – action, situation – response, feedback – result pairs.
For example,
If (you have an exam tomorrow)
THEN (study the whole night)
21
Figure below illustrates the relationship between different types of production
systems with example.
Monotonic Non-Monotonic
Answer:
22
Informed (Heuristic) search: Search is guided by an evaluation function:
Generate and Test, Hill Climbing, Best First Search, Problem Reduction,
Constraint Satisfaction and Means End Analysis.
23
performing the search. In general, the problems involving search of exponential
complexity (like chess game) cannot be solved by uninformed methods for the
simple reason, the size of the data being too big. The data structure used for
breadth first search is First in First out (FIFO).
2. Depth First Search:( Expand one of the nodes at the deepest level). In this type
of approach, instead of probing the width, we can explore one branch of a tree
until the solution is found or we decide to terminate the search because either a
dead end is met, some previous state is encountered or the process becomes
longer than the set time limit. If any of the above situations is encountered and
the process is terminated, a backtracking occurs. A fresh search will be done on
some other branch of the tree, and the process will be repeated until goal state is
reached. This type of technique is known as Depth-First Search technique. It
generates the left most successor of root node and expands it, until dead end is
reached. The search proceeds immediately to the deepest level of search tree, or
24
until the goal is encountered. The sequence of explored nodes in the previous
tree will be A, B, E, F, C, G, H, K, L, D, I, J. The search is shown in Fig below:
The DFS has lesser space complexity, because at a time it needs to store only
single path from root to leaf node. The data structure used for DFS is Last-In First-
Out (LIFO).
Depth first search Algorithm
1. If the initial state is a goal state quit and return success
2. Otherwise do the following until success or failure is signaled
a. Generate a successor E of initial State. If there are no successor signal
failure.
b. Call DFS with E as the initial state
c. If success is returned , signal success , otherwise continue in this loop
25
One of the solution tree is
BFS DFS
BFS Stands for “Breadth First DFS stands for “Depth First Search”.
Search”.
BFS starts traversal from the root DFS starts the traversal from the root node
node and then explore the search in and explore the search as far as possible from
the level by level manner i.e. as close the root node i.e. depth wise.
as possible from the root node.
Breadth First Search can be done with Depth First Search can be done with the help
the help of queue i.e. of Stack i.e. LIFO implementations.
FIFO implementation.
This algorithm works in single stage. This algorithm works in two stages – in the
The visited vertices are removed first stage the visited vertices are pushed onto
from the queue and then displayed at the stack and later on when there is no vertex
once. further to visit those are popped-off.
26
BFS is slower than DFS. DFS is more faster than BFS.
BFS requires more memory compare DFS require less memory compare to BFS.
to DFS.
Applications of BFS Applications of DFS
> To find Shortest path > Useful in Cycle detection
> Single Source & All pairs shortest > In Connectivity testing
paths > Finding a path between V and W in the
> In Spanning tree graph.
> In Connectivity > useful in finding spanning trees & forest.
BFS is useful in finding shortest path. DFS in not so useful in finding shortest path. It
BFS can be used to find the shortest is used to perform a traversal of a general
distance between some starting node graph and the idea of DFS is to make a path as
and the remaining nodes of the graph. long as possible, and then go back (backtrack)
to add branches also as long as possible.
Example: Example:
• The breadth first search is not caught in a blind alley. This means that, it will
not follow a single unfruitful path for very long time or forever, before the
path actually terminates in a state that has no successors. In DFS may follow
single unfruitful path for a very long time
• In the situations where solution exists, the breadth first search is guaranteed
to find it. Besides this, in the situations where there are multiple solutions, the
BFS finds the minimal solution. The minimal solution is one that requires the
minimum number of steps. In contrast DFS may find a long path to a solution
in one part of the tree , when a shorter path exists in some other , unexplored
part of the tree.
27
Advantages of Depth First Search (DFS)
1. DFS requires less memory space since only the nodes on the current path
are stored. In BFS all the tree that has so far being generated must be
stored
2. If care is taken in ordering the alternative successor states DFS may find a
solution without examining much of the search space at all. In BFS all parts
of the tree must be examined to level n before any nodes level n+1 can be
examined.
28
Chapter 3: Heuristic Search Techniques
Q1. Explain what is Heuristic. And Give examples for the
problems where heuristic is applied.
Answer: A heuristic technique ( meaning : "find" or "discover" or “ Guide”), often
called simply a heuristic, is any approach to problem solving, learning, or
discovery that employs a practical method not guaranteed to be optimal or
perfect, but sufficient for the immediate goals.
The introduction of ‘Heuristics’ can improve the efficiency of the search process,
probably sacrificing the completeness. The dictionary meaning of term heuristic is
GUIDE. Heuristic works like a tour guide. E.g. imagine that you are lost in a jungle
and you are searching for road which can lead you to a particular city. A tour
guide can guide you by removing so many unwanted roads by providing you
important information so that you can reach your destination more quickly.
2) Problems for which exact solutions are known, but computationally they are
infeasible. E.g. chess and cube game
29
information is also available like distance of the current node and the goal node or
the cost of moving from current node to goal node, which can help the search
procedure to find the goal state more quickly and efficiently that is why this type
of search is also known as informed search.
30
Q4. Give examples for the search algorithms which use
the heuristic functions.
Answer: Following are the search algorithms which use the heuristic functions:
1. Generate and Test
2. Hill Climbing
3. Best First Search
4. Problem Reduction
5. Constraint Satisfaction
6. Mean End Analysis
31
2. Can solution steps be ignored or undone?
32
3. Is the universe predictable?
Way1:
33
Way2:
For the problem of the natural language understanding , the solution is a state of
the world. Consider the problem of finding a consistent interpretation for the
sentence “The bank president ate a dish of pasta salad with the fork “ . There are
several components of this sentence each of which in isolation may have more
than one interpretation. But the component must form a coherent whole and so
they constrain each other interpretation.
Contrast to this with the water jug problem, what we really must report is
not the final state but the path that we found to that state. Thus a
statement of solution to this problem must be a sequence of operation that
produces the final state. This problem solution is path to the state.
34
we get a solution with the help of knowledge base. (Rules for determining the
legal moves).
But when we consider the problem of scanning daily newspaper to decide
which political party will win in upcoming election, it would have to know such
things as
- The name of the candidate of each party
- Major issues/achievement to support party
- Major issues to oppose the party
- And so on –
These two problems Chess and Newspaper story understanding, illustrate the
difference between problems for which a lot of knowledge is important only to
constrain the search for a solution and those for which a lot of knowledge is
important only to constrain the search for a solution and those for which a lot of
knowledge is required even to be able to recognize a solution.
35
Q7. Explain the following Heuristic Search techniques
with algorithms and examples
1. Generate and Test
2. Hill Climbing
3. Best First Search and A* Search
4. Problem Reduction and AO* Search
5. Constraint Satisfaction
6. Means End Analysis
Answer:
1. Generate‐and‐Test: Here the possible solution is generated and the generated
solution is tested by comparing to the set of acceptable goal states. The
correct solution will be considered and incorrect solutions will be rejected. The
working of Generate and test solution is illustrated in the figure below:
36
random form is also known as the British Museum method a reference to a
method for finding an object in the British Museum by wandering randomly.
Example - Traveling Salesman Problem (TSP)
Here Traveler needs to visit n cities. The distance between each pair of cities
are given. The goal is to determine the shortest route that visits all the cities
once. If number of cities is n=80 it will take millions of years to solve
exhaustively!
2.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. Following are the different types of Hill Climbing
algorithm.
1. Simple Hill Climbing
2. Steepest Ascent Hill Climbing
3. Simulated Healing
37
2.1 Simple Hill Climbing: It uses heuristic to move only to states that are better
than the current state. Always moves to better state when possible. The process
ends when all operators have been applied and none of the resulting states are
better than the current state. The simplest way to implement hill climbing is as
follows.
38
2.3 Simulated Annealing: The algorithm is derived based on the behavioural
patterns of metals that changes their state when it is heated to certain
temperature. The algorithm is patterned after the physical process of
annealing, known as Physical annealing in which physical substances are
melted and then gradually cooled until some solid state is reached. The goal
is to produce a minimal-energy state. The rate at which the system is cooled
is called the annealing schedule. If the temperature is lowered sufficiently
slowly, then the goal will be attained.
Note : The algorithm for simulated annealing is only slightly different from the
simple hill climbing procedure . The three differences are :
39
• The annealing schedule must be maintained
• Moves to worse states may be accepted
• It is a good idea to maintain, in addition to the current state the best state
found so far.
Example: The Figure below illustrates the example for Best First Search using OR
Graphs.
40
3.1 A* Search Algorithm:
A* (A star) is the most widely known form of Best-First search. It evaluates
nodes by combining g(n) and h(n).
That is by computing the evaluating function
f(n) = g(n) + h(n) .
– Where
• g(n) = cost so far to reach n
• h(n) = estimated cost from n to goal
f(n) = estimated total cost of path through n to goal
41
The complete A* algorithm, its advantages and disadvantages is given below:
A* Algorithm
1. Start with OPEN holding the initial nodes.
2. Pick the BEST node on OPEN such that
f(n) = g(n) + h(n) is minimal.
3. If BEST is goal node quit and return the path from initial to BEST Otherwise
4. Remove BEST from OPEN and all of BEST's children, labeling each with its
path from initial node.
Advantages
• It is complete and optimal.
• It is the best one from other techniques.
• It is used to solve very complex problems.
• It is optimally efficient, i.e. there is no other optimal algorithm guaranteed
to expand fewer nodes than A*.
Disadvantages
• This algorithm is complete if the branching factor is finite and every action
has fixed cost.
• The speed execution of A* search is highly dependent on the accuracy of
the heuristic algorithm that is used to compute h (n).
• It has complexity problems.
Example for A* Search Techniques: Consider the graph of different cities like S, A,
B, C, D, E, F and G. The objective is to find the optimal path from source S to Goal
City G.
City Straight Line
Distance to Goal City
(h(n))
S 11.5
A 10.1
B 5.8
C 3.4
D 9.2
The Straight line distance, i.e., heuristic value
E 7.1
h(n), from each city to goal city is given in table .
F 3.5
G 0
42
The simulation of each steps of A* algorithm to find the goal is given below:
A*, step 1
A*, step 2
A*, step 3
43
A*, step 4
A*, step 5
A*, step 6
44
4. Problem Reduction:
AndOR Graph :
OR AND
45
4.1 : AO* Algorithm: The AO* algorithm is problem reduction technique which
makes use of AND and OR graph in order to obtain the solution. The AO*
algorithm or Problem Reduction algorithm is given below :
Problem Reduction Algorithm using AndOR Graphs /AO* Algorithm
1. Start with initial node say N
2. Expand the node with all possible successors say Ns1,Ns2,Ns3,---Nsn each
representing the simple sub solutions.
3. Categorize the Successors into AND Node successors and OR Node
Successors.
4. Estimate the Objective function f(N) w.r.t all solvable nodes of OR Node
and AND Node successors.
1. For AND Node f(N)) = [ f(Nsi) + c(N, Nsi) ]
2. For OR Node f(N) = min { f(Nsi) + c(N,Nsi) } where Nsi
represents successor of N
5. Select the optimal successor which have solution .
6. Repeat the Steps from 2 for selected optimal successor until the goal is
reached.
Example: Following are the two examples which illustrate the application of AO*
algorithm for Problem Reduction .
46
Advantages and Disadvantages of AO* Algorithm
Advantages
• It is an optimal algorithm.
• If traverse according to the ordering of nodes.
• It can be used for both OR and AND graph.
Disadvantages
• Sometimes for unsolvable nodes, it can’t find the optimal path.
• Its complexity is more than other algorithms.
47
5. Constraint Satisfaction Problem: A CSP is a problem composed of a finite set
of variables, each of which is associated with a finite domain, and a set of
constraints. CPS is a search procedure that operates in a space of constraint
state. Constraints in the initial state are originally given in the given problem.
Any state is a goal state that has been constrained ‘enough’ where ‘enough’
means that each letter has been assigned a unique numeric value. The solution
process in CSP contains cycles wherein the following things are done on each
cycle:
• Propagate the constraints using rules that correspond to the arithmetic
properties
• Guess a value for some letter whose value is not yet determined.
Example 1:
Cryptarithmetic Problems: The problem is to plot integers from 0 to 9 for the
alphabet specified in the crypt arithmetic problems with following constraints:
1. No two alphabets should have the same integer value.
2. Having allotted the different values for different alphabets we have to
perform the arithmetic operations specified in the problem.
48
Example : Assign numbers to letters so that the sum is correct as illustarted
below :
49
SOLUTION for the Problem SEND+MORE=MONEY
1) SEND + MORE = MONEY
5 4 3 2 1
S E N D
+ M O R E
c3 c2 c1
----------------------
M O N E Y
1. From Column 5, M=1, since it is only carry-over possible from sum of 2 single digit number in
column 4.
2. To produce a carry from column 4 to column 5 'S + M' is atleast 9 so 'S=8 or 9' so 'S + M=9
or 10' & so 'O = 0 or 1'. But 'M=1', so 'O = 0'.
3. If there is carry from Column 3 to 4 then 'E=9' & so 'N=0'. But 'O = 0' so there is no carry &
'S=9' & 'c3=0'.
4. If there is no carry from column 2 to 3 then 'E=N' which is Impossible, therefore there is carry
& 'N=E+1' & 'c2=1'.
5. If there is carry from column 1 to 2 then 'N+R=E mod 10' & 'N=E+1' so 'E+1+R=E mod 10', so
'R=9' but 'S=9', so there must be carry from column 1 to 2. Therefore 'c1=1' & 'R=8'.
6. To produce carry 'c1=1' from column 1 to 2, we must have 'D+E=10+Y' as Y cannot be 0/1 so
D+E is atleast 12. As D is atmost 7 & E is at least 5 (D cannot be 8 or 9 as it is already assigned).
N is atmost 7 & 'N=E+1' so 'E= 5 or 6'.
50
7. If E were 6 & D+E at least 12 then D would be 7, but 'N=E+1' & N would also be 7 which is
impossible. Therefore 'E =5' & 'N =6'.
SOLUTION:
9 5 6 7
+ 1 0 8 5
-----------------
1 0 6 5 2
VALUES:
S = 9 , E = 5 , N = 6 ,D = 7 , M = 1, O = 0,R = 8 , Y = 2
Example2: Map-Coloring
51
6. Means End Analysis: MEA is a technique that was first used in general
problems solver by Newell and Simon. It is a problem-solving method in which the
solution with minimum difference between the current state and the goal state is
determined. The MEA algorithm is given below:
Means-Ends Analysis Algorithm
1. Until the goal is reached or no more procedures are available,
a) Describe the current state, the goal state, and Calculate the difference
between the two.
b) Use the difference, to select a promising procedure.
2. Use the promising procedure and update the current state.
3. If the goal is reached, announce success; otherwise, announce failure.
Example: Consider the Robot Task in which a robot moves a desk with two things
on it from one room to another. The different operator that the Robot can
manipulate are PUSH, CARRY, WALK, PICKUP, PUTDOWN and PLACE. The
preconditions and results of these operators are described in figure below.
The preconditions for the PUSH operator is Robot must be in front of the object,
the object must be large, object must be clear that is no other object must be placed
on the given object and the arm of the robot must be empty or free. The
preconditions for CARRY is that robot and object must be present and the object
52
must be small. The precondition for PICKUP is the robot must be in front of the
object and so on. The objective the means end analysis is to reduce the difference
between the goal state and present state. The difference table used for the above
robot problem is given below:
In order to move a object the robot can select Push or Carry operator. IF the robot
wants to move from one place to another place it can select Move Robot. In order
clear the object the operator selected is Pickup. In order to get object on the other
object Place is used. In order to empty the arm one has to use place operator and
putdown operator.
Suppose that the robot in this domain were given the problem of moving a desk
with two things on it from one room to another. The objects on top must be moved.
The main difference between the start state and the goal state would be the location
of the desk. To reduce this difference either PUSH or carry could be chosen. If
CARRY is chosen first, its precondition must be met. This results in two more
differences that must be reduced: the location of the robot and the size of the desk.
The location of the robot can be handled by applying WALK, but there re no
operators than can change the size of an object. So, this path leads to a dead end.
Following the other branch, we attempt to apply PUSH. Figure below shows the
problem solver’s progress at this point.
It has found a way of doing something useful. But it does not lead to the goal state.
The proper sequence of the operator to be selected is WALK , PICKUP, PUTDOWN,
53
PICKUP , PUTDOWN, PUSH, WALK , PICKUP, PLACE, WALK , PICKUP , PLACE . The
progress of the Means Ends Method. After each step, the difference towards the
goal decreases.
C D
A B
WALK PICKUP PUTDOWN PICKUP PUTDOWN PUSH WALK PICKUP PLACE WALK PICKUP PLACE
START GOAL
The process can be summarized and put in the form of algorithm as given below :
Algorithm: Means-Ends Analysis (CURRENT, GOAL)
1. Compare CURRENT with GOAL. If there are no differences between them then return.
2. Otherwise, select the most important difference and reduce it doing the following until success
or failure is signaled:
a. Select an as yet untried operator O that is applicable to the current difference. If there
are no such operators, then signal failure.
b. Attempt to apply O to CURRENT. Generate descriptions of two states: O-START, a
state in which O's preconditions are satisfied and ORESULT, the state that would result if
O were applied in O-START.
c. If (FIRST-PART <- MEA (CURRENT, O-START)) and (LAST-PART <- MEA (O-
RESULT, GOAL)) are successful, then signal success and return the result of
concatenating FIRST-PART,O, and LAST-PART.
Q8. What are the Problems With hill climbing? What are
the possible solutions?
Answer: The problems with hill climbing techniques are :
1. Local maximum, or the foothill problem: there is a peak, but it is lower
than the highest peak in the whole space.
2. The plateau problem: all local moves are equally unpromising, and all
peaks seem far away.
3. The ridge problem: almost every move takes us down.
The above problems are illustrated in the figure below:
54
Solutions to Problem
• Backtrack to some earlier node and try going in a different direction
• Make a big jump in some direction to try to get to a new section of the
search space.
• Apply two or more rules before doing the test. This corresponds to moving
in several directions at once.
55