Skip to content

Commit ad777b1

Browse files
committed
Add docstrings for quadpotential
1 parent d2684c0 commit ad777b1

File tree

1 file changed

+59
-6
lines changed

1 file changed

+59
-6
lines changed

pymc3/step_methods/hmc/quadpotential.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,40 @@ def __init__(
155155
adaptation_window_multiplier=1,
156156
dtype=None,
157157
discard_window=50,
158-
initial_weights=None,
159158
early_update=False,
160159
store_mass_matrix_trace=False,
161160
):
162-
"""Set up a diagonal mass matrix."""
161+
"""Set up a diagonal mass matrix.
162+
163+
Parameters
164+
----------
165+
n : int
166+
The number of parameters.
167+
initial_mean : np.ndarray
168+
An initial guess for the posterior mean of each parameter.
169+
initial_diag : np.ndarray
170+
An estimate of the posterior variance of each parameter.
171+
initial_weight : int
172+
How much weight the initial guess has compared to new samples during tuning.
173+
Measured in equivalent number of samples.
174+
adaptation_window : int
175+
The size of the adaptation window during tuning. It specifies how many samples
176+
are used to estimate the mass matrix in each section of the adaptation.
177+
adaptation_window_multiplier : float
178+
The factor with which we increase the adaptation window after each adaptation
179+
window.
180+
dtype : np.dtype
181+
The dtype used to store the mass matrix
182+
discard_window : int
183+
The number of initial samples that are just discarded and not used to estimate
184+
the mass matrix.
185+
early_update : bool
186+
Whether to update the mass matrix live during the first half of the first
187+
adaptation window.
188+
store_mass_matrix_trace : bool
189+
If true, store the mass matrix at each step of the adaptation. Only for debugging
190+
purposes.
191+
"""
163192
if initial_diag is not None and initial_diag.ndim != 1:
164193
raise ValueError("Initial diagonal must be one-dimensional.")
165194
if initial_mean.ndim != 1:
@@ -191,8 +220,6 @@ def __init__(
191220
self._store_mass_matrix_trace = store_mass_matrix_trace
192221
self._mass_trace = []
193222

194-
self._initial_weights = initial_weights
195-
196223
self.reset()
197224

198225
def reset(self):
@@ -366,6 +393,34 @@ def current_mean(self, out=None):
366393

367394
class QuadPotentialDiagAdaptExp(QuadPotentialDiagAdapt):
368395
def __init__(self, *args, alpha, use_grads=False, stop_adaptation=None, **kwargs):
396+
"""Set up a diagonal mass matrix.
397+
398+
Parameters
399+
----------
400+
n : int
401+
The number of parameters.
402+
initial_mean : np.ndarray
403+
An initial guess for the posterior mean of each parameter.
404+
initial_diag : np.ndarray
405+
An estimate of the posterior variance of each parameter.
406+
alpha : float
407+
Decay rate of the exponetial weighted variance.
408+
use_grads : bool
409+
Use gradients, not only samples to estimate the mass matrix.
410+
stop_adaptation : int
411+
Stop the mass matrix adaptation after this many samples.
412+
dtype : np.dtype
413+
The dtype used to store the mass matrix
414+
discard_window : int
415+
The number of initial samples that are just discarded and not used to estimate
416+
the mass matrix.
417+
store_mass_matrix_trace : bool
418+
If true, store the mass matrix at each step of the adaptation. Only for debugging
419+
purposes.
420+
"""
421+
if len(args) > 3:
422+
raise ValueError("Unsupported arguments to QuadPotentialDiagAdaptExp")
423+
369424
super().__init__(*args, **kwargs)
370425
self._alpha = alpha
371426
self._use_grads = use_grads
@@ -411,10 +466,8 @@ def update(self, sample, grad, tune):
411466
def _update_from_variances(self, var_estimator, inv_var_estimator):
412467
var = var_estimator.current_variance()
413468
inv_var = inv_var_estimator.current_variance()
414-
# print(inv_var)
415469
updated = np.sqrt(var / inv_var)
416470
self._var[:] = updated
417-
# updated = np.exp((np.log(var) - np.log(inv_var)) / 2)
418471
np.sqrt(updated, out=self._stds)
419472
np.divide(1, self._stds, out=self._inv_stds)
420473

0 commit comments

Comments
 (0)