Introduction Uncertainty appears when an agent is not completely sure about the outcome of the decisions it has made. This happens where t...
Introduction
Uncertainty appears when an agent is not completely sure about the outcome of the decisions it has made. This happens where the conditions fall into contradiction. In terms of Artificial Intelligence, an agent faces uncertainty while making a decision when it perceives the environment. In this report, we will see how Bayesian Network helps an agent to overcome uncertainty. Now, what is Bayesian Network? It’s a data structure that represents probabilistic relations and dependencies among random variables. Following properties are found in Bayesian Networks:
- Networks are directed graphs.
- Each node on the graph represents a random variable.
- An arrow from X to Y represents that X is a parent of Y. That is, the probability distribution of Y depends on the value of X.
- Each node X has probability distribution P (X | Parents(X)).
This report is a part of the Artificial Intelligence course
Lab-work under supervision of Nuruzzaman Faruqui, Lecturer of City University,
Bangladesh. This course offers students various up-to-date AI topics. Students
get to explore the real applicable approaches through AI. From this course, the student acquires better knowledge of the functionality of AI and how AI is
making our daily life easier. This is the best Artificial Intelligence course
in Bangladesh.
Problem Statement
Let’s
say, Mr. X has an appointment to attend. To reach there Mr. X has to travel on
a train. Now his chances of not being able to attend the appointment are uncertain. And this could vary on random variables, for instance, Rain,
Maintenance (of the train), Train (arrival of the train). So, we will use these
variables to build a model and reduce the uncertainty as much as possible.

Fig: Bayesian network model
Proposed Solution
Let’s try to understand the above model.
Rain is a root node. What it means is, no other probability distributions are
depending on it. The numbers are
arbitrarily given for the sake of understanding and implementing on python.
These are probability distributions, so obviously total sum would be 1.
|
none |
light |
heavy |
|
0.7 |
0.2 |
0.1 |
Maintenance from our model depends on root node Rain.
{yes, no} defines whether there will be maintenance on a train track.
|
R |
yes |
no |
|
none |
0.4 |
0.6 |
|
light |
0.2 |
0.8 |
|
heavy |
0.1 |
0.9 |
|
R |
M |
on time |
delayed |
|
none |
yes |
0.8 |
0.2 |
|
none |
no |
0.9 |
0.1 |
|
light |
yes |
0.6 |
0.4 |
|
light |
no |
0.7 |
0.3 |
|
heavy |
yes |
0.4 |
0.6 |
|
heavy |
no |
0.5 |
0.5 |
The final is an Appointment from our mode.
which is solely dependent on its parent node Train. Though Train has dependencies
with other variables. However, the Appointment variable only focuses on its parent
node.
|
T |
attend |
miss |
|
on time |
0.9 |
0.1 |
|
delayed |
0.6 |
0.4 |
#pomegranate is a
python package which implement fast and extremely flexoble probablilistic
models
#rannging from probability distribution to Bayesian network
from pomegranate import *
# Rain node has no parent
rain = Node(DiscreteDistribution({
"none": 0.7,
"light": 0.2,
"heavy": 0.1
}), name="rain")
# Track maintenance node is conditional on rain
maintenance = Node(ConditionalProbabilityTable([
["none", "yes", 0.4],
["none", "no", 0.6],
["light", "yes", 0.2],
["light", "no", 0.8],
["heavy", "yes", 0.1],
["heavy", "no", 0.9]
], [rain.distribution]), name="maintenance")
# Train node is conditional on rain and maintenance
train = Node(ConditionalProbabilityTable([
["none", "yes", "on
time", 0.8],
["none", "yes", "delayed", 0.2],
["none", "no", "on
time", 0.9],
["none", "no", "delayed", 0.1],
["light", "yes", "on
time", 0.6],
["light", "yes", "delayed", 0.4],
["light", "no", "on
time", 0.7],
["light", "no", "delayed", 0.3],
["heavy", "yes", "on
time", 0.4],
["heavy", "yes", "delayed", 0.6],
["heavy", "no", "on
time", 0.5],
["heavy", "no", "delayed", 0.5],
], [rain.distribution, maintenance.distribution]), name="train")
# Appointment node is conditional on train
appointment = Node(ConditionalProbabilityTable([
["on time", "attend", 0.9],
["on time", "miss", 0.1],
["delayed", "attend", 0.6],
["delayed", "miss", 0.4]
], [train.distribution]), name="appointment")
# Create a Bayesian Network and add states
model1 = BayesianNetwork()
model1.add_states(rain, maintenance, train, appointment)
# Add edges connecting nodes
model1.add_edge(rain, maintenance)
model1.add_edge(rain, train)
model1.add_edge(maintenance, train)
model1.add_edge(train, appointment)
# Finalize model
model1.bake()
By using this model, we can predict if
Mr. X can attend his appointment on some given conditions. Let’s try that in Python.
# Calculate the probability for a given observation
reds_probability = model1.probability([["heavy", "yes", "delayed", "attend"]])
print(reds_probability)
Result
By using the above model, we can also infer the probability
distribution for all variables given some specific evidence. The example we
have used above, if we say, the train was delayed, we can infer the probability
distribution of the variables Rain, Maintenance, and Appointment.
from
model import model1
#Calculate predictions (probabilities of differnet variable)
#predict_proba= probability based on Baysian Network
predictions = model1.predict_proba({
"train" : "delayed"
})
#print(predictions)
#train delayed is given..inferred based on the output
#Print predictions for each node
#zip=look into the model in ordered pair
for node, prediction in
zip(model1.states,predictions):
if
isinstance(prediction,str): #in our model we have string and number, i.e maintenance=0.6
print(f"{node.name}:{prediction}")
else:
print(f"{node.name}")
for value, probability in
prediction.parameters[0].items():
print(f"{value}:{probability:0.4f}")
Result
Conclusion
Bayesian network is one of the widely used approaches
to tackle uncertainty in Artificial Intelligence. Just like we were able to
solve the problem Mr. X was facing, with inference by enumeration we had gained
more results such as probability distribution. Inference by enumeration is a
process of finding by the probability distribution of the variable given observed
evidence.
As you can probably tell now how easily this concept is
described above. Anyone with basic discrete mathematics knowledge can
understand this. Our honorable instructor’s well-explained teaching method is
the main reason for successfully grasping every topic of this course quickly.
That’s why this is the best AI course in Bangladesh.

No comments