0% found this document useful (0 votes)
2 views37 pages

AI - Lab - Manual - C-Scheme Jan 2025

The document outlines a series of experiments conducted in the Department of Computer Engineering at Shivajirao S Jondhale College of Engineering, focusing on various artificial intelligence concepts such as AI applications, the Wumpus world problem, and search algorithms including BFS, DFS, and A*. Each experiment includes aims, theoretical background, procedures, and conclusions, emphasizing the understanding and implementation of AI techniques.

Uploaded by

Akshata Jondhale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views37 pages

AI - Lab - Manual - C-Scheme Jan 2025

The document outlines a series of experiments conducted in the Department of Computer Engineering at Shivajirao S Jondhale College of Engineering, focusing on various artificial intelligence concepts such as AI applications, the Wumpus world problem, and search algorithms including BFS, DFS, and A*. Each experiment includes aims, theoretical background, procedures, and conclusions, emphasizing the understanding and implementation of AI techniques.

Uploaded by

Akshata Jondhale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Shivajirao S Jondhale College of Engineering, Dombivli (E)

Department of Computer Engineering

Experiment Number: 1

Aim:

One case study on AI applications publication in IEEE/ACM/Springer or any


prominent journal.

Theory:

Students can find the research papers based on the artificial neural network,
hybrid systems, genetic algorithm, fuzzy system, fuzzy logic, fuzzy inference
system etc. Students should write technology used, algorithm and survey.
Students need to search recent papers on any of the above mentioned topics,
study it and prepare report on the same

Conclusion:
Thus, we have understood the recent advancements and applications of
various sub-domains of Artificial Intelligence

AI Lab/ VI 1
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 2

Aim:

Assignment on State space formulation and PEAS representation for Wumpus


world Problem. And implement wumpus world problem

Theory:
Note: Also describe task environment properties for wumpus world
problem
The Wumpus world is a cave which has 4/4 rooms connected with
passageways. So there are total 16 rooms which are connected with each other.
We have a knowledge-based agent who will go forward in this world. The
cave has a room with a beast which is called Wumpus, who eats anyone who
enters the room. The Wumpus can be shot by the agent, but the agent has a
single arrow. In the Wumpus world, there are some Pits rooms which are
bottomless, and if agent falls in Pits, then he will be stuck there forever. The
exciting thing with this cave is that in one room there is a possibility of finding
a heap of gold. So the agent goal is to find the gold and climb out the cave
without fallen into Pits or eaten by Wumpus. The agent will get a reward if he
comes out with gold, and he will get a penalty if eaten by Wumpus or falls in
the pit.

Following is a sample diagram for representing the Wumpus world. It


is showing some rooms with Pits, one room with Wumpus and one agent at (1,
1) square location of the world.

AI Lab/ VI 2
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Fig.2.1 Initial state

Procedure:

PEAS description of Wumpus world:

To explain the Wumpus world we have given PEAS description as below:

Performance measure:

o +1000 reward points if the agent comes out of the cave with the gold.
o -1000 points penalty for being eaten by the Wumpus or falling into the
pit.
o -1 for each action, and -10 for using an arrow.
o The game ends if either agent dies or came out of the cave.

Environment:

o A 4*4 grid of rooms.


o The agent initially in room square [1, 1], facing toward the right.
o Location of Wumpus and gold are chosen randomly except the first
square [1,1].
o Each square of the cave can be a pit with probability 0.2 except the
first square.

AI Lab/ VI 3
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Actuators:

o Left turn,
o Right turn
o Move forward
o Grab
o Release
o Shoot.

Sensors:

o The agent will perceive the stench if he is in the room adjacent to the
Wumpus. (Not diagonally).
o The agent will perceive breeze if he is in the room directly adjacent to
the Pit.
o The agent will perceive the glitter in the room where the gold is
present.
o The agent will perceive the bump if he walks into a wall.
o When the Wumpus is shot, it emits a horrible scream which can be
perceived anywhere in the cave.
o These percepts can be represented as five element list, in which we
will have different indicators for each sensor.
o Example if agent perceives stench, breeze, but no glitter, no bump, and
no scream then it can be represented as:
[Stench, Breeze, None, None, None].

