Markov Chains Clearly Explained! Part - 1

Normalized Nerd
25 Oct 202009:24

Summary

TLDRIn this 'Normalized Nerd' video, the presenter introduces Markov chains, a concept used across various fields like statistics, biology, economics, physics, and machine learning. The video explains Markov chains through a restaurant example that serves three types of food with a predictable pattern based on the previous day's meal. The Markov property, which states that the future state depends only on the current state, is highlighted. The presenter also discusses the stationary distribution, or equilibrium state, which represents the long-term probability distribution of states. The video demonstrates how to find this distribution through simulation and linear algebra, using an adjacency matrix and eigenvector equations to solve for the stationary state.

Takeaways

  • 😀 Markov chains are used in various fields such as statistics, biology, economics, physics, and machine learning.
  • 🍔 The video uses a restaurant example with three food types (hamburger, pizza, hot dog) to explain Markov chains, where the probability of serving a food type depends on what was served the previous day.
  • 🔢 A Markov chain is represented by a diagram with weighted arrows indicating the probability of transitioning from one state to another.
  • 📈 The Markov property states that the future state depends only on the current state, not on the sequence of previous states.
  • 🎯 The sum of the probabilities (weights) of outgoing transitions from any state must equal 1, as they represent a complete probability distribution.
  • 🚶‍♂️ A random walk along the chain can be used to explore the probabilities of each state over time.
  • 📊 After many steps, the probabilities converge to a stationary distribution, also known as the equilibrium state, which does not change over time.
  • 📚 Linear algebra can be used to find the stationary state more efficiently than simulation, by representing the Markov chain as an adjacency matrix and solving for the eigenvector corresponding to the eigenvalue of 1.
  • 🔍 The stationary state can reveal long-term probabilities, such as the restaurant serving hamburgers about 35% of the time, pizza 21%, and hot dogs 44% of the time.
  • 🔬 The eigenvector method also allows for the detection of multiple stationary states by checking for multiple eigenvectors with an eigenvalue of 1.
  • 📈 The results from the linear algebra method can be compared with simulation results to validate the findings and understanding of the Markov chain.

Q & A

  • What is a Markov chain?

    -A Markov chain is a mathematical concept used in various fields such as statistics, biology, economics, physics, and machine learning. It represents a sequence of possible events where the probability of each event depends only on the state attained in the previous event.

  • Why are Markov chains interesting?

    -Markov chains are interesting because they simplify the process of predicting future states by only considering the current state, without needing to know the sequence of events that led up to it. This makes them useful for modeling real-world problems with complex dependencies.

  • What is the restaurant example in the script illustrating?

    -The restaurant example illustrates how a Markov chain works. The restaurant serves only one of three foods each day, and the probability of serving a particular food depends on what was served the previous day. This creates a predictable pattern that can be represented as a Markov chain.

  • What does the term 'state' refer to in the context of Markov chains?

    -In the context of Markov chains, 'state' refers to a situation or condition that can result in a particular outcome. In the restaurant example, the state is the type of food being served on a given day.

  • What is the Markov property?

    -The Markov property is the fundamental characteristic of a Markov chain, stating that the probability of transitioning to a future state depends only on the current state and not on the sequence of events that preceded it.

  • Why is the sum of the weights of outgoing arrows from any state equal to 1 in a Markov chain?

    -The sum of the weights of the outgoing arrows from any state equals 1 because these weights represent probabilities. For probabilities to be valid, they must add up to one, ensuring that all possible outcomes are accounted for.

  • What is a stationary distribution in the context of Markov chains?

    -A stationary distribution, also known as the equilibrium state, is a probability distribution of the states in a Markov chain that does not change over time. It represents the long-term probabilities of being in each state after a large number of transitions.

  • How can you find the stationary state of a Markov chain?

    -One way to find the stationary state of a Markov chain is through simulation, running a large number of steps and observing the convergence of probabilities. Alternatively, linear algebra can be used by setting up and solving the eigenvector equation for the transition matrix with the eigenvalue equal to 1.

  • What is an adjacency matrix and how is it used in representing a Markov chain?

    -An adjacency matrix is a way to represent a directed graph, such as a Markov chain, where the elements of the matrix denote the weight of the edge connecting two vertices. In the context of Markov chains, it is called the transition matrix and is used to calculate the probabilities of transitioning from one state to another.

  • How does the script demonstrate the use of linear algebra to find the stationary state?

    -The script demonstrates the use of linear algebra by showing how to set up an eigenvector equation for the transition matrix with an eigenvalue of 1. Solving this equation yields the stationary state, which represents the long-term probability distribution of the states in the Markov chain.

  • How can you determine if there are multiple stationary states in a Markov chain?

    -To determine if there are multiple stationary states, you can look for the existence of more than one eigenvector with an eigenvalue equal to 1 for the transition matrix. Each eigenvector represents a different stationary state.

