we can see we have two states: “sunny” and “rainy”. Let’s say
the day is sunny, and we want to know what the chances are that it will be
sunny the next day. We can see that the Markov chain indicates that there is a
.9, or 90%, chance it will be sunny. And rainy is 0.5 so there is no chance
that it would be a rainy day.
This is an Artificial Intelligence course conducted in City University by
Nuruzzaman Faruqui. This is the Best AI Course in Bangladesh. The way of
teaching is very familiar to us. we can easily communicate with the teacher.
After finishing the lecture, what examples are done in lecture we are
implemented in coding for better understand.
Problem Statement
Let’s make a Markov chain by
a transition model. That transition model will set out the probability
distribution of the next event.
From the above figure, the
probability of tomorrow will be a sunny day based on today being a sunny day is
0.8. If it is rainy today, the probability of rain tomorrow is 0.7. It is
reasonable since rainy days are more likely to follow each other. Using this
transition model, we will make a Markov chain on python code.
Source Code
from pomegranate import *
# Define starting probabilities
start = DiscreteDistribution({
"sun": 0.5,
"rain": 0.5
})
# Define transition model
transitions = ConditionalProbabilityTable([
["sun", "sun", 0.8],
["sun", "rain", 0.2],
["rain", "sun", 0.3],
["rain", "rain", 0.7]
], [start])
# Create Markov chain
model = MarkovChain([start, transitions])
# Sample 10 states from chain
chain = model.sample(10)
print(chain)
Result
After importing the pomegranate made the
distribution as 50:50 then write the transition model and set the 50 states
sample we will get this kind of result:
Firstly, we define
our starting distribution as 50:50 that's means sun = 0.5 and rain = 0.5 and
then, we import the pomegranate. Then define the transition model from
the conditional probability table. Then we create the Markov chain function.
After creating the Markov chain function, we set 50 state samples for painting
the result the 50 samples.
Conclusion
At first, we discuss the Markov chain and an
example of the Markov chain. Then discuss the problem and the solution, after
this, we write the code in python and discuss the code so that everyone can
easily understand the code. That's why This is the Best AI Course in
Bangladesh.
No comments:
Post a Comment