The Wumpus world Properties:

o Partially observable: The Wumpus world is partially observable


because the agent can only perceive the close environment such as an
adjacent room.

AI Lab/ VI 4
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

o Deterministic: It is deterministic, as the result and outcome of the


world are already known.
o Sequential: The order is important, so it is sequential.
o Static: It is static as Wumpus and Pits are not moving.
o Discrete: The environment is discrete.
o One agent: The environment is a single agent as we have one agent
only and Wumpus is not considered as an agent.

Exploring the Wumpus world:

Now we will explore the Wumpus world and will determine how the agent
will find its goal by applying logical reasoning.

Agent's First step:

Initially, the agent is in the first room or on the square [1,1], and we already
know that this room is safe for the agent, so to represent on the below diagram
(a) that room is safe we will add symbol OK. Symbol A is used to represent
agent, symbol B for the breeze, G for Glitter or gold, V for the visited room, P
for pits, W for Wumpus.

At Room [1,1] agent does not feel any breeze or any Stench which means the
adjacent squares are also OK.

AI Lab/ VI 5
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Fig 2.2 1st step

Agent's second Step:

Now agent needs to move forward, so it will either move to [1, 2], or [2,1].
Let's suppose agent moves to the room [2, 1], at this room agent perceives
some breeze which means Pit is around this room. The pit can be in [3, 1], or
[2,2], so we will add symbol P? to say that, is this Pit room?

Now agent will stop and think and will not make any harmful move. The agent
will go back to the [1, 1] room. The room [1,1], and [2,1] are visited by the
agent, so we will use symbol V to represent the visited squares.

Agent's third step:

At the third step, now agent will move to the room [1,2] which is OK. In the
room [1,2] agent perceives a stench which means there must be a Wumpus
nearby. But Wumpus cannot be in the room [1,1] as by rules of the game, and
also not in [2,2] (Agent had not detected any stench when he was at [2,1]).
Therefore agent infers that Wumpus is in the room [1,3], and in current state,

AI Lab/ VI 6
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

there is no breeze which means in [2,2] there is no Pit and no Wumpus. So it is


safe, and we will mark it OK, and the agent moves further in [2,2].

Fig 2.3 2nd step

Agent's fourth step:

At room [2,2], here no stench and no breezes present so let's suppose agent
decides to move to [2,3]. At room [2,3] agent perceives glitter, so it should
grab the gold and climb out of the cave.

Program:

Output:

Conclusion: Thus, we have studied PEAS representation for Wumpus world


Problem.

AI Lab/ VI 7
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 3

Aim:

WAP for BFS algorithm using uninformed search method.

Theory:

For exploring and navigating different problem domains, the Breadth-First


Search (BFS) algorithm is an essential tool in artificial intelligence. Tasks like
pathfinding, network routing, and puzzle solving are resolved by BFS by
methodically navigating graph or tree structures. In this article, the
fundamental ideas of BFS, its algorithms, and real-world AI applications are
examined.

A traversal technique called the Breadth-First Search looks through a tree or


graph data structure to find a property that has to be satisfied. Because it just
considers node connection and does not favor one path over another based on
heuristic knowledge or domain-specific information, it falls under the category
of blind or ignorant search AI algorithms. It just includes the structure of the
search space and no further information. For unweighted graphs, it works best,
and it works best when the cost of each action is the same. Even unlimited
state spaces can be efficiently explored by BFS because of its methodical
search approach.

Characteristics of BFS:

1. First-in-First-Out (FIFO): In BFS, the FIFO queue is usually favored


as it is quicker than a priority queue and frequently produces the right
node order. New nodes farther down the search tree are added to the
rear of the queue when FIFO is used with BFS. First to be enlarged are
the older nodes that are more powerful than the new ones.
2. Early goal test: The method preserves a collection of states attained
during the search process in conventional BFS implementations.