Outlines

00:00

🍔 Introduction to Markov Chains with a Restaurant Example

The video begins with an introduction to Markov chains, a concept used across various disciplines like statistics, biology, economics, physics, and machine learning. The presenter uses a restaurant example to illustrate the concept, where the restaurant serves only one of three foods—hamburger, pizza, or hot dog—based on what was served the previous day. This creates a predictable pattern, represented by a Markov chain diagram with weighted arrows indicating the transition probabilities between states. The Markov property is highlighted, which states that the future state depends solely on the current state, not on the sequence of past states. This property simplifies the handling of complex real-world problems.

05:01

📊 Markov Chain Properties and Simulation of a Random Walk

The video continues by discussing the properties of Markov chains. It emphasizes that the sum of the transition probabilities from any state must equal 1, as they represent a complete set of probabilities. The presenter then introduces a simulation of a random walk along the Markov chain to explore the probability distribution of states over time. By conducting a random walk for 10 consecutive days, the presenter demonstrates how the probabilities for each food item change and eventually seeks to determine if these probabilities converge to fixed values in the long run, indicating a stationary or equilibrium state.

🔍 Efficient Calculation of Stationary States Using Linear Algebra

The presenter acknowledges that the simulation method for finding stationary states may not be efficient and suggests using linear algebra as a more effective approach. The Markov chain is represented by an adjacency matrix, also known as the transition matrix, where each element denotes the transition probability between states. The goal is to find the stationary state, which is a row vector representing the long-term probability distribution of states. The presenter explains that this can be achieved by solving for the eigenvector of the transition matrix with an eigenvalue of 1, which corresponds to the stationary distribution. The method is shown to yield a close result to the one obtained from the simulation, validating the stationary state probabilities for the restaurant example.

Mindmap

Keywords

💡Markov Chains

Markov Chains are stochastic models that describe a sequence of possible events where the probability of each event depends only on the state attained in the previous event. In the video, Markov Chains are introduced as a concept used across various fields like statistics, biology, economics, physics, and machine learning. The script uses a restaurant example to illustrate how the probability of serving a particular food item depends solely on what was served the previous day, showcasing the Markov property.

💡Normalized Nerd

Normalized Nerd appears to be the name of the channel or the host presenting the video. It is not a technical term but rather a branding element that adds personality and identity to the content. The channel likely focuses on explaining complex topics in a more accessible and 'normalized' manner, as suggested by the name.

💡Machine Learning

Machine Learning is a subset of artificial intelligence that enables computers to learn from data and improve at tasks without being explicitly programmed. In the context of the video, machine learning is mentioned as one of the fields where Markov Chains are applied, indicating the video's relevance to both theoretical concepts and practical applications in technology.

💡State

In the context of Markov Chains, a 'state' represents a situation or condition that can be occupied at a certain time step. The video uses the term 'state' to describe the different types of food served by the restaurant on any given day, with each food item representing a unique state in the Markov Chain.

💡Transition

A 'transition' in Markov Chains refers to the movement from one state to another. The video script describes transitions with weighted arrows, where each arrow represents the probability of moving from the current state (e.g., serving hamburgers) to a future state (e.g., serving pizza). Transitions are fundamental to understanding how Markov Chains model sequences of events.

💡Markov Property

