Identify the communicating classes of a Markov chain. Then, determine whether the classes are recurrent and their periodicity.
Generate a random seven-state Markov chain. Specify that 40 random elements in the transition matrix should be zero.
rng(1); % For reproducibility
mc = mcmix(7,'Zeros',40);
Plot a directed graph of the Markov chain. Visually identify the communicating class to which each state belongs by using node colors.
figure;
graphplot(mc,'ColorNodes',true)
Identify the communicating classes in mc, and then determine:
The communicating class to which each state belongs
Whether each communicating class is recurrent
The period of each class
[bins,ClassStates,ClassRecurrence,ClassPeriod] = classify(mc)
bins = 1×7
6 4 6 3 2 5 1
ClassStates=1×6 cell array
{["7"]} {["5"]} {["4"]} {["2"]} {["6"]} {["1" "3"]}
ClassRecurrence = 1x6 logical array
0 0 0 0 0 1
ClassPeriod = 1×6
1 1 1 1 1 2
mc has seven classes. Each state is its own communicating class, except states 1 and 3, which together compose class 6. Class 6 is the only recurrent class; classes 1 through 5 are transient. Class 6 has period 2; all other classes are aperiodic.