Skip to content

oyamad/test_mc_compute_stationary

Repository files navigation

test_mc_compute_stationary.py

Nose test for mc_compute_stationary in mc_tools.py from quantecon

Check whether all the elements of the computed stationary distribution are nonnegative for the Markov matrix generated by the KMR model with a large number of players or a very small probability of mutation.

(Instances of outputs with negative values have initially been found by students from my undergrad seminar, Takayasu Ohno and Atsushi Yamagishi.)

Run

$ python test_mc_compute_stationary.py

or

$ nosetests -v -s

IPython Notebooks

  • Outcome 1: Python 2.7.6 (installed via Homebrew) on Mac OS X 10.6.8 (Snow Leopard)
  • Outcome 2: Python 2.7.6 in Anaconda on Mac OS X 10.9.4 (Marvericks)
  • Outcome 3: Python 2.7.8 (installed via Homebrew) on Mac OS X 10.9.4 (Marvericks)

The outputs in general differ across different environment, while for some cases, 1 and 3 yield exactly the same outputs.

unittest_mc_compute_stationary.py

Manual Unittest for mc_compute_stationary in mc_tools.py from quantecon

Run

$ python unittest_mc_compute_stationary.py

or with parameter values, for example,

$ python unittest_mc_compute_stationary.py --N=3 --epsilon=1e-14

or

$ python unittest_mc_compute_stationary.py --move='simultaneous' --N=5 --epsilon=1e-15

IPython Notebooks

  • Outcome 1: Python 2.7.6 (installed via Homebrew) on Mac OS X 10.6.8 (Snow Leopard)
  • Outcome 2: Python 2.7.6 in Anaconda on Mac OS X 10.9.4 (Marvericks)
  • Outcome 3: Python 2.7.8 (installed via Homebrew) on Mac OS X 10.9.4 (Marvericks)

mc_compute_stationary_sympy.py

Using Matrix.eigenvects() from SymPy, it returns (computed) eigenvectors whose (computed) eigenvalues are close to 1.

In some cases, this does not work well, returning an empty list...

mc_compute_stationary_mpmath.py

This uses mpmath (version 0.18 or above required), which allows arbitrary precision in floating-point arithmetic.

mpmath:

This seems to work very well:

(The outcomes yielded are exactly the same.)

Manual Unittest

  • Outcome: Python 2.7.8 (installed via Homebrew) on Mac OS X 10.9.4 (Marvericks)

Automated Nose Test

  • Outcome: Python 2.7.8 (installed via Homebrew) on Mac OS X 10.9.4 (Marvericks)

Passed the tests with tolerance level 1e-17.

Update (2014/8/8)

This functionality has been incorporated into the new version of mc_compute_stationary in mc_tools.py.

About

Test mc_compute_stationary from quantecon

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages