Hidden Markov Model

Introduction

Example

Consider the observations of a man carrying an umbrella.

Supposing that we do not know what the weather is, can we deduce from the presence of his umbrella?

Let the state of the weather be recorded as shown.

Sunny Overcast Raining

Let the initial probabilities be as shown.

P(Sunny) = 0.3 P(Overcast) = 0.4 P(Raining) = 0.3

Let the transition probabilities be as shown.

P(Sunny → Sunny) = 0.6 P(Sunny → Overcast) = 0.3 P(Sunny → Raining) = 0.1 P(Overcast → Sunny) = 0.2 P(Overcast → Overcast) = 0.6 P(Overcast → Raining) = 0.2 P(Raining → Sunny) = 0.1 P(Raining → Overcast) = 0.3 P(Raining → Raining) = 0.6

The probability of two days of sunshine, followed by two days of rain is

P(Sunny) * P(Sunny → Sunny) * P(Sunny → Raining) * P(Raining → Raining) = 0.3 * 0.6 * 0.1 * 0.6 = 0.0108

Dialog

Input
Output

Code

The following is the javaScript code.

src/js/markovChain.js