Skip to content

Commit 3004bd1

Browse files
author
Christopher Fonnesbeck
committed
Added slice sampler to test_step
1 parent 744cb36 commit 3004bd1

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

pymc/sample.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def sample(draws, step, start=None, trace=None, track_progress=True, model=None)
1717
Parameters
1818
----------
1919
20-
model : Model (optional if in `with` context)
2120
draws : int
2221
The number of samples to draw
2322
step : function
@@ -26,8 +25,9 @@ def sample(draws, step, start=None, trace=None, track_progress=True, model=None)
2625
Starting point in parameter space (Defaults to trace.point(-1))
2726
trace : NpTrace
2827
A trace of past values (defaults to None)
29-
track : list of vars
30-
The variables to follow
28+
track_progress : bool
29+
Flag for progress bar
30+
model : Model (optional if in `with` context)
3131
3232
Examples
3333
--------

pymc/tests/models.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
from pymc import Model, Normal, Metropolis
2-
import numpy as np
2+
import numpy as np
33
import pymc as pm
44

5-
def simple_init():
6-
start, model, moments = simple_model()
7-
8-
step = Metropolis(model.vars, np.diag([1.]), model = model)
9-
return model, start, step, moments
10-
11-
125
def simple_model():
136
mu = -2.1
147
tau = 1.3
@@ -17,6 +10,12 @@ def simple_model():
1710

1811
return model.test_point, model, (mu, tau**-1)
1912

13+
def simple_init():
14+
start, model, moments = simple_model()
15+
16+
step = Metropolis(model.vars, np.diag([1.]), model = model)
17+
return model, start, step, moments
18+
2019
def simple_2model():
2120
mu = -2.1
2221
tau = 1.3
@@ -34,7 +33,7 @@ def mv_simple():
3433
[.05 , .1, 0],
3534
[1. ,-0.05,5.5]])
3635

37-
tau = np.dot(p,p.T)
36+
tau = np.dot(p,p.T)
3837

3938

4039
with pm.Model() as model:

pymc/tests/test_step.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from checks import *
2-
from models import simple_model, mv_simple
1+
from .checks import *
2+
from .models import simple_model, mv_simple
33
from theano.tensor import constant
44
from scipy.stats.mstats import moment
55

@@ -11,8 +11,8 @@ def check_stat(name, trace, var, stat, value, bound):
1111
def test_step_continuous():
1212
start, model, (mu, C) = mv_simple()
1313

14-
hmc = pm.HamiltonianMC(model.vars, C, is_cov = True, model = model)
15-
mh = pm.Metropolis(model.vars , C, is_cov = True, scaling = 2, model = model)
14+
hmc = pm.HamiltonianMC(model.vars, C, is_cov=True, model=model)
15+
mh = pm.Metropolis(model.vars, model=model)
1616
slicer = pm.Slice(model.vars, model=model)
1717
compound = pm.CompoundStep([hmc, mh])
1818

@@ -25,9 +25,9 @@ def test_step_continuous():
2525

2626
for st in steps:
2727
np.random.seed(1)
28-
h = sample(8000, st, start, track_progress=False, model = model)
28+
h = sample(8000, st, start, model=model)
2929
for (var, stat, val, bound) in check:
3030
np.random.seed(1)
31-
h = sample(8000, st, start, track_progess=False, model = model)
31+
h = sample(8000, st, start, model=model)
3232

3333
yield check_stat,repr(st), h, var, stat, val, bound

0 commit comments

Comments
 (0)