The Markov Property is the core characteristic of a Markov Chain, stating that the future state depends only on the current state and not on the sequence of events that preceded it. The video emphasizes this property by explaining that knowing what the restaurant served on the current day is sufficient to predict what they will serve the next day, without needing to know the entire history of served items.

💡Stationary Distribution

The 'Stationary Distribution' or 'Equilibrium State' in a Markov Chain refers to the probability distribution of the states that does not change over time. The video discusses how, after simulating a random walk for a large number of steps, the probabilities of serving each food item converge to fixed values, indicating the stationary distribution of the Markov Chain.

💡Adjacency Matrix

An 'Adjacency Matrix' is a way to represent a directed graph, where the elements of the matrix denote the weight of the edge connecting two vertices. In the video, the Markov Chain is represented by an adjacency matrix, which is also called the transition matrix, to efficiently model the transitions between states.

💡Eigenvector

An 'Eigenvector' is a non-zero vector that does not change its direction after a linear transformation represented by a matrix. In the context of the video, the stationary state of the Markov Chain is found by solving for the eigenvector of the transition matrix where the eigenvalue is 1, which helps in determining the long-term probabilities of each state.

💡Linear Algebra

Linear Algebra is a branch of mathematics that deals with vector spaces and linear equations. The video suggests using linear algebra as a more efficient method to find the stationary state of a Markov Chain, by solving the eigenvector equation related to the transition matrix.

Highlights

Introduction to Markov chains and their applications in various fields such as statistics, biology, economics, physics, and machine learning.

Explanation of the concept of Markov chains with an example of a restaurant serving three types of food with a specific rule based on the previous day's serving.

Use of weighted arrows in a diagram to represent the transitions between states in a Markov chain.

The Markov property, which states that the future state depends only on the current state, not on the sequence of previous states.

The requirement that the sum of the weights of outgoing arrows from any state in a Markov chain must equal 1, representing the total probability.

Discussion of special properties of certain Markov chains that deserve individual videos.

Exploring the Markov chain through a random walk simulation to understand the probability distribution of states over time.

The observation that probabilities may converge to fixed values in the long run, known as the stationary distribution or equilibrium state.

A Python script used to simulate a random walk for 100,000 steps to observe the convergence of probabilities to the stationary distribution.

Introduction to a more efficient method to find the stationary state using linear algebra and adjacency matrices.

Representation of a Markov chain as a directed graph and its translation into an adjacency matrix for efficient analysis.

The use of a row vector to represent the probability distribution of states and its multiplication with the transition matrix to find future probabilities.

The concept of a stationary state as an eigenvector equation where the eigenvalue is 1, representing a state that does not change over time.

The condition that the elements of the stationary state vector must sum up to 1, as it represents a probability distribution.

The method to determine if there are multiple stationary states by checking for more than one eigenvector with an eigenvalue of 1.

Comparison of the stationary state found using linear algebra with the results from the simulation, validating the findings.

Encouragement for viewers to request more videos on Markov chains and a call to action to subscribe and share the video.

Transcripts

play00:00

hello people from the future welcome to

play00:02

normalized nerd

play00:03

today i'm gonna talk about markov chains

play00:06

this is a concept that is used in many

play00:08

places

play00:09

from statistics to biology from

play00:11

economics to physics and of course in

play00:12

machine learning

play00:14

i guess some of you have heard of markov

play00:16

chains before but don't have a clear

play00:18

idea about it

play00:19

i hope by the end of this video you will

play00:21

have a fair understanding of markov

play00:23

chains

play00:24

and you will know why they are so

play00:25

interesting if you are new here then

play00:27

please subscribe to my channel and hit

play00:29

the bell icon

play00:30

i make videos about machine learning and

play00:32

data science regularly

play00:34

so let's get started well as you know me

play00:36

i like to start with an example

play00:38

assume there's a restaurant that serves

play00:40

only three types of foods

play00:42

hamburger pizza and hot dog

play00:45

but they follow a weird rule on any

play00:48

given day

play00:49

they serve only one of these three items

play00:52

and it depends on what they had served

play00:55

yesterday

play00:56

in other words there is a way to predict

