You are on page 1of 115

Test 2 portions

BEST-FIRST SEARCH
• A combination of depth first and breadth first searches.
• Depth first is good because a solution can be found without computing all nodes
and breadth first is good because it does not get trapped in dead ends.
• The best first search allows us to switch between paths thus gaining the benefit
of both approaches.
• At each step the most promising node by applying Heuristic function is chosen
and branch is explored.
• If one of the nodes chosen generates nodes that are less promising it is possible
to choose another at the same level and in effect the search changes from depth
to breadth.
• If there is no node better than this previously unexpanded node and branch is
not forgotten and the search method reverts back to the unexpanded node.
To implement graph structure we use list of nodes-
• OPEN – Nodes have been generated and have had the heuristic
function applied, and have not yet examined .
• It is Priority queue with elements of highest priority ( most promising
nodes value of heuristic function ).
• CLOSED- Nodes that have already been examined .
• If we use Search Graph rather Search Tree , we need to check whether
it has been generated before.
Example:
Consider the below search problem, and we will traverse it using greedy best-first search. At each iteration, each
node is expanded using evaluation function f(n)=h(n) , which is given in the below table.
• We start from source "S" and search for goal "I" using given costs and Best
First search.

Priority Queue pq initially contains S


• We remove s from and process unvisited neighbors of S to pq.
• pq now contains {A, C, B} (C is put before B because C has lesser cost)

We remove A from pq and process unvisited neighbors of A to pq.


• pq now contains {C, B, E, D}
We remove C from pq and process unvisited
• Neighbors of C to pq.
• pq now contains {B, H, E, D}

We remove B from pq and process unvisited


• Neighbors of B to pq.
• pq now contains {H, E, D, F, G}

We remove H from pq. Since our goal


• "I" is a neighbor of H, we return.
Expand the nodes of S and put in the CLOSED list

• Initialization: Open [A, B], Closed [S]

• Iteration 1: Open [A], Closed [S, B]

• Iteration 2: Open [E, F, A], Closed [S, B]


• : Open [E, A], Closed [S, B, F]

• Iteration 3: Open [I, G, E, A], Closed [S, B, F]


• : Open [I, E, A], Closed [S, B, F, G]

• Hence the final solution path will be: S----> B----->F----> G


• Expand the nodes of S and put in the CLOSED list

• Initialization: Open [A, B], Closed [S]

• Iteration 1: Open [A], Closed [S, B]

• Iteration 2: Open [E, F, A], Closed [S, B]


• : Open [E, A], Closed [S, B, F]

• Iteration 3: Open [I, G, E, A], Closed [S, B, F]


• : Open [I, E, A], Closed [S, B, F, G]

• Hence the final solution path will be: S----> B----->F----> G


Advantages:
Best first search can switch between BFS and DFS by gaining the
advantages of both the algorithms.
This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
It can behave as an unguided depth-first search in the worst case
scenario.
It can get stuck in a loop as DFS.
This algorithm is not optimal.
THE A* ALGORITHM
• To approximate the shortest path in real-life situations, like- in maps, games.
• A* Search algorithm is one of the best and popular technique used in path-
finding and graph traversals.
• A* Algo is guaranteed to find an optimal path to a goal state, hence it is called
admissible.
• A* Search Algorithm does is that at each step it picks the node according to a
value-‘f’ which is a parameter equal to the sum of two other parameters – ‘g’ and
‘h’.
• f(n)=g(n)+h(n)

g = Actual cost from the starting node to node n.

h = the estimated cost to move from n to the goal node. It


is referred to as the heuristic Value.
A* Search
• A* search is the most commonly known form of best-first search. It uses
heuristic function h(n), and cost to reach the node n from the start state
g(n).

• A* search algorithm finds the shortest path through the search space
using the heuristic function. This search algorithm expands less search
tree and provides optimal result faster.

• A* algorithm is except that it uses g(n)+h(n) instead of g(n).


• In A* search algorithm, we use search heuristic as well as the cost to
reach the node. Hence we can combine both costs as following, and this
sum is called as a fitness number.

