/usr/share/pyshared/pymc/tests/test_norm_approx.py is in python-pymc 2.2+ds-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 | from pymc import NormApprox
from pymc.examples import gelman_bioassay
try:
from pylab import *
except:
pass
from numpy import *
from numpy.testing import *
from numpy.linalg import cholesky
import nose
PLOT=False
model = gelman_bioassay
class test_norm_approx(TestCase):
@classmethod
def setUpClass(self):
try:
import scipy
except:
raise nose.SkipTest("SciPy not installed.")
def test_fmin(self):
N = NormApprox(model)
N.fit('fmin')
def test_fmin_l_bfgs_b(self):
N = NormApprox(model)
N.fit('fmin_l_bfgs_b')
def test_fmin_ncg(self):
N = NormApprox(model)
N.fit('fmin_ncg')
def test_fmin_cg(self):
N = NormApprox(model)
N.fit('fmin_cg')
def test_fmin_powell(self):
N = NormApprox(model)
N.fit('fmin_powell')
def test_revert(self):
N = NormApprox(model)
N.fit()
max_alpha = N.alpha.value.copy()
N.alpha.random()
N.revert_to_max()
assert_almost_equal(N.alpha.value, max_alpha)
def test_sig(self):
N = NormApprox(model)
N.fit('fmin')
assert((abs(N._sig * N._sig.T - N._C) < 1.0e-14).all())
def test_draws(self):
N = NormApprox(model)
N.fit('fmin')
N.sample(1000)
if PLOT:
plot(N.alpha.trace(),N.beta.trace(),'k.')
xlabel(r'$\alpha$')
ylabel(r'$\beta$')
if __name__=='__main__':
import unittest
unittest.main()
|