In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

Consider an example where we're tracking voter behavior. So a voter's preference is tracted say week to week.

In [18]:
M = np.array([[0.7, 0.1, 0.3], [0.1, 0.8, 0.3], [0.2, 0.1, 0.4]])
print(M.round(2))
[[ 0.7  0.1  0.3]
 [ 0.1  0.8  0.3]
 [ 0.2  0.1  0.4]]

Suppose the first element is the probability for democrats, the second for republicans, the third for independents.

Now assume that we start our simulation after a deadlock debate with only two parties. What is the final steady state?

In [19]:
x = np.array([0.5, 0.5, 0.0])
In [21]:
for i in range(100):
    x = M.dot(x)
print(x)
[ 0.34615385  0.46153846  0.19230769]

How do we know this converged? Does it depend on how it started?

In [ ]: