Skip to content

Commit

Permalink
stabilize covariance
Browse files Browse the repository at this point in the history
  • Loading branch information
aloctavodia committed Jul 30, 2019
1 parent 0ea44a4 commit 31269b2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pymc3/step_methods/smc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def _calc_covariance(posterior, weights):
Calculate trace covariance matrix based on importance weights.
"""
cov = np.cov(posterior, aweights=weights.ravel(), bias=False, rowvar=0)
cov = np.atleast_2d(cov)
cov += 1e-6 * np.eye(cov.shape[0])
if np.isnan(cov).any() or np.isinf(cov).any():
raise ValueError('Sample covariances not valid! Likely "draws" is too small!')
return np.atleast_2d(cov)
return cov


def _tune(acc_rate, proposed, step):
Expand Down

0 comments on commit 31269b2

Please sign in to comment.