AI Lab/ VI 8
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

However, it simply retains the set of attained states that permit an early
goal test, rather than saving all obtained states. As soon as the newly
created node is formed, this test verifies that it satisfies the objective
requirements.
3. Cost-optimal: When BFS creates nodes at a given depth d, it has
previously examined and created every node at the previous depth d-1.
It always seeks to find a solution with the lowest cost, giving priority
to the shortest path. As a result, BFS can find a solution as soon as it
reaches a certain depth level in a search area. BFS is therefore seen as
a cost-effective approach.

* Note: Solve one example based on Breadth first search

Performance Comparison:

 Completeness: yes, it gives shallowest goal

 Optimality: yes, provided path cost is non- decreasing

 Time complexity: O(b ͩ + ¹)

 Space complexity: O(b ͩ + ¹)

Algorithm:

1. Create single member queue comprising of root node.

2. If 1st Member of Queue is GOAL then goto Step 5.

3. If first member of queue is not GOAL then remove it and add to


CLOSE or Visited Queue. Consider its Children/ successor, if any
add them from BACK/REAR [FIFO]

4. If queue is not empty then goto Step 2, If queue is empty then goto
Step 6

5. Print “SUCCESS” and stop.

6. Print “FALIURE” and stop


AI Lab/ VI 9
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Program:

Output:

Conclusion: Thus, the program of Breadth first search has been executed
successfully.
.

AI Lab/ VI 10
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 4

Aim:

WAP for DFS algorithm using uninformed search method.

Theory:

The effectiveness and optimization of depth-first search in artificial


intelligence are enhanced. DFS has a significant impact on AI system
optimization, from algorithmic insights to practical applications. Let's examine
DFS's foundational principles, its role in artificial intelligence, and its real-
world uses.

A traversal approach called depth-first search is used to data structures that


resemble trees and graphs. Usually, it begins by investigating the frontier's
deepest node. The method begins at the root node and searches all the way
down the search tree until it reaches nodes that have no successors. The search
retraces to the next deepest node to investigate alternate routes if the node with
unexpanded successors is found.

Characteristics of DFS:

1. Since DFS cannot ensure that the shortest pathways will be found, it is
not cost-optimal.
2. DFS tracks visited nodes using a straightforward principle: it employs
a stack to record nodes visited thus far, which aids with graph
backtracking. The DFS adds a new node to the stack in order to
investigate its neighbors. It backtracks, for example, by popping nodes
off the stack to investigate alternate routes, if it encounters a node with
no successors (leaf node).
3. Backtracking search: Compared to the conventional depth-first search,
this DFS variation utilizes less memory. The backtracking search
allows the DFS to create only one successor at a time instead of all the

AI Lab/ VI 11
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

successors. By changing the current state description directly rather


than allocating the RAM to a new state, this method enables dynamic
state change, such as creating successors. Consequently, less memory
is needed to hold a single state description and action sequence.

*Note: Solve One example based on DFS

Performance Analysis: Depth-first search visits every vertex once and checks
every edge in the graph once. Therefore, DFS complexity is O(V + E)O(V+E).
This assumes that the graph is represented as an adjacency list.

Algorithm:

1. If the initial state is a goal state, quit and return success.


2. Otherwise, loop until success or failure is signalled.
A] Generate a state, say E, and let it be the successor of the initial
state.If there is no successor, signal failure.

B] Call Depth-First Search with E as the initial state.

C] If success is returned, signal success. Otherwise continue in this

Loop.

Program:

Output:

Conclusion: Thus, the program of Depth first search has been executed
successfully.

AI Lab/ VI 12
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 5

Aim:

WAP for A* algorithm using informed search method.

Theory:

An informed search strategy-one that uses problem-specific


