AI Unit-L
AI Unit-L
Artificial Intelligence
UNIT-I
✓ It is huge.
✓ It is constantly varying.
✓ It differs from data by being organized in a way that corresponds to its application.
✓ It is complicated.
Technique is a method that exploits knowledge that should be represented in such a way:
The knowledge acquires generalization. Situations that share common properties are grouped together.
✓ It can be easily modified to correct errors and to reflect changes in the world.
✓ It can be used in many situations even though it may not be totally accurate.
✓ Problem definition, that include precise specifications of what initial situation will be as what final
acceptable solutions to the problem.
✓ Problem Analysis, this can have immense impact on the appropriateness of possible techniques for solving
the problem.
To solve the problem of playing a game,we require the rules of the game and targets for wining
as well as representing positions in the game.The opening position can be defined as initial state and a winning
position as a goal state. Moves from initial state to other states leading to the goal state follow legally.
A State space represents a problem in terms of states and operators that change states. It consists of:
✓ A set of operators that can change one state into another state.
✓ An initial state.
✓ A set of final states.This set is often represented by a program that detects terminal states.
EG: Water jug Problem
3) What is Production System? Explain about search problem characteristics and production system
characteristics?
✓ It is used to implement search algorithms and replicate human problem solving skills.
✓ This problem solving knowledge is encoded in the system in the form of productions.It consists of
2components: Rule and Action.
✓ Rule recognize the condition and the actions part has the knowledge of how to deal with the condition.
Problem Characteristics: A problem may have different aspects of representation and explanation.It is
necessary to analyze the problem along several key dimensions: Some of the key features of a problem are
given below.
✓ Is the problem decomposable into set of sub problems? Can the solution step be ignored or undone?
✓ Is a good solution to the problem obvious without comparison to all the possible solutions?
✓ Will the solution of the problem required interaction between the computer and the person?
Simplicity: Due to the use of IF-THEN structure each sentence is unique in the production system.
Modularity: The knowledge available is coded in discrete pieces by the production system,which makes it easy
to add,modify or delete the information without any side effects.
Modifiability: This feature allows for the modification of the production rules.
Knowledge intensive: The system only stores knowledge.This type of representation sovles the semantic
problems.
Control/search strategies: Control strategies in AI is a technique tells about which rule has to be applied
next while searching for the solution of a problem within problem space.
➢ It helps to decide which rule has to apply next without getting any stuck at any point.
Control strategy should cause motion:- Each rule applied should cause the motion because if there will be no
motion than such control strategy will never lead to a solution.
Control Strategy should be systematic: Though the strategy applied should create the motion but if do not
follow some systematic strategy than we are likely to reach the same state number of times before reaching the
solution which increases the number of steps.Control strategy should be systematic implies a need for global
and local motion
◆ Breadth-First search: It searches along with the breadth and follows first-in - first-out queue data structure
approach.It will start to scan node A first and then B-C-D-E-F-G
Algorithm:
Step3: If the FRONT node of the queue is a goal node then stop and return success.
Step4: Remove the FRONT node from the queue. Process it and find all its neighbours that are in ready state
then place them inside the queue in any order.
Step5: Go to step3.
Step6: Exit
Advantages:
✓ BFS will never get trapped in a blind alley,which means unwanted nodes.
✓ If there is more than one solution then it will find a solution with minimal steps.
Disadvantages:
✓ Memory constraints as it stores all the nodes of the present level to go for the next level.
◆ Depth first search: It searches along the depth and follows the stack approach.The sequence for scanning
nodes will be A-B-D-E-C-F,it scans all the sub-nodes of parent nodes and then moves to another node.
Step3: If the top node of the stack is the goal node,then stop and return success.
Step4: Else POP the top node from the stack and process it .Find all its neighbour
that are in ready state and PUSH them into the stack in any order.
Step5: Go to step3
Step6: Exit
Advantages:
Disadvantages:
Applications:
✓ Topological sorting.
Heuristic search: A Heuristic is a technique to solve a problem faster than classic methods,or to find
approximate solution when classic methods cannot.
✓ A heuristic takes a look at search algorithm .At each branching step,it evaluates the available information
and makes a decision on which branch to follow.
✓ It is a function that when applied to a state returns value as estimated merit of state,with respect to goal
✓ Heuristic evaluation functions estimated likelihood of given state leading to goal state and also estimates
cost from current state to goal.
Generate-And-Test Algorithm
Generate-and-test search algorithm is a very simple algorithm that guarantees to find a solution if
done systematically and there exists a solution.
Algorithm: Generate-And-Test
While generating complete solutions and generating random solutions are the two extremes there exists
another approach that lies in between. The approach is that the search process proceeds systematically but some
paths that unlikely to lead the solution are not considered. This evaluation is performed by a heuristic
function.Depth-first search tree with backtracking can be used to implement systematic generate-and-test
procedure.
Hill climbing: Hill Climbing is heuristic search used for mathematical optimization problems in the
field of Artificial Intelligence . Hill climbing is widely used when a good heuristic is available.It is a
local search algorithm that continuously moves in the direction of increasing value to find the best
solution to the problem.It is also called greedy local search as it only looks to its good immediate
neighbour state and not beyond that.
➢ Produce and Test variation: Hill climbing is the variation of the Generate and Test strategy.
➢ Use of Greedy Approach: Hill climbing calculation search moves toward the path which improves the
expense.
➢ No Backtracking: It doesn’t backtrack the space as it doesn’t recall the past state.
✓ Simple Hill Climbing: It examines the neighboring nodes one by one and selects the first
Step 1 : Evaluate the initial state. If it is a goal state then stop and return success. Otherwise,
Step 2 : Loop until the solution state is found or there are no new operators present which can be applied to
current state.
a) Select a state that has not been yet applied to the current state and apply it to produce a new
state.
i. If the current state is a goal state, then stop and return success.
ii. If it is better than the current state, then make it current state and proceed further.
iii. If it is not better than the current state, then continue in the loop until a solution is found.
Step 3 : Exit
✓ Steepest-Ascent Hill climbing : It first examines all the neighboring nodes and then
Step 1 : Evaluate the initial state. If it is goal state then exit else make the current state as initial
state
Step 2 : Repeat these steps until a solution is found or current state does not change
i. Let ‘target’ be a state such that any successor of the current state will be better than it;
c. if this state is goal state then quit else compare with ‘target’
Step 3 : Exit
✓ Stochastic hill climbing : It does not examine all the neighboring nodes before deciding
which node to select .It just selects a neighboring node at random, and decides whether to move to that
neighbor or to examine another.It is also an area search algorithm,it modifies one solution and searches the
relatively local area of search space until the local optima is found.
✓ Simulated Annealing Heuristic Search: It is an algorithm that never makes a move towards lower esteem
destined to be incomplete that it can stall out on a nearby extreme.Annealing in metallurgy and material
science is the process used to harden metals and glass by heating them to a high temperature and then
gradually cooling them,thus allowing the material to reach a low energy state.
If better than current state go there otherwise go there with some probability.
Variation of hill climbing downhill moves may be made.The probability that the metal will jump to a
higher energy level is given by
Where k is a constant known as Boltzmann's constant.δE is to change in the value of the objective function
Local Maximum: At a local maximum all neighboring states have a values which is worse than than the
current state. Since hill climbing uses greedy approach, it will not move to the worse state and terminate
itself. The process will end even though a better solution may exist.
Plateau : On plateau all neighbors have same value . Hence, it is not possible to select the
best direction.
Ridge : Any point on a ridge can look like peak because movement in all possible
directions is downward. Hence the algorithm stops when it reaches this state
Best - first Search: In BFS and DFS, when we are at a node, we can consider any of the adjacent as next
node. So both BFS and DFS blindly explore paths without considering any cost function. The idea of Best First
Search is to use an evaluation function to decide which adjacent is most promising and then explore. Best First
Search falls under the category of Heuristic Search or Informed Search.
Algorithm: Step 1: Place the starting node or root node into the queue.
Step 3: If the first element of the queue is our goal node, then stop and return success.
Step 4: Else, remove the first element from the queue. Expand it and compute the estimated goal
distance for each child. Place the children in the queue in ascending order to the goal
distance.
Step 5: Go to step-3
Step 6: Exit.
Implementation:
Step 1:
Consider the node A as our root node. So the first element of the queue is A which is not our goal node,
so remove it from the queue and find its neighbour that are to inserted in ascending order.
|A|
Step 2:
The neighbours of A are B and C. They will be inserted into the queue in ascending order.
|B| C| A|
Step 3:
Now B is on the FRONT end of the queue. So calculate the neighbours of B that are maintaining a least
|F| E| D| C| B
Step 4:
Now the node F is on the FRONT end of the queue. But as it has no further children, so remove it from
|E |D| C| F
Step 5:
Now E is the FRONT end. So the children of E are J and K. Insert them into the queue in ascending order.
|K| J| D| C| E
Step 6:
Now K is on the FRONT end and as it has no further children, so remove it and proceed further
|J| D| C| K
Step7:
|D| C| J
Step 8:
Now D is on the FRONT end and calculates the children of D and put it into the queue.
|I| C| D
Step9:
Now I is the FRONT node and it has no children. So proceed further after removing this node from the
queue.
|C| I
Step 10:
Now C is the FRONT node .So calculate the neighbours of C that are to be inserted in ascending order
|G| H| C
Step 11:
Now remove G from the queue and calculate its neighbour that is to insert in ascending order into the
queue.
|M| L| H| G
Step12:
Now M is the FRONT node of the queue which is our goal node. So stop here and exit.
|L|H| M
Advantage:
✓ It is more efficient than that of BFS and DFS.
✓ Time complexity of Best first search is much less than Breadth first search.
✓ The Best first search allows us to switch between paths by gaining the benefits of both breadth first and depth first search.
Because, depth first is good because a solution can be found without computing all nodes and Breadth first search is good
because it does not get trapped in dead ends.
Disadvantages:
Sometimes, it covers more distance than our consideration.
A* search is the most commonly form of best-first search.It uses the heuristic function h(n) and cost to
reach the node n from the start stage g(n).It finds the shortest path through the search using the heuristic
function.This search algorithm expands fewer search tree and gives optimal results faster.
Algorithm of A* Search :
Step 1: Place the starting node into OPEN and find its f (n) value.
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 the evaluation function (g+h).If node n is
the goal node ,then return success and stop otherwise,
Step 4: Expand node n and generate all 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 the evaluation function for ‘n’ and place it into
the OPEN list.
Step 5: Else,if the node ‘n’ is already in OPEN and CLOSED then it should be attached to the back pointer which
reflects the lowest g(n) value.
We already know about the divide and conquer strategy, a solution to a problem can be obtained by
decomposing it into smaller sub-problems. Each of this sub-problem can then be solved to get its sub-solution.
These sub-solutions can then be recombined to get a solution as a whole. That is called Problem Reduction.
This method generates arc which is called as AND arcs. One AND arc may point to any number of successor
nodes, all of which must be solved for an arc to point to a solution.
The Depth first search and Breadth first search given earlier for OR trees or graphs can be easily
adopted by AND-OR graph. The main difference lies in the way termination conditions are determined, since
all goals following an AND nodes must be realized; where as a single goal node following an OR node will do.
So for this purpose we are using AO* algorithm.
Algorithm:
Step 3: Select a node n that is both on OPEN and a member of T0. Remove it from OPEN and
place it in CLOSE.
Step 4: If n is the terminal goal node then leveled n as solved and leveled all the ancestors of n
as solved. If the starting node is marked as solved then success and exit.
Step 5: If n is not a solvable node, then mark n as unsolvable. If starting node is marked as
Step 6: Expand n. Find all its successors and find their h (n) value, push them into OPEN.
Step 8: Exit.
( d ) Constraint satisfaction?
Many problems in AI can be considered as problems of constraint satisfaction, in which the goal
state satisfies a given set of constraint. constraint satisfaction problems can be solved by using any of the search
strategies. The general form of the constraint satisfaction procedure is as follows:
Until a complete solution is found or until all paths have led to lead ends, do
1. select an unexpanded node of the search graph.
2. Apply the constraint inference rules to the selected node to generate all possible new constraints.
3. If the set of constraints contains a contradiction, then report that this path is a dead end.
5. If neither a constraint nor a complete solution has been found then apply the rules to generate new partial
solutions. Insert these partial solutions into the search graph.
SEND
+ MORE
----------
MONEY
Assign decimal digit to each of the letters in such a way that the answer to the problem is correct to the same
letter occurs more than once , it must be assign the same digit each time . no two different letters may be
assigned the same digit. Consider the crypt arithmetic problem.
CONSTRAINTS:-
4. Assumption can be made at various levels such that they do not contradict each other.
5. The problem can be decomposed into secured constraints. A constraint satisfaction approach may be used.
Most of the search strategies either reason forward of backward however, often a mixture of the
two directions is appropriate. Such mixed strategy would make it possible to solve the major parts of problem
first and solve the smaller problems the arise when combining them together. Such a technique is called "Means
- Ends Analysis".
✓ First evaluate the difference between Initial state and final state.
✓ Select the various operators which can be applied for each difference.
✓ Apply the operator at each difference,which reduces the difference between the current and goal state.
➢ Compare CURRENT to GOAL,If there is no difference between both then return success and exit.
➢ Else,select the most significant difference and reduce it by doing the following steps until the success or
failure occurs.
(a) Select a new operator O which is applicable for the current difference and if there is no such opeartor
then signal failure.
(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 combining FIRST-PART,O,LAST PART