/usr/lib/python2.7/dist-packages/pymc/tests/test_MCMCSampler.py is in python-pymc 2.2+ds-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | """
The DisasterMCMC example.
"""
from __future__ import with_statement
from numpy.testing import *
from pymc import MCMC, database
from pymc.examples import disaster_model
import nose, warnings, os
PLOT=True
try:
from pymc.Matplot import plot, autocorrelation
except:
PLOT=False
pass
DIR = 'testresults/'
class test_tiny_MCMC(TestCase):
# Instantiate samplers
M = MCMC(disaster_model)
# Sample
M.sample(10, progress_bar=False)
def test_plot(self):
if not PLOT:
raise nose.SkipTest
# Plot samples
plot(self.M)
class test_MCMC(TestCase):
# Instantiate samplers
M = MCMC(disaster_model, db='pickle')
# Sample
M.sample(4000,2000,verbose=0, progress_bar=False)
M.db.close()
def test_instantiation(self):
# Check stochastic arrays
assert_equal(len(self.M.stochastics), 3)
assert_equal(len(self.M.observed_stochastics),1)
assert_array_equal(self.M.disasters.value, disaster_model.disasters_array)
def test_plot(self):
if not PLOT:
raise nose.SkipTest
# Plot samples
plot(self.M.early_mean, path=DIR, verbose=0)
def test_autocorrelation(self):
if not PLOT:
raise nose.SkipTest
# Plot samples
autocorrelation(self.M.early_mean, path=DIR, verbose=0)
def test_stats(self):
S = self.M.early_mean.stats()
self.M.stats()
def test_stats_after_reload(self):
db = database.pickle.load('MCMC.pickle')
M2 = MCMC(disaster_model, db=db)
M2.stats()
db.close()
os.remove('MCMC.pickle')
if __name__ == '__main__':
original_filters = warnings.filters[:]
warnings.simplefilter("ignore")
try:
import nose
nose.runmodule()
finally:
warnings.filters = original_filters
# TODO: Restore in 2.2
# with warnings.catch_warnings():
# warnings.simplefilter('ignore', FutureWarning)
# nose.runmodule()
|