knowledge-can find solutions more efficiently. Akey component of these
algorithms is a heuristic function h(n)
h(n)= estimated cost of the cheapest path from node n to a goal node.
Admissible /heuristic never over estimated i.e. h(n)≤ Actual cost. For
example, Distance between two nodes(cities)=> straight line distance and
for 8-puzzel problem- Admissible heuristic can be number of misplaced tiles
h(n)= 8.

A* Search technique
It is informed search technique. It uses additional information beyond
problem formulation and tree. Search is based on Evaluation function
f(n).Evaluation function is based on both heuristic function h(n) and g(n).
f(n)=g(n) + h(n)
It uses two queues for its implementation: open, close Queue. Open queue is
a priority queue which is arranged in ascending order of f(n).

Heuristic Function in A* Algorithm


The heuristic employed has a significant impact on the A* algorithm's
efficacy. The algorithm's efficiency and performance can be significantly
impacted by the heuristic selection. A good heuristic is one that minimizes
the number of nodes explored by the algorithm in order to help it locate the
shortest path. A heuristic's characteristics include:
 Admissibility: If a heuristic never overestimates the expense of

AI Lab/ VI 13
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

achieving the objective, it is acceptable. The straight-line distance on


a spatial map is the quintessential illustration of an acceptable
heuristic.
 Consistency (or Monotonicity): If the projected cost from the current
node to the objective is consistently less than or equal to the step
cost from the current node to the next node plus the anticipated cost
from any neighboring node, then the heuristic is considered
consistent.

Algorithm:
1. Create a single member queue comprising of Root node
2. If FIRST member of queue is goal then goto step 5
3. If first member of queue is not goal then remove it from
queue and add to close queue.
4. Consider its children if any, and add them to queue in
ascending order of evaluation function f(n).
5. If queue is not empty then goto step 2.
6. If queue is empty then goto step 6
7. Print ‘success’ and stop
8. Print ‘failure’ and stop.
Performance Comparison:
 Completeness: yes
 Optimality: yes
Limitation:
 It generate same node again and again
 Large Memory is required

AI Lab/ VI 14
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Fig.5.1. Example of A*
OPEN/FRINGE CLOSE
[A] [ ]
[C,B] [A]
[D,B,E,A] [A,C]
[F,E,B,C,A] [A,C,D]
[G,E,B,C,A,D] [A,C,D,F]
SUCCESS

Node A:
f(B)=g(B) + h(B)=3+5=8
f(C) =g(C) + h(C)=1 + 6=7
Node C:
f(A) = g(A) + h(A)=2+7=10
f(D) = g(D) + h(D)=3+4=7
f(E) = g(E) + h(E)=7+1=8
Node D:
f(F) = g(F) + h(F)=6+1=7
f(C) = g(C) + h(C)= 5+6=11
f(B) = g(B) + h(B)=4+5=9

AI Lab/ VI 15
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Node F:
f(E) = g(E) + h(E)=7+1=8
f(D) = g(D) + h(D)= 9+4=13
f(G) = g(G) + h(G)=7+0=7

Final path: A  C  DF  G


Total cost= 7
Program:

Output:

Conclusion: Thus, the program of A*algorithm has been executed


successfully

AI Lab/ VI 16
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 6

Aim:

WAP for Tic-Tac-Toe using game playing algorithm.

Theory:
The min-max algorithm computes the min-max decision from the
current state. It uses a simple recursive computation of the min-max values of
each successor state, directly implementing the defining equations. The
recursion process all the way down to the leaves of the tree, and then the min-
max values are backed up through the tree as the recursion unwinds.
The min-max algorithm performs a complete depth-first exploration of the
game tree. If the maximum depth of the tree is m, and there are b legal moves
at each point, then the time complexity of the min-max algorithm is O(bm).
The space complexity is O(bm) for an algorithm that generates all successors
at once, or O(m) for an algorithm that generates successors one at a time. For
real games, of course, the time cost is totally impractical, but this algorithm
serves as the basis for the mathematical analysis of games and for more
practical algorithms.

