Skip to content

Commit b0b56ce

Browse files
committed
Remove weight argument in quadpotential add_sample
1 parent 2f9e5d1 commit b0b56ce

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Diff for: pymc3/step_methods/hmc/quadpotential.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ def __init__(
183183
The number of initial samples that are just discarded and not used to estimate
184184
the mass matrix.
185185
early_update : bool
186-
Whether to update the mass matrix live during the first half of the first
187-
adaptation window.
186+
Whether to update the mass matrix live during the first adaptation window.
188187
store_mass_matrix_trace : bool
189188
If true, store the mass matrix at each step of the adaptation. Only for debugging
190189
purposes.
@@ -268,8 +267,8 @@ def update(self, sample, grad, tune):
268267
return
269268

270269
if self._n_samples > self._discard_window:
271-
self._foreground_var.add_sample(sample, weight=1)
272-
self._background_var.add_sample(sample, weight=1)
270+
self._foreground_var.add_sample(sample)
271+
self._background_var.add_sample(sample)
273272

274273
if self._early_update or self._n_samples > self.adaptation_window:
275274
self._update_from_weightvar(self._foreground_var)
@@ -344,15 +343,13 @@ def __init__(
344343
if self.mean.shape != (nelem,):
345344
raise ValueError("Invalid shape for initial mean.")
346345

347-
def add_sample(self, x, weight):
346+
def add_sample(self, x):
348347
x = np.asarray(x)
349-
if weight != 1:
350-
raise ValueError("Setting weight != 1 is not supported.")
351348
self.n_samples += 1
352349
old_diff = x - self.mean
353350
self.mean[:] += old_diff / self.n_samples
354351
new_diff = x - self.mean
355-
self.raw_var[:] += weight * old_diff * new_diff
352+
self.raw_var[:] += old_diff * new_diff
356353

357354
def current_variance(self, out=None):
358355
if self.n_samples == 0:
@@ -666,8 +663,8 @@ def update(self, sample, grad, tune):
666663
# Steps since previous update
667664
delta = self._n_samples - self._previous_update
668665

669-
self._foreground_cov.add_sample(sample, weight=1)
670-
self._background_cov.add_sample(sample, weight=1)
666+
self._foreground_cov.add_sample(sample)
667+
self._background_cov.add_sample(sample)
671668

672669
# Update the covariance matrix and recompute the Cholesky factorization
673670
# every "update_window" steps
@@ -726,13 +723,13 @@ def __init__(
726723
if self.mean.shape != (nelem,):
727724
raise ValueError("Invalid shape for initial mean.")
728725

729-
def add_sample(self, x, weight):
726+
def add_sample(self, x):
730727
x = np.asarray(x)
731728
self.n_samples += 1
732729
old_diff = x - self.mean
733730
self.mean[:] += old_diff / self.n_samples
734731
new_diff = x - self.mean
735-
self.raw_cov[:] += weight * new_diff[:, None] * old_diff[None, :]
732+
self.raw_cov[:] += new_diff[:, None] * old_diff[None, :]
736733

737734
def current_covariance(self, out=None):
738735
if self.n_samples == 0:

Diff for: pymc3/tests/test_quadpotential.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_weighted_covariance(ndim=10, seed=5432):
169169

170170
est = quadpotential._WeightedCovariance(ndim)
171171
for sample in samples:
172-
est.add_sample(sample, 1)
172+
est.add_sample(sample)
173173
mu_est = est.current_mean()
174174
cov_est = est.current_covariance()
175175

@@ -184,7 +184,7 @@ def test_weighted_covariance(ndim=10, seed=5432):
184184
10,
185185
)
186186
for sample in samples[10:]:
187-
est2.add_sample(sample, 1)
187+
est2.add_sample(sample)
188188
mu_est2 = est2.current_mean()
189189
cov_est2 = est2.current_covariance()
190190

0 commit comments

Comments
 (0)