def _compute_weights_and_cov(self, pop):
params = np.column_stack(tuple([pop.outputs[p] for p in self.parameter_names]))
if self._populations:
q_logpdf = GMDistribution.logpdf(params, *self._gm_params)
p_logpdf = self._prior.logpdf(params)
w = np.exp(p_logpdf - q_logpdf)
else:
w = np.ones(pop.n_samples)
if np.count_nonzero(w) == 0:
raise RuntimeError("All sample weights are zero. If you are using a prior "
"with a bounded support, this may be caused by specifying "
"a too small sample size.")
# New covariance
cov = 2 * np.diag(weighted_var(params, w))
if not np.all(np.isfinite(cov)):
logger.warning("Could not estimate the sample covariance. This is often "
"caused by majority of the sample weights becoming zero."
"Falling back to using unit covariance.")
cov = np.diag(np.ones(params.shape[1]))
return w, cov
评论列表
文章目录