Skip to content

Commit cad059e

Browse files
author
Christopher Fonnesbeck
committed
Moved tests into pymc/ and made them easily runnable as a batch
1 parent 3761025 commit cad059e

12 files changed

+30
-27
lines changed

pymc/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from core import *
1+
from core import *
22
from distributions import *
3-
from math import *
3+
from math import *
44

55
from trace import *
6-
from sample import *
6+
from sample import *
77
from step_methods import *
88
from tuning import *
99

10-
from debug import *
10+
from debug import *
1111

1212
from plots import *
13+
14+
from .tests import test

pymc/tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from test_examples import *
2+
3+
from numpy.testing import Tester
4+
5+
test = Tester().test
File renamed without changes.
File renamed without changes.

tests/test_distributions.py renamed to pymc/tests/test_distributions.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import itertools as its
2-
from checks import *
2+
from checks import *
33
from pymc import *
44
from numpy import array, inf
55

@@ -70,17 +70,17 @@ def test_constantdist():
7070

7171
def test_zeroinflatedpoisson():
7272
checkd(ZeroInflatedPoisson, I, {'theta' : Rplus, 'z' : Bool})
73-
73+
7474

7575
def test_densitydist():
7676
def logp(x):
7777
return -log(2*.5) - abs(x-.5)/.5
78-
78+
7979
checkd(DensityDist,R, {}, extra_args = {'logp' : logp})
8080

8181

8282
def test_addpotential():
83-
with Model() as model:
83+
with Model() as model:
8484
x = Normal('x', 1,1)
8585
model.AddPotential(-x**2)
8686

@@ -89,10 +89,10 @@ def test_addpotential():
8989

9090
def checkd(distfam, valuedomain, vardomains, check_int = True, check_der = True, extra_args = {}):
9191

92-
with Model() as m:
92+
with Model() as m:
9393
vars = dict((v , Flat(v, dtype = dom.dtype)) for v,dom in vardomains.iteritems())
9494
vars.update(extra_args)
95-
print vars
95+
# print vars
9696
value = distfam('value', testval = valuedomain[len(valuedomain)//2], **vars)
9797

9898
vardomains['value'] = np.array(valuedomain)
@@ -101,13 +101,13 @@ def checkd(distfam, valuedomain, vardomains, check_int = True, check_der = True,
101101

102102
if check_int:
103103
check_int_to_1(m, value, domains)
104-
if check_der:
104+
if check_der:
105105
check_dlogp(m, value, domains)
106106

107-
108-
def check_int_to_1(model, value, domains):
107+
108+
def check_int_to_1(model, value, domains):
109109
pdf = compilef(exp(model.logp))
110-
110+
111111
lower, upper = np.min(domains[-1]), np.max(domains[-1])
112112

113113
domains = [d[1:-1] for d in domains[:-1]]
@@ -118,28 +118,28 @@ def check_int_to_1(model, value, domains):
118118
pt = Point(dict( (str(var), val) for var,val in zip(model.vars, a)), model = model)
119119

120120
bij = DictToVarBijection(value,() , pt)
121-
121+
122122
pdfx = bij.mapf(pdf)
123-
123+
124124
if value.dtype in continuous_types:
125125
area = integrate.quad(pdfx, lower, upper, epsabs = 1e-8)[0]
126-
else:
126+
else:
127127
area = np.sum(map(pdfx, np.arange(lower, upper + 1)))
128128

129129
assert_almost_equal(area, 1, err_msg = str(pt))
130130

131131

132-
def check_dlogp(model, value, domains):
132+
def check_dlogp(model, value, domains):
133133

134134
domains = [d[1:-1] for d in domains]
135135
bij = DictToArrayBijection(ArrayOrdering(model.cont_vars), model.test_point)
136136

137137
if not model.cont_vars:
138-
return
138+
return
139139

140140
dlp = model.dlogpc()
141141
dlogp = bij.mapf(model.dlogpc())
142-
142+
143143
lp = model.logpc
144144
logp = bij.mapf(model.logpc)
145145
ndlogp = Gradient(logp)

tests/test_examples.py renamed to pymc/tests/test_examples.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import matplotlib
2-
matplotlib.use('Agg')
3-
41
from os import path
5-
import os
2+
import os
63
import fnmatch
74
import imp
85

9-
def test_examples():
6+
def test_examples():
107

118
for path in all_matching_files(example_dir(), '*.py'):
129
yield check_example, path
@@ -18,7 +15,7 @@ def addfiles(fls, dir, nfiles):
1815
nfiles = fnmatch.filter(nfiles, pattern)
1916
nfiles = [path.join(dir,f) for f in nfiles]
2017
fls.extend(nfiles)
21-
18+
2219
files = []
2320
path.walk(d, addfiles, files)
2421
return files
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)