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
- 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.
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
- 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)
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...
This uses mpmath (version 0.18 or above required), which allows arbitrary precision in floating-point arithmetic.
mpmath:
This seems to work very well:
- Demonstration 1: sympy.mpmath 0.18
- Demonstration 2: mpmath 0.19
(The outcomes yielded are exactly the same.)
- Outcome: Python 2.7.8 (installed via Homebrew) on Mac OS X 10.9.4 (Marvericks)
- Outcome: Python 2.7.8 (installed via Homebrew) on Mac OS X 10.9.4 (Marvericks)
Passed the tests with tolerance level 1e-17.
This functionality has been incorporated into the new version of mc_compute_stationary
in mc_tools.py.