play00:58

what they will serve tomorrow

play01:00

if you know what they are serving today

play01:04

for example there is a 60 chance that

play01:07

tomorrow will be a pizza day

play01:09

given that today is a hamburger day

play01:12

i'm gonna represent it in the diagram as

play01:14

weighted arrows

play01:16

the arrow originates from the current

play01:18

state and

play01:19

points to the future state i'm using the

play01:22

term

play01:22

state because that's the convention

play01:24

let's see another one

play01:26

there's a 20 chance that tomorrow again

play01:29

they will serve hamburgers

play01:31

and that is represented as a

play01:33

self-pointing arrow

play01:35

well each arrow is called a transition

play01:37

from one state to the other now i'm

play01:40

gonna show you

play01:41

all the possible transitions the diagram

play01:43

you are seeing right now

play01:45

is actually a markov chain yes the

play01:48

concept is

play01:48

that simple now let's discuss some

play01:50

properties of the markov chain

play01:52

the most important property of the

play01:54

markov chain is that the future state

play01:57

depends only on the current state not

play02:00

the steps before

play02:01

mathematically we can say the

play02:03

probability that

play02:04

n plus 1 x step will be x depends

play02:08

only on the nth step not the complete

play02:11

sequence of steps that came before n

play02:14

at first glance this might not seem so

play02:16

impressive

play02:17

but on a closer look we can see that

play02:19

this property

play02:20

makes our life a lot easier while we

play02:23

tackle some complicated real world

play02:25

problems

play02:26

let's understand it a little better

play02:28

suppose the restaurant served

play02:30

pizza on the first day hamburger on the

play02:32

second

play02:33

and again pizza on the third day now

play02:36

what is the probability

play02:37

that they will serve hot dogs on the

play02:39

fourth day

play02:40

well we just need to look at the third

play02:43

day and it turns out to be

play02:45

0.7 this is the heart of markov chains

play02:48

and it's known as the markov property

play02:51

the second important property is that

play02:54

the sum of the weights of the outgoing

play02:57

arrows

play02:58

from any state is equal to 1.

play03:01

this has to be true because they

play03:03

represent probabilities

play03:04

and for probabilities to make sense they

play03:07

must add up to one

play03:08

here i should probably tell you that

play03:09

there are certain markov chains with

play03:12

special properties

play03:13

but they deserve individual videos on

play03:15

their own so here i'm just gonna stick

play03:18

to the basic kind of markov chains

play03:20

now that you know what a markov chain

play03:22

actually is let's explore

play03:24

our markov chain by doing a random walk

play03:27

along the chain

play03:28

initially we are on a hamburger day

play03:31

let's see what they serve for 10

play03:33

consecutive days

play03:51

so after 10 steps we have a situation

play03:53

like this

play03:54

now we want to find what is the

play03:56

probability corresponding to

play03:57

each of the food items aka

play04:00

the probability distribution of the

play04:03

states

play04:04

well it's pretty simple just divide the

play04:06

number of

play04:07

occurrences of an item by the total

play04:10

number of days

play04:11

for hamburger it's 4 upon 10 for pizza

play04:15

it's 2 upon 10 and it's 4 upon 10 for

play04:18

hot dogs

play04:19

it's obvious that if we change the

play04:21

number of steps

play04:22

then these probabilities will vary but

play04:25

we are interested in

play04:26

what happens in the long run do these

play04:29

probabilities converge to fixed values

play04:31

or they continue to change forever i

play04:34

wrote a python script to simulate the

play04:36

random work for hundred thousand steps

play04:38

i found that the probabilities converge

play04:40

to these values

play04:46

and this probability distribution has a

play04:48

special name

play04:49

which is the stationary distribution or

play04:52

the equilibrium state this simply means

play04:55

that this

play04:56

probability distribution doesn't change

play04:58

with time

play04:59

for this markov chain okay so we have

play05:01

managed to find the stationary state

play05:03

but this method doesn't seem to be very

play05:06

efficient

play05:06

is it moreover we don't know if there

play05:10

exists any other stationary states well

play05:13

a better way to approach this problem is

