Markov Chain

Table of contents

  1. Learning Outcomes
  2. Outline
  3. Hidden Markov Model
  4. Forward algorithm
  5. Exercise

1. Learning Outcomes

1.1 Learning outcomes

This section outlines the specific competencies students must achieve by the end of the session.

  • Core competency: students must learn to apply various techniques to an agent when it is acting under certainty.

📝 An agent follows a fixed, predictable path where every outcome is known with 100% probability.

2. Outline

2.1 Outline

The session covers three primary mathematical frameworks for modeling sequential data and transitions.

  • Markov Chain: a model for systems that transition between states over time.
  • Hidden Markov Chain: an extension of the Markov model where states are not directly visible.
  • Forward Algorithm: a method used to calculate probabilities within these models.

2.2 Introduction

Sequential data requires specific modeling techniques to be useful for analysis.

  • Sequential patterns: data points often show correlation between observations that are close to each other in a sequence.
  • i.i.d. approach: treating observations as independent and identically distributed ignores these patterns and fails to exploit the relationship between consecutive data points.

2.3 Markov chain definition

A Markov chain is a mathematical system used to model situations where a population or state fluctuates over time.

  • Modeling purpose: it helps determine the probability of a system being in a specific state at a given time.
  • Fluctuation: the model accounts for how elements move from one state to another, such as birds moving between levels in an aviary.

📝 A zoo aviary has three levels where birds fly between perches; a Markov chain models the probability of a bird being on a specific level at any time.

2.4 Markov chain formulation

The mathematical structure of a Markov chain relies on specific types of matrices to represent distributions and transitions.

TermDefinition
Probability vectorA matrix pp where the sum of all elements equals 1, representing the distribution of states.
Stochastic matrixA square matrix TT whose columns are probability vectors, used to transition the system from one distribution to another.
  • State distribution: the current state of the system is represented by a probability vector pp.
  • Transition process: the stochastic matrix TT moves the system from one distribution to a new distribution after a set time interval.
  • Mathematical constraint: for a probability vector pp, the sum of its components must satisfy ∑pi=1\sum p_i = 1.

📝 If a 3x1 matrix pp represents bird percentages on three levels, p1+p2+p3=1p_1 + p_2 + p_3 = 1.

2.5 Markov chain example

A Markov model can represent transitions between discrete states, such as weather conditions, using a transition matrix.

Current StateNext StateProbability
Sunny (S)Sunny (S)0.9
Sunny (S)Rainy (R)0.1
Rainy (R)Sunny (S)0.5
Rainy (R)Rainy (R)0.5
  • Transition probabilities: these values represent the likelihood of moving from one state to another.
  • Transition matrix: the probabilities are organized into a square matrix to simplify calculations.

📝 In a weather model, if it is Sunny today, there is a 0.9 probability it will be Sunny tomorrow and a 0.1 probability it will be Rainy.

2.6 Markov chain example: Tree diagram and Markov chain

There are two primary methods to calculate the probability of future states, such as determining the weather in two days.

  • Tree diagram: a visual method that branches out to show every possible sequence of events and their associated probabilities.
  • Markov chain: a matrix-based method used to calculate state probabilities directly.
MethodApproach
Tree diagramMapping out individual paths and multiplying probabilities for each branch.
Markov chainUsing the transition matrix to calculate the state after multiple steps.

📝 To find the probability of it being rainy in 2 days if today is rainy, one can multiply the probabilities along the branches of a tree diagram or use the transition matrix.

3. Hidden Markov Model

3.1 Hidden Markov model definition

A Hidden Markov Model (HMM) is an inference model used to describe systems where the internal state is not directly visible. These models rely on the assumptions of a Markov Process to function.

  • Markov Process assumption: the model assumes that the future is independent of the past given the present.
  • Data characteristics: HMMs are applied when the data consists of a sequence of observations.
  • Probabilistic dependence: the observed data depends probabilistically on the internal state of the dynamic system.
  • Latent states: the true state of the system is unknown, which is why it is referred to as hidden or latent.

📝 A person's mood is a hidden state that we cannot see directly, but we can observe their outward behavior to infer it.

3.2 States and observations

HMMs distinguish between what is happening internally and what can actually be measured or seen.

TermDescription
Hidden StateThe internal, latent state of the system that is not directly observed.
ObservationThe observed state or data point that is visible to the user.

3.3 Model components

To define an HMM, three specific types of data or probabilities must be established to describe how the system moves and produces data.

ComponentDefinition
Transition dataThe probability of transitioning to a new state conditioned on a present state.
Emission dataThe probability of transitioning to an observed state conditioned on a hidden state.
Initial state informationThe initial probability of transitioning to a hidden state, acting as a prior probability.

📝 In a weather model, the probability of moving from a sunny day to a rainy day is transition data, while the probability of feeling happy given it is sunny is emission data.

3.4 Hidden Markov model example

The model can be visualized through diagrams that represent the relationships between weather and mood.

  • Weather states: in the Gotham city example, the weather can be rainy, cloudy, or sunny.
  • Mood states: Jack's mood can be either sad or happy.
  • Dependencies: the weather for tomorrow depends on the weather today, and Jack's mood depends on the current weather.

📝 If we observe that Jack is happy on a sunny day, we are looking at an observation that is conditioned on the hidden weather state.

3.5 Training

Training refers to the process of determining the model parameters from the available data.

📝 Training an HMM involves adjusting the transition and emission probabilities so that the model best fits a sequence of observed moods and weather patterns.

4. Forward algorithm

4.1 Forward algorithm definition

The Forward Algorithm is a method used to calculate the probability of a specific sequence of observations occurring within an HMM.

📝 The algorithm allows us to calculate the exact probability that Jack would experience the specific sequence of being sad, sad, and then happy.

4.2 Forward algorithm algorithm

The algorithm provides a systematic way to compute the total probability of an observation sequence by summing the probabilities of all possible paths through the hidden states.

  • Purpose: it calculates the probability of an observed sequence given the parameters of the HMM.
  • Process: the algorithm moves through the sequence step-by-step, accumulating probabilities at each time interval.

📝 To find the probability of a three-day sequence, the algorithm calculates the likelihood of every possible weather combination that could produce those specific moods.

5. Exercise

5.1 Weather probability prediction

This exercise requires calculating the probability of specific weather states occurring over a multi-day period based on transition probabilities.

  • Exercise 1: It asks for the probability that it will be rainy in two days, given that today is rainy.
  • Concept tested: This problem tests the ability to use transition probabilities to predict future states in a sequence.

📝 If today is sunny, the probability of tomorrow being sunny is 0.80.8. If today is rainy, the probability of tomorrow being rainy is 0.30.3.

5.2 Weather in the Land of Oz

This problem involves a more complex weather system with three distinct states and specific transition rules.

  • Exercise 2: It asks to find the probabilities of different weather types three days after a fine day.
  • Concept tested: This tests the application of Markov chains or state transitions across multiple time steps.
Current WeatherProbability of FineProbability of CloudyProbability of Rain
Fine00.50.5
Cloudy0.250.250.5
Rain0.250.50.25

5.3 Hidden Markov model and the Forward Algorithm

This exercise applies probabilistic modeling to a scenario involving both weather states and observed human moods.

  • Exercise 3: It asks for the probability of an observed sequence of moods (happy, happy, sad) given specific weather parameters.
  • Concept tested: This tests the use of the Forward Algorithm within a Hidden Markov Model (HMM).
Parameter TypeDetails
Initial ProbabilitiesP(rainy) = 0.35; P(sunny) = 0.65
StatesRainy and sunny weather
ObservationsJack's moods: sad or happy

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also