Skip to content

Commit 4812b63

Browse files
canyon289Spaak
authored andcommitted
Add deterministic test
1 parent 4ef4f97 commit 4812b63

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pymc3/tests/test_model.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import theano
1717
import theano.tensor as tt
1818
import numpy as np
19+
import pickle
1920
import pandas as pd
2021
import numpy.testing as npt
2122
import unittest
@@ -423,21 +424,24 @@ def test_tempered_logp_dlogp():
423424
npt.assert_allclose(func_temp_nograd(x), func_temp(x)[0])
424425

425426

426-
import pickle
427427
def test_model_pickle(tmpdir):
428428
"""Tests that PyMC3 models are pickleable"""
429+
with pm.Model() as model:
430+
x = pm.Normal('x')
431+
pm.Normal('y', observed=1)
432+
433+
file_path = tmpdir.join("model.p")
434+
with open(file_path, 'wb') as buff:
435+
pickle.dump(model, buff)
429436

430-
# Data of the Eight Schools Model
431-
J = 8
432-
y = np.array([28., 8., -3., 7., -1., 1., 18., 12.])
433-
sigma = np.array([15., 10., 16., 11., 9., 11., 10., 18.])
434437

438+
def test_model_pickle_deterministic(tmpdir):
439+
"""Tests that PyMC3 models are pickleable"""
435440
with pm.Model() as model:
436-
mu = pm.Normal('mu', mu=0, sigma=5)
437-
tau = pm.HalfCauchy('tau', beta=5)
438-
theta = pm.Normal('theta', mu=mu, sigma=tau, shape=J)
439-
obs = pm.Normal('obs', mu=theta, sigma=sigma, observed=y)
440-
# t = pm.sample(draws=100)
441+
x = pm.Normal('x')
442+
z = pm.Normal("z")
443+
pm.Deterministic("w", x/z)
444+
pm.Normal('y', observed=1)
441445

442446
file_path = tmpdir.join("model.p")
443447
with open(file_path, 'wb') as buff:

0 commit comments

Comments
 (0)