Skip to content

Commit 71361bf

Browse files
committed
stabilize covariance
1 parent 187028d commit 71361bf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: pymc3/step_methods/smc_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ def _calc_covariance(posterior, weights):
4444
Calculate trace covariance matrix based on importance weights.
4545
"""
4646
cov = np.cov(posterior, aweights=weights.ravel(), bias=False, rowvar=0)
47+
cov = np.atleast_2d(cov)
48+
cov += 1e-6 * np.eye(cov.shape[0])
4749
if np.isnan(cov).any() or np.isinf(cov).any():
4850
raise ValueError('Sample covariances not valid! Likely "draws" is too small!')
49-
return np.atleast_2d(cov)
51+
return cov
5052

5153

5254
def _tune(acc_rate, proposed, step):

0 commit comments

Comments
 (0)