Skip to content

Conversation

@oyamad
Copy link

@oyamad oyamad commented Aug 25, 2014

Hello,
this pull request is to add routines to compute the stationary distribution vector of a Markov matrix, implementing an algorithm called the "GTH-algorithm", a numerically stable variant of Gaussian elimination. They should be useful in particular when the subdominant (second largest) eigenvalue of the Markov matrix is close to 1.

The routines, which are specialized in computing the eigenvector with eigenvalue 1 for irreducible Markov matrices, are much faster than the general purpose routine eig.

I also included some test code and added documents that describe the routines.
I hope you find this useful.

@oyamad
Copy link
Author

oyamad commented Aug 26, 2014

Travis CI failed in test_stoch_eig_iv and test_gth_solve_iv:

assert mpf('0.625') in mpi('0.6249999999999999978315955904', '0.6249999999999999978315957197')

I could not reproduce the problem in my environment (with or without gmpy), but as I defined the instances of iv.matrix with strings, as in the documentation, slightly different outcomes came out:

Python 2.7.8 (default, Jul  2 2014, 10:14:46) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mpmath as mp
>>> P = mp.iv.matrix([[0.9, 0.075, 0.025], [0.15, 0.8, 0.05], [0.25, 0.25, 0.5]])
>>> x_iv = mp.iv.stoch_eig(P)
>>> x_iv[0]
mpi('0.62499999999999922', '0.62500000000000078')
>>> Q = mp.iv.matrix([['0.9', '0.075', '0.025'], ['0.15', '0.8', '0.05'], ['0.25', '0.25', '0.5']])
>>> y_iv = mp.iv.stoch_eig(Q)
>>> y_iv[0]
mpi('0.624999999999999', '0.625000000000001')
>>> R = mp.matrix([[0.9, 0.075, 0.025], [0.15, 0.8, 0.05], [0.25, 0.25, 0.5]])
>>> mp.stoch_eig(R)
matrix(
[['0.625', '0.3125', '0.0625']])

So let me give it another try.

@oyamad oyamad closed this Aug 27, 2017
@oyamad oyamad deleted the eigen_markov branch August 27, 2017 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant