@@ -155,11 +155,40 @@ def __init__(
155
155
adaptation_window_multiplier = 1 ,
156
156
dtype = None ,
157
157
discard_window = 50 ,
158
- initial_weights = None ,
159
158
early_update = False ,
160
159
store_mass_matrix_trace = False ,
161
160
):
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
+ """
163
192
if initial_diag is not None and initial_diag .ndim != 1 :
164
193
raise ValueError ("Initial diagonal must be one-dimensional." )
165
194
if initial_mean .ndim != 1 :
@@ -191,8 +220,6 @@ def __init__(
191
220
self ._store_mass_matrix_trace = store_mass_matrix_trace
192
221
self ._mass_trace = []
193
222
194
- self ._initial_weights = initial_weights
195
-
196
223
self .reset ()
197
224
198
225
def reset (self ):
@@ -366,6 +393,34 @@ def current_mean(self, out=None):
366
393
367
394
class QuadPotentialDiagAdaptExp (QuadPotentialDiagAdapt ):
368
395
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
+
369
424
super ().__init__ (* args , ** kwargs )
370
425
self ._alpha = alpha
371
426
self ._use_grads = use_grads
@@ -411,10 +466,8 @@ def update(self, sample, grad, tune):
411
466
def _update_from_variances (self , var_estimator , inv_var_estimator ):
412
467
var = var_estimator .current_variance ()
413
468
inv_var = inv_var_estimator .current_variance ()
414
- # print(inv_var)
415
469
updated = np .sqrt (var / inv_var )
416
470
self ._var [:] = updated
417
- # updated = np.exp((np.log(var) - np.log(inv_var)) / 2)
418
471
np .sqrt (updated , out = self ._stds )
419
472
np .divide (1 , self ._stds , out = self ._inv_stds )
420
473
0 commit comments