Skip to content

Commit 140a80c

Browse files
colintwiecki
colin
authored andcommitted
Reformat docs
1 parent ea82ebd commit 140a80c

File tree

5 files changed

+70
-69
lines changed

5 files changed

+70
-69
lines changed

pymc3/step_methods/hmc/base_hmc.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ class BaseHMC(ArrayStepShared):
1212

1313
def __init__(self, vars=None, scaling=None, step_scale=0.25, is_cov=False,
1414
model=None, blocked=True, use_single_leapfrog=False, **theano_kwargs):
15-
"""
15+
"""Superclass to implement Hamiltonian/hybrid monte carlo
16+
1617
Parameters
1718
----------
18-
vars : list of theano variables
19-
scaling : array_like, ndim = {1,2}
20-
Scaling for momentum distribution. 1d arrays interpreted matrix diagonal.
21-
step_scale : float, default=0.25
22-
Size of steps to take, automatically scaled down by 1/n**(1/4)
23-
is_cov : bool, default=False
24-
Treat scaling as a covariance matrix/vector if True, else treat it as a
25-
precision matrix/vector
26-
state
27-
State object
28-
model : pymc3 Model instance. default=Context model
29-
blocked: Boolean, default True
30-
use_single_leapfrog: Boolean, will leapfrog steps take a single step at a time.
31-
default False.
32-
**theano_kwargs: passed to theano functions
19+
vars : list of theano variables
20+
scaling : array_like, ndim = {1,2}
21+
Scaling for momentum distribution. 1d arrays interpreted matrix diagonal.
22+
step_scale : float, default=0.25
23+
Size of steps to take, automatically scaled down by 1/n**(1/4)
24+
is_cov : bool, default=False
25+
Treat scaling as a covariance matrix/vector if True, else treat it as a
26+
precision matrix/vector
27+
state
28+
State object
29+
model : pymc3 Model instance. default=Context model
30+
blocked: Boolean, default True
31+
use_single_leapfrog: Boolean, will leapfrog steps take a single step at a time.
32+
default False.
33+
**theano_kwargs: passed to theano functions
3334
"""
3435
model = modelcontext(model)
3536

pymc3/step_methods/hmc/hmc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def __init__(self, vars=None, path_length=2., step_rand=unif, **kwargs):
2727
"""
2828
Parameters
2929
----------
30-
vars : list of theano variables
31-
path_length : float, default=2
32-
total length to travel
33-
step_rand : function float -> float, default=unif
34-
A function which takes the step size and returns an new one used to
35-
randomize the step size at each iteration.
36-
**kwargs : passed to BaseHMC
30+
vars : list of theano variables
31+
path_length : float, default=2
32+
total length to travel
33+
step_rand : function float -> float, default=unif
34+
A function which takes the step size and returns an new one used to
35+
randomize the step size at each iteration.
36+
**kwargs : passed to BaseHMC
3737
"""
3838
super(HamiltonianMC, self).__init__(vars, **kwargs)
3939
self.path_length = path_length

pymc3/step_methods/hmc/nuts.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ def __init__(self, vars=None, Emax=1000, target_accept=0.8,
2828
"""
2929
Parameters
3030
----------
31-
vars : list of Theano variables, default continuous vars
32-
Emax : float, default 1000
33-
maximum energy
34-
target_accept : float (0,1) default .8
35-
target for avg accept probability between final branch and initial position
36-
gamma : float, default .05
37-
k : float (.5,1) default .75
38-
scaling of speed of adaptation
39-
t0 : int, default 10
40-
slows inital adapatation
41-
kwargs: passed to BaseHMC
31+
vars : list of Theano variables, default continuous vars
32+
Emax : float, default 1000
33+
maximum energy
34+
target_accept : float (0,1) default .8
35+
target for avg accept probability between final branch and initial position
36+
gamma : float, default .05
37+
k : float (.5,1) default .75
38+
scaling of speed of adaptation
39+
t0 : int, default 10
40+
slows inital adapatation
41+
kwargs: passed to BaseHMC
4242
"""
4343
super(NUTS, self).__init__(vars, use_single_leapfrog=True, **kwargs)
4444

pymc3/step_methods/hmc/quadpotential.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ def quad_potential(C, is_cov, as_cov):
1414
"""
1515
Parameters
1616
----------
17-
C : arraylike, 0 <= ndim <= 2
18-
scaling matrix for the potential
19-
vector treated as diagonal matrix
20-
is_cov : Boolean
21-
whether C is provided as a covariance matrix or hessian
22-
as_cov : Boolean
23-
whether the random draws should come from the normal dist
24-
using the covariance matrix above or the inverse
17+
C : arraylike, 0 <= ndim <= 2
18+
scaling matrix for the potential
19+
vector treated as diagonal matrix
20+
is_cov : Boolean
21+
whether C is provided as a covariance matrix or hessian
22+
as_cov : Boolean
23+
whether the random draws should come from the normal dist
24+
using the covariance matrix above or the inverse
2525
2626
Returns
2727
-------
28-
q : Quadpotential
28+
q : Quadpotential
2929
"""
3030

3131
if issparse(C) and is_cov != as_cov:

pymc3/step_methods/hmc/trajectory.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ def _theano_hamiltonian(model_vars, shared, logpt, potential):
1414
1515
Parameters
1616
----------
17-
model_vars: array of variables to be sampled
18-
shared theano tensors that are already shared
19-
logpt: model log probability
20-
potential: hamiltonian potential
17+
model_vars : array of variables to be sampled
18+
shared : theano tensors that are already shared
19+
logpt : model log probability
20+
potential : hamiltonian potential
2121
2222
Returns
2323
-------
24-
Hamiltonian: namedtuple with log pdf, gradient of log pdf, and potential functions
25-
q: Starting position variable.
24+
Hamiltonian : namedtuple with log pdf, gradient of log pdf, and potential functions
25+
q : Starting position variable.
2626
"""
2727
dlogp = gradient(logpt, model_vars)
2828
(logp, dlogp), q = join_nonshared_inputs([logpt, dlogp], model_vars, shared)
@@ -36,14 +36,14 @@ def _theano_energy_function(H, q, **theano_kwargs):
3636
3737
Parameters
3838
----------
39-
H: Hamiltonian namedtuple
40-
q: theano variable, starting position
41-
theano_kwargs: passed to theano.function
39+
H : Hamiltonian namedtuple
40+
q : theano variable, starting position
41+
theano_kwargs : passed to theano.function
4242
4343
Returns
4444
-------
45-
energy_function: theano function that computes the energy at a point (p, q) in phase space
46-
p: Starting momentum variable.
45+
energy_function : theano function that computes the energy at a point (p, q) in phase space
46+
p : Starting momentum variable.
4747
"""
4848
p = tt.dvector('p')
4949
p.tag.test_value = q.tag.test_value
@@ -91,19 +91,19 @@ def get_theano_hamiltonian_functions(model_vars, shared, logpt, potential,
9191
Parameters
9292
----------
9393
model_vars : array of variables to be sampled
94-
shared theano tensors that are already shared
95-
logpt: model log probability
96-
potential: hamiltonian potential
94+
shared : theano tensors that are already shared
95+
logpt : model log probability
96+
potential : Hamiltonian potential
9797
theano_kwargs : dictionary of keyword arguments to pass to theano functions
98-
use_single_leapfrog: Boolean, if only 1 integration step is done at a time (as in NUTS),
99-
this provides a ~2x speedup
98+
use_single_leapfrog : Boolean, if only 1 integration step is done at a time (as in NUTS),
99+
this provides a ~2x speedup
100100
101101
Returns
102102
-------
103-
H: Hamiltonian namedtuple
104-
energy_function: theano function computing energy at a point in phase space
105-
leapfrog_integrator: theano function integrating the Hamiltonian from a point in phase space
106-
theano_variables: dictionary of variables used in the computation graph which may be useful
103+
H : Hamiltonian namedtuple
104+
energy_function : theano function computing energy at a point in phase space
105+
leapfrog_integrator : theano function integrating the Hamiltonian from a point in phase space
106+
theano_variables : dictionary of variables used in the computation graph which may be useful
107107
"""
108108
H, q = _theano_hamiltonian(model_vars, shared, logpt, potential)
109109
energy_function, p = _theano_energy_function(H, q, **theano_kwargs)
@@ -137,18 +137,18 @@ def leapfrog(H, q, p, epsilon, n_steps):
137137
----------
138138
H : Hamiltonian instance.
139139
Tuple of `logp, dlogp, potential`.
140-
q: Theano.tensor
140+
q : Theano.tensor
141141
initial position vector
142-
p: Theano.tensor
142+
p : Theano.tensor
143143
initial momentum vector
144-
epsilon: float, step size
145-
n_steps: int, number of iterations
144+
epsilon : float, step size
145+
n_steps : int, number of iterations
146146
147147
Returns
148148
-------
149-
position: Theano.tensor
149+
position : Theano.tensor
150150
position estimate at time :math:`n \cdot e`.
151-
momentum: Theano.tensor
151+
momentum : Theano.tensor
152152
momentum estimate at time :math:`n \cdot e`.
153153
"""
154154
def full_update(p, q):

0 commit comments

Comments
 (0)