Algorithm:
function MINIMAX-DECISION(state)returns an action
inputs: state, current state in game
v  MAX-VALUE(state)
return the action in SUCCESSORS(state) v

function MAX-VALUE(state)returns a utility value


if TERMINAL-TEST(state) then return UTILITY(state)
v  -infinity
for a, s in SUCCESSORS(state)do
v  MAX(V, MIN-VALUE(S))
AI Lab/ VI 17
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

return v

function MIN-VALUE
if TERMINAL-TEST(state) then return UTILITY(state)
V infinity
for a , s in SUCCESSORS(state)do
v  MIN(V, MAX-VALUE(S))
return v

Fig.6.1. Tic-Tac-Toe

Program:

Output:

Conclusion: Thus, the program for Tic-Tac-Toe game has been executed
successfully

AI Lab/ VI 18
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 7

Aim:

WAP for Water Jug Problem in Prolog.

Theory:
This is the jug problem using simple depth-first search of a graph. The
modified water-jug problem is as follows: Jug A holds 4 liters, and jug B
holds 3 liters. There is a pump, which can be used to fill either Jug. How
can you get exactly 2 liters of water into the 4-liter jug?
Assumptions:
 We can fill a jug from the pump
 We can pour water out of the jug onto the ground
 We can pour water from one jug to another
 There are no other measuring devices available

To solve the water jug problem, apart from problem statement we also need a
control structure that loops through a simple cycle in which some rule whose
left side matches the current state is chosen, the appropriate change to state is
made as described in corresponding right side and the resulting state is
checked to see if it corresponds to a goal state. As long as it does not the cycle
continues.
* Note: Solve water jug problem

Algorithm:

Rules for water jug problem

AI Lab/ VI 19
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Table 7.1. Rules


Rule Current New state Rules
state
(x, y) (4,y) Fill the 4-gallon jug.
1 if x<4
2 (x, y) (x,3) Fill the 3-gallon jug.
if y<3
3 (x, y) (x-d, y) Pour some water out of 4-gallon
if x>0 jug.
4 (x, y) (x, y-d) Pour some water out of 3-gallon
if y>0 jug.
5 (x, y) (0, y) Empty the 4-gallon jug on
if x>0 ground.
6 (x, y) (x, 0) Empty the 3-gallon jug on
if y>0 ground.
7 (x, y) (4,y-(4-x)) Pour water from 3-gallon jug
if into the 4-gallon jug until the 4-
(x+y)>=4 gallon jug is full.
&(y>0)
8 if (x-(3-y),3) Pour water from 4-gallon jug
(x+y)>=3 into the 3-gallon jug until the 3-
&(x>0) gallon jug is full.
9 (x, y) (x+y,0) Pour all the water from 3-gallon
if jug into the 4-gallon jug.
(x+y)<=4
&(y>0)
10 (x, y)if (0,x+y) Pour all the water from 4-gallon
(x+y)<=3 jug into the 3-gallon jug.
&(x>0)

AI Lab/ VI 20
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

11 (0,2) (2,0) Pour the 2 gallons from the 3-


gallon jug into the 4-gallon jug.
12 (2,y) (0,y) Empty 2 gallons in the 4-gallon
jug on the ground.

Program:

Output:

Conclusion: Thus, the program of water jug problem has been executed
successfully.

AI Lab/ VI 21
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 8

Aim:

WAP for Block world Problem using planning agent.

Theory:

Fig. 8.1.Block word Problem


What is Blocks World Problem?

This is how the problem goes — There is a table on which some blocks are
placed. Some blocks may or may not be stacked on other blocks. We have a
robot arm to pick up or put down the blocks. The robot arm can move only
one block at a time, and no other block should be stacked on top of the block
which is to be moved by the robot arm.
Our aim is to change the configuration of the blocks from the Initial State to
the Goal State, both of which have been specified in the diagram above.

What is Goal Stack Planning?


