Skip to content

Commit 6d2aa5d

Browse files
authored
small edits in documentation and messages (#4921)
1 parent 3cb1359 commit 6d2aa5d

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

pymc3/sampling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ def sample(
381381
work better for problematic posteriors
382382
* max_treedepth : The maximum depth of the trajectory tree
383383
* step_scale : float, default 0.25
384-
The initial guess for the step size scaled down by :math:`1/n**(1/4)`
384+
The initial guess for the step size scaled down by :math:`1/n**(1/4)`,
385+
where n is the dimensionality of the parameter space
385386
386387
If your model uses multiple step methods, aka a Compound Step, then you have
387388
two ways to address arguments to each step method:

pymc3/step_methods/arraystep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
@unique
3535
class Competence(IntEnum):
36-
"""Enum for charaterizing competence classes of step methods.
36+
"""Enum for characterizing competence classes of step methods.
3737
Values include:
3838
0: INCOMPATIBLE
3939
1: COMPATIBLE

pymc3/step_methods/hmc/base_hmc.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ def __init__(
6666
6767
Parameters
6868
----------
69-
vars: list of Aesara variables
70-
scaling: array_like, ndim = {1,2}
69+
vars: list, default=None
70+
List of Aesara variables. If None, all continuous RVs from the
71+
model are included.
72+
scaling: array_like, ndim={1,2}
7173
Scaling for momentum distribution. 1d arrays interpreted matrix
7274
diagonal.
7375
step_scale: float, default=0.25
74-
Size of steps to take, automatically scaled down by 1/n**(1/4)
76+
Size of steps to take, automatically scaled down by 1/n**(1/4),
77+
where n is the dimensionality of the parameter space
7578
is_cov: bool, default=False
7679
Treat scaling as a covariance matrix/vector if True, else treat
7780
it as a precision matrix/vector
@@ -134,9 +137,9 @@ def __init__(
134137

135138
@abstractmethod
136139
def _hamiltonian_step(self, start, p0, step_size):
137-
"""Compute one hamiltonian trajectory and return the next state.
140+
"""Compute one Hamiltonian trajectory and return the next state.
138141
139-
Subclasses must overwrite this method and return a `HMCStepData`.
142+
Subclasses must overwrite this abstract method and return an `HMCStepData` object.
140143
"""
141144

142145
def astep(self, q0):

pymc3/step_methods/hmc/hmc.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ def __init__(self, vars=None, path_length=2.0, max_steps=1024, **kwargs):
5959
6060
Parameters
6161
----------
62-
vars: list of Aesara variables
62+
vars: list, default=None
63+
List of Aesara variables. If None, all continuous RVs from the
64+
model are included.
6365
path_length: float, default=2
64-
total length to travel
66+
Total length to travel
6567
step_rand: function float -> float, default=unif
66-
A function which takes the step size and returns an new one used to
67-
randomize the step size at each iteration.
68+
A function which takes the step size and returns a new one used to
69+
randomize the step size at each iteration. The default draws a random
70+
new step size from a uniform distribution with +-15% of the given one.
71+
If set to None, no randomization is done.
6872
step_scale: float, default=0.25
69-
Initial size of steps to take, automatically scaled down
70-
by 1/n**(1/4).
73+
Initial size of steps to take, automatically scaled down by 1/n**(1/4)
74+
where n is the dimensionality of the parameter space
7175
scaling: array_like, ndim = {1,2}
7276
The inverse mass, or precision matrix. One dimensional arrays are
7377
interpreted as diagonal matrices. If `is_cov` is set to True,
@@ -133,7 +137,10 @@ def _hamiltonian_step(self, start, p0, step_size):
133137
energy_change = -np.inf
134138
if np.abs(energy_change) > self.Emax:
135139
div_info = DivergenceInfo(
136-
"Divergence encountered, large integration error.", None, last, state
140+
f"Divergence encountered, energy change larger than {self.Emax}.",
141+
None,
142+
last,
143+
state,
137144
)
138145

139146
accept_stat = min(1, np.exp(energy_change))

pymc3/step_methods/hmc/nuts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def __init__(self, vars=None, max_treedepth=10, early_max_treedepth=8, **kwargs)
114114
115115
Parameters
116116
----------
117-
vars: list of Aesara variables, default all continuous vars
117+
vars: list, default=None
118+
List of Aesara variables. If None, all continuous RVs from the
119+
model are included.
118120
Emax: float, default 1000
119121
Maximum energy change allowed during leapfrog steps. Larger
120122
deviations will abort the integration.
@@ -357,7 +359,7 @@ def _single_step(self, left, epsilon):
357359
)
358360
return tree, None, False
359361
else:
360-
error_msg = "Energy change in leapfrog step is too large: %s." % energy_change
362+
error_msg = f"Energy change in leapfrog step is too large: {energy_change}."
361363
error = None
362364
tree = Subtree(None, None, None, None, -np.inf, -np.inf, 1)
363365
divergance_info = DivergenceInfo(error_msg, error, left, right)

0 commit comments

Comments
 (0)