Thursday, April 8, 2021

Uncertainty – Bayesian Network (Instructor Name: Nuruzzaman Faruqui)

 

Introduction

"A Bayesian network is a probabilistic graphical model which represents a set of variables and their conditional dependencies using a directed acyclic graph." We know knowledge representation are using first-order logic and propositional logic with certainty, which means we were sure about the predicates. With this knowledge representation, we might write A→B, which means if A is true then B is true, but consider a situation where we are not sure about whether A is true or not then we cannot express this statement, this situation is called uncertainty. So to represent uncertain knowledge, where we are not sure about the predicates, we need uncertain reasoning or probabilistic reasoning. Uncertainty appears when an agent is not completely sure about the outcome of the decisions it has made. It’s a data structure that represents probabilistic relations and dependencies among random variables. 

The properties are 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 is an important part of Artificial Intelligence course and this  lab report is done by myself under the supervision of Nuruzzaman Faruqui, lecturer of City University, Bangladesh. From this course we get to explore the real applicable approaches through AI and also acquires better knowledge of the functionality of AI and how AI is making our daily life easier. That's why this is the best Artificial Intelligence course in Bangladesh.

Problem Statement:

Here we have an scenario to understand the Bayesian Network from Uncertainty. 

Let Mr. X has an appointment to attend. To reach the destination Mr. X may 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.


Figure: The Bayesian network model

 

Solution

From the above model let’s rain is a root node. That means it has no other probability distributions are depend 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

The train is a variable that varies if the train is on time or delayed. The train has dependencies on Maintenance and root node Rain. So, their values affect the probability distribution of Train.

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 model 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

 

Code Commentary:

#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:

After implementing the code we got the result below-


 

Conclusion

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.

No comments:

Post a Comment

Linear Programming in Artificial Intelligent ((Instructor Name: Nuruzzaman Faruqui)

  Linear Programming   Introduction: Linear Programming is the technique of portraying complicated relationships between elements by using...