• At each point in the search space, only those node is expanded which
have the lowest value of f(n), and the algorithm terminates when the
goal node is found.
Algorithm of A* search:
• Step1: Place the starting node in the OPEN list.

• Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stop.

• Step 3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if
node n is goal node then return success and stop, otherwise

• Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each
successor n', check whether n' is already in the OPEN or CLOSED list, if not then compute evaluation
function for n' and place into Open list.

• Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the back pointer
which reflects the lowest g(n') value.

• Step 6: Return to Step 2.


ALGORITHM STEPS

Point to them yet .


City Straight Line City Straight Line City Straight Line
Distance Distance Distance

C1 380 C8 244 C15 80

C2 374 C9 100 C16 151

C3 366 C10 241 C17 161

C4 253 C11 242 C18 199

C5 176 C12 160 C19 226

C6 329 C13 0 C20 234

C7 193 c14 77
Example :The heuristic value of all states is given in the below table so we will calculate the f(n) of each state using the formula f(n)= g(n) + h(n),
where g(n) is the cost to reach any node from start state.
Here we will use OPEN and CLOSED list.
• Initialization: {(S, 5)}

• Iteration1: {(S--> A, 4), (S-->G, 10)}

• Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}

• Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}

• Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with cost 6.

• Points to remember:

• A* algorithm returns the path which occurred first, and it does not search for all remaining paths.
• The efficiency of A* algorithm depends on the quality of heuristic.
• A* algorithm expands all nodes which satisfy the condition f(n)
PROBLEM REDUCTION
AND-OR GRAPHS
• Is useful for representing the solution of problems that can be solved
by decomposing them into a set of smaller problem, all of which must
be solved .
Search strategies for OR graphs through which we want to find a single path
to a goal.
In an OR graph each of its branch represents an alternative problem solving
path.
PROBLEM REDUCTION:
So far we have considered search strategies for OR graphs through which we
want to find a single path to a goal. Such structure represent the fact that
we know how to get from a node to a goal state if we can discover how to
get from that node to a goal state along any one of the branches leaving it.
AND-OR GRAPHS
The AND-OR GRAPH (or tree) is useful for representing the solution of problems that can solved by decomposing them into a set
of smaller problems, all of which must then be solved. This decomposition, or reduction, generates arcs that we call AND arcs.
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.
Just as in an OR graph, several arcs may emerge from a single node, indicating a variety of ways in which the original problem
might be solved. This is why the structure is called not simply an AND-graph but rather an AND-OR graph (which also happens to
be an AND-OR tree)
• OR node represents a choice between possible decomposition.
• AND node represents a given decomposition.
AND – OR GRAPH
Heuristic Function
• h(n ) is estimating the cost of solving the subproblem at node n .
• The main of AND-OR GRAPH is find the a minimum cost solution tree.
THE AO* ALGORITHM
ALGORITHM STEPS
1.
2.
4.
Means-Ends Analysis in Artificial Intelligence
We have studied the strategies which can reason either in forward or
backward, but a mixture of the two directions is appropriate for solving a
complex and large problem.
Such a mixed strategy, make it possible that first to solve the major part of
a problem and then go back and solve the small problems arise during
combining the big parts of the problem. Such a technique is called Means-
Ends Analysis.
Means end analysis (MEA) is an important concept in artificial intelligence
(AI) because it enhances problem resolution. MEA solves problems by
defining the goal and establishing the right action plan. This technique is
used in AI programs to limit search.
• It is a mixture of Backward and forward search technique.
• The MEA technique was first introduced in 1961 by Allen Newell, and
Herbert A. Simon in their problem-solving computer program, which was
named as General Problem Solver (GPS).
• The MEA analysis process centered on the evaluation of the difference
between the current state and goal state.
Means end analysis uses the following processes to achieve its objectives:

1. First, the system evaluates the current state to establish whether