play05:15

linear algebra

play05:16

let me show you first of all let us

play05:19

think about

play05:19

how we can represent this markov chain

play05:22

more efficiently

play05:23

well this is essentially a directed

play05:25

graph

play05:26

so we can represent it by an adjacency

play05:29

matrix

play05:30

if you don't know what it is then please

play05:32

don't worry it's very simple

play05:34

the elements in the matrix just denote

play05:36

the weight of the

play05:38

edge connecting the two corresponding

play05:40

vertices for example

play05:42

the element in the second row and first

play05:44

column denotes the weight

play05:46

or the transition probability from pizza

play05:49

to hamburger if an element is 0 then it

play05:52

just means that there's no edge

play05:54

between the two vertices this matrix is

play05:57

also called

play05:58

transition matrix let's denote it by a

play06:01

remember that our goal is to find the

play06:04

probabilities of

play06:05

each state conventionally we take a row

play06:08

vector

play06:09

called pi whose elements represent the

play06:12

probabilities of the states

play06:13

basically pi denotes the probability

play06:15

distribution of the states

play06:17

suppose in the beginning we are on a

play06:20

pizza day

play06:21

so the second element which corresponds

play06:23

to the pizza becomes one

play06:25

and other two remain zero now see what

play06:28

happens when we multiply this row vector

play06:31

with our transition matrix

play06:37

we get the second row of the matrix in

play06:40

other words

play06:41

we get the future probabilities

play06:42

corresponding to the pisa state

play06:45

then we take this result and put it in

play06:48

the place of

play06:49

pi zero

play06:52

we will do this once again

play06:59

now if there exists a stationary state

play07:02

then

play07:02

after a certain point the output row

play07:04

vector should be exactly same

play07:07

as the input vector let's denote this

play07:10

special row vector as

play07:11

pi so we should be able to write pi

play07:14

a equals pi if you have ever taken a

play07:18

course of linear algebra then you should

play07:20

find this equation somewhat similar

play07:22

to a very famous equation yes i'm

play07:25

talking about

play07:26

the eigenvector equation consider lambda

play07:29

equal to 1 and just

play07:30

reverse the order of multiplication and

play07:32

you have got our equilibrium state

play07:34

equation

play07:35

how to interpret this you might ask well

play07:37

we can imagine that

play07:39

pi is a left eigenvector of matrix a

play07:43

with eigenvalue equal to 1. please pause

play07:46

the video if you need a moment to

play07:47

convince yourself

play07:48

now the eigenvector must satisfy another

play07:51

condition

play07:52

the elements of pi must add up to 1

play07:55

because it denotes a probability

play07:56

distribution

play07:57

so after solving these two equations

play08:01

we get the stationary state as this

play08:05

it tells us that the restaurant will

play08:07

serve hamburger about 35

play08:09

of the days pigs are about 21 and hot

play08:13

dog about 46 percent

play08:14

using this technique we can actually see

play08:16

if there are more than one stationary

play08:18

states

play08:19

can you guess how we just need to see if

play08:22

there exists

play08:23

more than one eigenvectors with

play08:25

eigenvalue equal to 1.

play08:27

isn't it super elegant now let's compare

play08:29

this result

play08:30

with the previous one that we got from

play08:32

our simulation

play08:33

look how close they are they kind of

play08:36

validate each other

play08:37

by now you should have a very good

play08:39

understanding of markov chains

play08:41

and you should be able to identify

play08:42

markov chains successfully

play08:44

obviously there is much more to learn

play08:46

about different kinds of markov chains

play08:48

and their properties

play08:49

that cannot be covered in a single video

play08:52

if you want me to make more videos on

play08:53

this topic

play08:54

then please let me know in the comment

play08:56

section if you like this video

play08:58

do share it and please please please

play09:00

subscribe to my channel

play09:01

stay safe and thanks for watching

play09:11

[Music]

play09:23

you

Rate This

5.0 / 5 (0 votes)

Related Tags
Markov ChainsMachine LearningData ScienceStatisticsBiologyEconomicsPhysicsRandom WalkTransition MatrixStationary State