Last active
November 2, 2016 12:30
-
-
Save nullhack/cadcbbcae1ffe036b89f7e12e98299a4 to your computer and use it in GitHub Desktop.
Compute the stationary values for W
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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