there is a problem. If a problem is identified, then it means that an action
should be taken to correct it.
2. The second step involves defining the target or desired goal that
needs to be achieved.
3. The target goal is split into sub-goals, that are further split into
other smaller goals.
4. This step involves establishing the actions or operations that will be
carried out to achieve the end state.
5. In this step, all the sub-goals are linked with corresponding
executable actions (operations).
6. After that is done, intermediate steps are undertaken to solve the
problems in the current state. The chosen operators will be applied to
reduce the differences between the current state and the end state.
7. This step involves tracking all the changes made to the actual state.
Changes are made until the target state is achieved.
• If operator does not produces exactly the goal state then we have a
Second Sub-problem of getting from the state.
• If the differences was chosen correctly and if the operator is effective
at reducing the difference , then the two sub-problems should be easier
to solve than the original problem.
Principle of Means-End Analysis:
• “It allows us to solve parts of a problem first and then go back and solve
the smaller problems that arise while assembling the final solution”.

• Technique: It is based on the use of the operations which transform the


state of the world. MEA works on three primary goals:
• i. Transformation
• ii. Reduction
• iii. Application
How means-ends analysis Works:
The means-ends analysis process can be applied recursively for a problem. It
is a strategy to control search in problem-solving. Following are the main
Steps which describes the working of MEA technique for solving a problem.

1. First, evaluate the difference between Initial State and final