Goal Stack Planning is one of the earliest methods in artificial intelligence in
which we work backwards from the goal state to the initial state.
We start at the goal state and we try fulfilling the preconditions required to
achieve the initial state. These preconditions in turn have their own set of
preconditions, which are required to be satisfied first. We keep solving these
AI Lab/ VI 22
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

“goals” and “sub-goals” until we finally arrive at the Initial State. We make
use of a stack to hold these goals that need to be fulfilled as well the
actions that we need to perform for the same.

Apart from the “Initial State” and the “Goal State”, we maintain a “World
State” configuration as well. Goal Stack uses this world state to work its way
from Goal State to Initial State. World State on the other hand starts off as the
Initial State and ends up being transformed into the Goal state.
At the end of this algorithm we are left with an empty stack and a set of
actions which helps us navigate from the Initial State to the World State.

Representing the configurations as a list of “predicates”


Predicates can be thought of as a statement which helps us convey the
information about a configuration in Blocks World.
Given below are the list of predicates as well as their intended meaning
1. ON(A,B) : Block A is on B
2. ONTABLE(A) : A is on table
3. CLEAR(A) : Nothing is on top of A
4. HOLDING(A) : Arm is holding A.
5. ARMEMPTY : Arm is holding nothing
Using these predicates, we represent the Initial State and the Goal State in our
example like this:
Initial State — ON(B,A) ∧ ONTABLE(A) ∧ ONTABLE(C) ∧
ONTABLE(D) ∧ CLEAR(B) ∧ CLEAR(C) ∧ CLEAR(D) ∧ ARMEMPTY

AI Lab/ VI 23
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Fig 8.2 Initial State


Goal State — ON(C,A) ∧ ON(B,D) ∧ ONTABLE(A) ∧ ONTABLE(D) ∧
CLEAR(B) ∧ CLEAR(C) ∧ ARMEMPTY

Fig 8.3 Goal State


Thus a configuration can be thought of as a list of predicates describing the
current scenario.
“Operations” performed by the robot arm
The Robot Arm can perform 4 operations:
1. STACK(X,Y) : Stacking Block X on Block Y
2. UNSTACK(X,Y) : Picking up Block X which is on top of Block Y
3. PICKUP(X) : Picking up Block X which is on top of the table
4. PUTDOWN(X) : Put Block X on the table

AI Lab/ VI 24
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

All the four operations have certain preconditions which need to be satisfied to
perform the same. These preconditions are represented in the form of
predicates.
The effect of these operations is represented using two
lists ADD and DELETE. DELETE List contains the predicates which will
cease to be true once the operation is performed. ADD List on the other hand
contains the predicates which will become true once the operation is
performed.
The Precondition, Add and Delete List for each operation is rather intuitive
and have been listed below.
Table 8.1 Operations

Operations performed by the Robot Arm


For example, to perform the STACK(X,Y) operation i.e. to Stack Block X on
top of Block Y, No other block should be on top of Y (CLEAR(Y)) and the
Robot Arm should be holding the Block X (HOLDING(X)).
Once the operation is performed, these predicates will cease to be true, thus
they are included in DELETE List as well. (Note : It is not necessary for the
Precondition and DELETE List to be the exact same).
On the other hand, once the operation is performed, The robot arm will be free
(ARMEMPTY) and the block X will be on top of Y (ON(X,Y)).
AI Lab/ VI 25
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Program:

Output:

Conclusion: Thus, the program for Block world problem has been executed
successfully.

AI Lab/ VI 26
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 9

Aim:

Study of Bayes Belief Network

