%% Supply Inertial Weights for Lazy Chain Transformation
% Consider this theoretical, right-stochastic transition matrix of a stochastic process.
% P = \left[ {\begin{array}{*{20}{c}}
% 0&0&1/2&1/4&1/4&0&0\\
% 0&0&1/3&0&2/3&0&0\\
% 0&0&0&0&0&1/3&2/3\\
% 0&0&0&0&0&1/2&1/2\\
% 0&0&0&0&0&3/4&1/4\\
% 1/2&1/2&0&0&0&0&0\\
% 1/4&3/4&0&0&0&0&0
% \end{array}} \right].
% Create the Markov chain that is characterized by the transition matrix P.

P = [ 0   0  1/2 1/4 1/4  0   0 ;
      0   0  1/3  0  2/3  0   0 ;
      0   0   0   0   0  1/3 2/3;
      0   0   0   0   0  1/2 1/2;
      0   0   0   0   0  3/4 1/4;
     1/2 1/2  0   0   0   0   0 ;
     1/4 3/4  0   0   0   0   0 ];
mc = dtmc(P);

%
% Plot the eigenvalues of the transition matrix on the complex plane.

figure;
eigplot(mc);
title('Original Markov Chain')

% Three eigenvalues have modulus one, which indicates that the period of mc is three.
%
% Create lazy versions of the Markov chain mc using various inertial weights. Plot the eigenvalues of the lazy chains on separate complex planes.

w2 = 0.1;                                 % More active Markov chain
w3 = 0.9;                                 % Lazier Markov chain
w4 = [0.9 0.1 0.25 0.5 0.25 0.001 0.999]; % Laziness differs between states

lc1 = lazy(mc);
lc2 = lazy(mc,w2);
lc3 = lazy(mc,w3);
lc4 = lazy(mc,w4);

figure;
eigplot(lc1);
title('Default Laziness');

figure;
eigplot(lc2);
title('More Active Chain');

figure;
eigplot(lc3);
title('Lazier Chain');

figure;
eigplot(lc4);
title('Differing Laziness Levels');

% All lazy chains have only one eigenvalue with modulus one. Therefore, they are aperiodic. The spectral gap (distance between inner and outer circle) determines the mixing time. Observe that all lazy chains take longer to mix than the original Markov chain. Chains with different inertial weights than the default take longer to mix than the default lazy chain.
% Copyright 2012 The MathWorks, Inc.