Muhanned Ansari AI Assignment 5
Muhanned Ansari AI Assignment 5
Assignment
Question 4
4.1)Consider the following joint probability distribution of X and
Y shown in Table 4.1.
Find:
(a) P(X=1, Y=2)
(b)P(X=0, 1≤Y<3)
(c) Find the marginal probability function for X and Y
(d)Give the conditional probability function for X given Y=1
(e) Are X and Y independent?
Ans :
4.1)
(a) P(x=1 y=2) = 1/12
(b) (b)P(X=0, 1≤Y<3) = 1/6+1/12
2/12+1/12
= 3/12
= ¼ =0.25
(c) marginal probability condition of x =
(x=0) = 1/12+1/6+1/12=0.33
(x=1)= 1/12+1/6+1/12=0.33
(x=2) =1/6+1/12+0=0.25
(x=3)= 1/12+0+0=0.083
marginal probability condition of y =
(y=0)= 1/12+1/12+1/6+1/12=0.41
(y=1) = 1/6+1/6+1/12+0=0.41
( y=2) =1/12+1/12+0+0=0.16
(d) conditional probability of X given Y=1
(x=0 | y=1) = P(x=0, y=1)/P(y=1)
= 1/6/5/12
= 1/6 *12/5=2/5= 0.4
(x=1|y=1) = P(x=1,y=1)/P(y=1)
= 1/6/5/12
= 1/6*12/5
= 2/5 =0.4
(x=2|y=1)
= P(x=2,y=1)/P(y=1)
= 1/12/5/12
=1/12*12/5
= 1/5 = 0.2
(x=3|y=1)
= P(x=3,y=1)/P(y=1)
= 0/5/12
= 0*12/5=0
e) P(Y)= 1/12+1/12+1/6+1/12=5/12
P(Y)=1/6+1/6+1/12+0=5/12
P(Y)=1/12+1/12+0+0=1/6
5/12+5/12+1/6=1
P(X)=1/12+1/6+1/12=2/6=1/3
P(X)= 1/12+1/6+1/12=1/3
P(X)=1/6+1/12+0=3/12=1/4
P(X)=1/12
2/3+1/4+1/12=1
In order for ,X and Y to be independent
P(X,Y)= P(X) x P(Y)
Here P(X,Y) is not equal to P(X) x P(Y) , that is LHS is not equal to
RHS for the cases (X=2,Y=0), (X=3,Y=0) and so on, therefore they
are dependant.
4.2)
A) P(X=true | Y=true)=0.2
B) P(X=false | Y=true)=0.4
C) . P(Y=false | X=true)=0.3
A state space graph is shown in Figure 5.1. S is the start state and J is
the goal state. Develop a computer code [in any language] to solve
this search problem using the Breadth First Search (BFS) method.
Ans:
Screenshot
Code:
from collections import deque
class Graph:
def __init__(self):
self.graph = {}
if current_node == goal:
print(f"\nGoal node {goal} reached.")
return
graph_obj = Graph()
graph_obj.add_edge('S', ['A', 'B', 'C'])
graph_obj.add_edge('A', ['D'])
graph_obj.add_edge('B', ['E'])
graph_obj.add_edge('C', ['F', 'J'])
graph_obj.add_edge('D', ['G'])
graph_obj.add_edge('E', ['I', 'J'])
graph_obj.add_edge('I', [])
graph_obj.add_edge('J', [])
graph_obj.add_edge('F', ['S'])
graph_obj.add_edge('G', ['H'])
graph_obj.add_edge('H', ['D'])
start_node = 'S'
goal_node = 'J'
print(f"BFS starting from node {start_node} to reach goal node {goal_node}:")
bfs(graph_obj.graph, start_node, goal_node)