Theory:
Bayesian belief network is key computer technology for dealing with
probabilistic events and to solve a problem which has uncertainty. We can
define a Bayesian network as:
"A Bayesian network is a probabilistic graphical model which represents a set
of variables and their conditional dependencies using a directed acyclic
graph."
It is also called a Bayes network, belief network, decision network,
or Bayesian model. Bayesian networks are probabilistic, because these
networks are built from a probability distribution, and also use probability
theory for prediction and anomaly detection.
Real world applications are probabilistic in nature, and to represent the
relationship between multiple events, we need a Bayesian network. It can also
be used in various tasks including prediction, anomaly detection, diagnostics,
automated insight, reasoning, time series prediction, and decision making
under uncertainty.
Bayesian Network can be used for building models from data and
experts opinions, and it consists of two parts: Directed Acyclic Graph and
Table of conditional probabilities.
The generalized form of Bayesian network that represents and solve
decision problems under uncertain knowledge is known as an Influence
diagram.

A Bayesian network graph is made up of nodes and Arcs (directed links),


where:

AI Lab/ VI 27
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Fig 9.1 Graph


o Each node corresponds to the random variables, and a variable can
be continuous or discrete.
o Arc or directed arrows represent the causal relationship or
conditional probabilities between random variables. These directed
links or arrows connect the pair of nodes in the graph.
These links represent that one node directly influence the other node,
and if there is no directed link that means that nodes are independent
with each other
o In the above diagram, A, B, C, and D are random variables
represented by the nodes of the network graph.
o If we are considering node B, which is connected with node
A by a directed arrow, then node A is called the parent of
Node B.
o Node C is independent of node A.

The Bayesian network has mainly two components:


o Causal Component
o Actual numbers

AI Lab/ VI 28
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Each node in the Bayesian network has condition probability


distribution P(Xi |Parent(Xi) ), which determines the effect of the parent on
that node.
Bayesian network is based on Joint probability distribution and conditional
probability. So let's first understand the joint probability distribution:
Joint probability distribution:
If we have variables x1, x2, x3,....., xn, then the probabilities of a different
combination of x1, x2, x3.. xn, are known as Joint probability distribution.

P[x1, x2, x3,....., xn], it can be written as the following way in terms of the joint
probability distribution.
 P[x1| x2, x3,....., xn]P[x2, x3,....., xn]
 P[x1| x2, x3,....., xn]P[x2|x3,....., xn]....P[xn-1|xn]P[xn].
In general for each variable Xi, we can write the equation as:
P(Xi|Xi-1,........., X1) = P(Xi |Parents(Xi ))

Conclusion: Thus, we have studied Belief networks.

AI Lab/ VI 29
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Experiment Number: 10

Aim:

WAP for Forward chaining and Backward chaining algorithm.


Theory:
Forward Chaining:
Forward chaining is also known as a forward deduction or forward
reasoning method when using an inference engine. Forward chaining is a form
of reasoning which start with atomic sentences in the knowledge base and
applies inference rules (Modus Ponens) in the forward direction to extract
more data until a goal is reached.

The Forward-chaining algorithm starts from known facts, triggers all


rules whose premises are satisfied, and add their conclusion to the known
facts. This process repeats until the problem is solved.

Properties of Forward-Chaining:

1. It is a down-up approach, as it moves from bottom to top.


2. It is a process of making a conclusion based on known facts or data, by
starting from the initial state and reaches the goal state.
3. Forward-chaining approach is also called as data-driven as we reach to
the goal using available data.
4. Forward -chaining approach is commonly used in the expert system,
such as CLIPS, business, and production rule systems.

Example:

"As per the law, it is a crime for an American to sell weapons to hostile
nations. Country A, an enemy of America, has some missiles, and all the
missiles were sold to it by Robert, who is an American citizen."

AI Lab/ VI 30
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Prove that "Robert is criminal."

To solve the above problem, first, we will convert all the above facts into first-
order definite clauses, and then we will use a forward-chaining algorithm to
reach the goal.

Facts Conversion into FOL:

o It is a crime for an American to sell weapons to hostile nations. (Let's


say p, q, and r are variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) →
Criminal(p) ...(1)

o Country A has some missiles. ?p Owns(A, p) ∧ Missile(p). It can be


written in two definite clauses by using Existential Instantiation,
introducing new Constant T1.
Owns(A, T1) ......(2)
Missile(T1) .......(3)

