javaalgorithmhidden-markov-modelsmarkov-chains

Implementing markov Chain Example - java


There are plenty of Markov Chain examples for text simulations, however for a state change (for ex weather change based on probability over time) I couldn't find any examples. For ex, lets say

Sunny --> Sunny = probability is 0.8
Sunny --> Rainy = probability is 0.2

what I am looking is a way to write an algorithm which will display the current weather till n no of steps.

for e.g: f(3) => S,S,R

I guess what I am really finding it difficult is how to put the randomness to the algorithm.

This algorithm generate a sentence based on the probability of given words in a phrase, but I am unable to map it into my requirement.( I am not good in maths)

And pls let me know how can I extend the algorithm, for ex if the probability of a sunny day with high humidity is 0.3, the function should produce something like

 f(4) -> [S,Low Hu],[S, Low Hu],[R,High Hu] etc..

Please let me know whether this approach is good for my requirement. pseudo code would be enough.


Solution

  • You can use mockNeat.probabilities() method from the library with the same name, if you don't want to implement the same functionality by yourself. Or you can take a look on how it's implemented.