Problem (Markov Chain)
Assume a discrete-time Markov chain over a finite set of states S={s1,…,sn}.
Part A — Multi-step transition probabilities
You are given a 1-step transition probability matrix P∈Rn×n, where Pij=Pr(Xt+1=sj∣Xt=si).
Answer queries of the form:
-
Pr(Xt+k=sj∣Xt=si)
for various
i,j,k
.
You may use matrix multiplication (e.g., matmul) in your solution.
Part B — Estimate the transition matrix from observed transitions
You are given a list of observed consecutive transitions (state pairs), e.g.:
[(s1, s2), (s2, s3), (s1, s3), (s1, s2), ...]
Construct an estimated transition matrix P^ using transition frequencies:
-
P^ij=∑j′#(si→sj′)#(si→sj)
Requirements / Edge cases to address
-
How to handle states that appear in the state list but have
zero
outgoing transitions in the data.
-
Ensure each row of
P^
is a valid probability distribution (sums to 1 where defined).