Skip to content

Commit

Permalink
Added multiple step methods to TestSampleEstimates
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Fonnesbeck committed Oct 3, 2016
1 parent 619d543 commit 311f5d8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pymc3/tests/test_step.py
Expand Up @@ -125,17 +125,19 @@ def test_parameter_estimate(self):
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2
Y = alpha_true + beta_true[0] * X1 + beta_true[1] * X2 + np.random.randn(size) * sigma_true

with Model() as model:
alpha = Normal('alpha', mu=0, sd=10)
beta = Normal('beta', mu=0, sd=10, shape=2)
sigma = Uniform('sigma', lower=0.0, upper=1.0)
mu = alpha + beta[0]*X1 + beta[1]*X2
Y_obs = Normal('Y_obs', mu=mu, sd=sigma, observed=Y)

with step_method in (NUTS(), Metropolis(), Slice()):

with Model() as model:
alpha = Normal('alpha', mu=0, sd=10)
beta = Normal('beta', mu=0, sd=10, shape=2)
sigma = Uniform('sigma', lower=0.0, upper=1.0)
mu = alpha + beta[0]*X1 + beta[1]*X2
Y_obs = Normal('Y_obs', mu=mu, sd=sigma, observed=Y)

trace = sample(1000)
trace = sample(1000, step=step_method)


assert np.isclose(np.median(trace.beta, 0), beta_true, rtol=0.1).all()
assert np.isclose(np.median(trace.alpha), alpha_true, rtol=0.1)
assert np.isclose(np.median(trace.sigma), sigma_true, rtol=0.1)
assert np.isclose(np.median(trace.beta, 0), beta_true, rtol=0.1).all()
assert np.isclose(np.median(trace.alpha), alpha_true, rtol=0.1)
assert np.isclose(np.median(trace.sigma), sigma_true, rtol=0.1)

0 comments on commit 311f5d8

Please sign in to comment.