o All of the missiles were sold to country A by Robert.


?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)

o Missiles are weapons.


Missile(p) → Weapons (p) .......(5)

o Enemy of America is known as hostile.


Enemy(p, America) →Hostile(p) ........(6)

o Country A is an enemy of America.


Enemy (A, America) .........(7)

o Robert is American
American(Robert). ..........(8)

AI Lab/ VI 31
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Proof:

Step-1:

In the first step we will start with the known facts and will choose the
sentences which do not have implications, such as: American(Robert),
Enemy(A, America), Owns(A, T1), and Missile(T1). All these facts will be
represented as below.

Step-2:

At the second step, we will see those facts which infer from available facts and
with satisfied premises.

Rule-(1) does not satisfy premises, so it will not be added in the first iteration.

Rule-(2) and (3) are already added.

Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is


added, which infers from the conjunction of Rule (2) and (3).

Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and


which infers from Rule-(7).

Step-3:

AI Lab/ VI 32
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

At step-3, as we can check Rule-(1) is satisfied with the


substitution {p/Robert, q/T1, r/A}, so we can add Criminal(Robert) which
infers all the available facts. And hence we reached our goal statement.

Hence it is proved that Robert is Criminal using forward chaining


approach.

Backward Chaining:

Backward-chaining is also known as a backward deduction or backward


reasoning method when using an inference engine. A backward chaining
algorithm is a form of reasoning, which starts with the goal and works
backward, chaining through rules to find known facts that support the goal.

Properties of backward chaining:

o It is known as a top-down approach.

o Backward-chaining is based on modus ponens inference rule.

o In backward chaining, the goal is broken into sub-goal or sub-goals to


prove the facts true.

AI Lab/ VI 33
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

o It is called a goal-driven approach, as a list of goals decides which


rules are selected and used.

o Backward -chaining algorithm is used in game theory, automated


theorem proving tools, inference engines, proof assistants, and various
AI applications.

o The backward-chaining method mostly used a depth-first


search strategy for proof.

Example:

In backward-chaining, we will use the same above example, and will rewrite
all the rules.

o American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) →


Criminal(p) ...(1)
Owns(A, T1) ........(2)

o Missile(T1)

o ?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)

o Missile(p) → Weapons (p) .......(5)

o Enemy(p, America) →Hostile(p) ........(6)

o Enemy (A, America) .........(7)

o American(Robert). ..........(8)

Proofs:

In Backward chaining, we will start with our goal predicate, which


is Criminal(Robert), and then infer further rules.

Step-1:

AI Lab/ VI 34
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

At the first step, we will take the goal fact. And from the goal fact, we will
infer other facts, and at last, we will prove those facts true. So our goal fact is
"Robert is Criminal," so following is the predicate of it.

Step-2:

At the second step, we will infer other facts form goal fact which satisfies the
rules. So as we can see in Rule-1, the goal predicate Criminal (Robert) is
present with substitution {Robert/P}. So we will add all the conjunctive facts
below the first level and will replace p with Robert.

Here we can see American (Robert) is a fact, so it is proved here.

Step-3:t At step-3, we will extract further fact Missile(q) which infer from
Weapon(q), as it satisfies Rule-(5). Weapon (q) is also true with the
substitution of a constant T1 at q.

AI Lab/ VI 35
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Step-4:

At step-4, we can infer facts Missile(T1) and Owns(A, T1) form Sells(Robert,
T1, r) which satisfies the Rule- 4, with the substitution of A in place of r. So
these two statements are proved here.

AI Lab/ VI 36
Shivajirao S Jondhale College of Engineering, Dombivli (E)
Department of Computer Engineering

Step-5:

At step-5, we can infer the fact Enemy(A, America) from Hostile(A) which
satisfies Rule- 6. And hence all the statements are proved true using backward
chaining.

Conclusion: Thus, the program for Forward Chaining and Backward Chaining
has been executed successfully.

AI Lab/ VI 37

You might also like