State.
2. Select the various operators which can be applied for each
difference.
3. Apply the operator at each difference, which reduces the
difference between the current state and goal state.
ALGORITHM
Step 1: Compare CURRENT to GOAL, if there are no differences between both then return Success and
Exit.
Step 2: Else, select the most significant difference and reduce it by doing the following steps until the
success or failure occurs.
Select a new operator O which is applicable for the current difference, and if there is no such
operator, then signal failure.
Attempt to apply operator O to CURRENT. Make a description of two states.
i) O-Start, a state in which O?s preconditions are satisfied.
ii) O-Result, the state that would result if O were applied in O-start.
If
(First-Part <------ MEA (CURRENT, O-START)
And
(LAST-Part <----- MEA (O-Result, GOAL), are successful, then signal Success and return the
result of combining FIRST-PART, O, and LAST-PART.
1

Solution:
To solve the above problem, we will first find the differences between initial states and goal
states, and for each difference, we will generate a new state and will apply the operators.
The operators we have for this problem are:

Move
Delete
Expand
1. Evaluating the initial state: In the first step, we will evaluate the initial state and will compare the
initial and Goal state to find the differences between both states.

2.
Applying Delete operator: As we can check the first difference is that in goal state there is no dot symbol
which is present in the initial state, so, first we will apply the Delete operator to remove this dot.
3. Applying Move Operator: After applying the Delete operator, the new state occurs which we will again
compare with goal state. After comparing these states, there is another difference that is the square is
outside the circle, so, we will apply the Move Operator.

4. Applying Expand Operator: Now a new state is generated in the third step, and we will compare this
state with the goal state. After comparing the states there is still one difference which is the size of the
square, so, we will apply Expand operator, and finally, it will generate the goal state.
END OF UNIT2
Unit 3
Unit 3
Knowledge Representation: Representations and Mappings,
Approaches to knowledge representation, representational adequacy,
Inferential adequacy, inferential efficiency, acquisition efficiency,
Issues in knowledge representation.
Predicate logic: Representing simple facts in logic, Representing
instance and ISA relationships, Computable functions and predicates,
resolution, the basis of resolution, unification algorithm.
Knowledge Representation
• Knowledge representation and reasoning is the area of artificial
intelligence concerned with how knowledge can be represented
Symbolically and manipulated in automated way by reasoning program.

• KR – refers to the data structure techniques and organizing notations


that are used in AI. These include Semantic Nets, Frames, Logic,
Production Systems and Conceptual Graphs.

• It is a part of AI that is concerned with thinking , and how thinking


contributes to intelligence behavior.

• Knowledge representation is the key area of artificial intelligence that


deals with the problem of representing, maintaining, and manipulating
knowledge about an application domain.

• Since AI systems have to deal with this problem, Knowledge


representation is one of the central Sub-field of Artificial Intelligence.
• Complex problems
Large amount of data and
manipulation of data
• Structuring of knowledge deals with Two different
kinds of entities
Facts – Truths in some real world
Representation of facts in some chosen
formalism, easy to manipulate
• Two levels of Structuring entities
Knowledge level- Facts are described
Symbol level – representation of objects at the
knowledge level are defined in terms of symbols which
can be manipulated by programs
• The facts and representations are linked with two-way
mappings. This link is called representation mappings.
• The forward representation mapping maps from facts
to representations.
• The backward representation mapping goes the other
way, from representations to facts.
• One common representation is natural language
(particularly English) sentences.
• Regardless of the representation for facts we use in a
program , we may also need to be concerned with an
English representation of those facts in order to
facilitate getting information into and out of the
system. We need mapping functions from English
sentences to the representation we actually use and
from it back to sentences.
Mapping functions from English sentences to representations
• A Knowledge Representation Language is defined by
two aspects:
• Syntax : The syntax of a language defines which
configurations of the components of the language
constitute valid sentences.
• Semantics: The semantics defines which facts in the
world the sentences refer to, and hence the
statement about the world that each sentence makes.
Logical Representation of the fact

ꓯx : dog(x)→mammal(x)

Then using deductive mechanism or reasoning

Then using backward mapping function


1. Ramu is a parrot
Parrot(Ramu)
2. All parrots are birds
ꓯx : parrot(x) →bird(x)
3. All parrots have red beaks
ꓯx : parrot(x)->hasredbeak(x)

Now using deductive reasoning


hasredbeak(Ramu)
Ramu has a red beak

bird(Ramu)
Ramu is a bird
1. Every Representation Corresponds to only one Fact- Backward Mapping

2. There Is at-least one representation for every fact – Forward Mapping

Representation of Facts

Facts to Representation Representation to Facts


Properties of Knowledge Representation
• Representational Adequacy
A major property of a knowledge representation system is that it
is adequate and can make an AI system understand, i.e., represent all
the knowledge required by it to deal with a particular field or domain.
• Inferential Adequacy
The knowledge representation system is flexible enough to deal
with the present knowledge to make way for newly possessed
knowledge.
• Inferential Efficiency
The representation system cannot accommodate new
knowledge in the presence of the old knowledge, but it can add this
knowledge efficiently and in a seamless manner.
• Acquisitional Efficiency
The final property of the knowledge representation system will
be its ability to gain new knowledge automatically, helping the AI to
add to its current knowledge and consequently become increasingly
smarter and productive.
Issues in Knowledge Representation

The main objective of knowledge representation is


to draw the conclusions from the knowledge, but
there are many issues associated with the use of
knowledge representation techniques.
4) Representing Sets of objects:

It is important to be able to represent the sets of objects for several reasons.


One is that there are some properties that are true for sets that are not true
for individual members.

Example: Consider the assertion made in the sentences:


"There are more sheep than people in Australia", and "English speakers can
be found all over the world."

These facts can be described by including an assertion to the sets


representing people, sheep, and English.
Hindi speaking people are found all over India.
Assertions to sets representing people, Hindi speakers

No single Hindi speaking person is found in India

large(elephant)----------can assert elephants are large


5) Finding the right structure as needed
To describe a particular situation, it is always important to find the access of right
structure. This can be done by selecting an initial structure and then revising the
choice.

Consider a script(a description of class of events in terms of contexts,


participants and sub-events)
Raman went to an Art gallery. He selected a beautiful painting, paid the money
and left the gallery with the painting.
The answer to the query “Did he buy a painting ?”…………….is………..YES

While having access to the right structure, it is necessary to solve following


problem statements. They include the process on how to:

Select an initial appropriate structure.


• Perform an initial selection of the most appropriate structure
• Determine a better structure if the initially selected structure is not
appropriate to fulfill other conditions.
• Find the solution if none of the available structures is appropriate.
• Create and remember a new structure for the given condition.

You might also like