Skip to content

Instantly share code, notes, and snippets.

@nullhack
Last active November 2, 2016 12:30
Show Gist options
  • Save nullhack/cadcbbcae1ffe036b89f7e12e98299a4 to your computer and use it in GitHub Desktop.
Save nullhack/cadcbbcae1ffe036b89f7e12e98299a4 to your computer and use it in GitHub Desktop.
Compute the stationary values for W
"""Licensed under GPLv3 <http://www.gnu.org/licenses/>.
Authors:
Eric Lopes
"""
import scipy.linalg
import numpy
W = numpy.matrix(
[[0.4 ,0.4 ,0.2 ,0.0],
[0.2 ,0.2 ,0.3 ,0.3],
[0.25,0.25,0.25,0.25],
[0.1 ,0.4 ,0.2 ,0.3]])
evals, lvecs = scipy.linalg.eig(W, right=False, left=True)
tolerance = 1e-15
mask = abs(evals - 1) < tolerance
evals = evals[mask]
lvecs = lvecs[:, mask]
equilibrium = lvecs/lvecs.sum(axis=0, keepdims=True)
print(equilibrium)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment