Skip to content

Commit

Permalink
Merge pull request #47 from minaskar/dev
Browse files Browse the repository at this point in the history
infinite likelihood fix
  • Loading branch information
minaskar authored Jun 14, 2024
2 parents a56b53d + 9505015 commit 6d63137
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the Preconditioned Monte Carlo (PMC) algorithm, offering significant speed impro
traditional methods like MCMC and Nested Sampling. Ideal for large-scale scientific problems
with expensive likelihood evaluations, non-linear correlations, and multimodality, ``pocoMC``
provides efficient and scalable posterior sampling and model evidence estimation. Widely used
in cosmology and astronomy, pocoMC is user-friendly, flexible, and actively maintained.
in cosmology and astronomy, ``pocoMC`` is user-friendly, flexible, and actively maintained.

## Documentation

Expand Down
6 changes: 5 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
traditional methods like MCMC and Nested Sampling. Ideal for large-scale scientific problems
with expensive likelihood evaluations, non-linear correlations, and multimodality, ``pocoMC``
provides efficient and scalable posterior sampling and model evidence estimation. Widely used
in cosmology and astronomy, pocoMC is user-friendly, flexible, and actively maintained.
in cosmology and astronomy, ``pocoMC`` is user-friendly, flexible, and actively maintained.

.. admonition:: Where to start?
:class: tip
Expand Down Expand Up @@ -114,6 +114,10 @@ Copyright 2022-2024 Minas Karamanis and contributors.
Changelog
=========

**1.2.1 (14/06/24)**

- Added support for log-likelihoods that return ``-np.inf`` inside the prior volume.

**1.2.0 (11/06/24)**

- Added ``MPIPool`` for parallelization.
Expand Down
2 changes: 1 addition & 1 deletion pocomc/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.2.0"
version = "1.2.1"
15 changes: 15 additions & 0 deletions pocomc/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ def run(self,
logl, blobs = self._log_like(x)
self.calls += self.n_active

# Resample prior particles with infinite likelihoods
inf_logl_mask = np.isinf(logl)
if np.any(inf_logl_mask):
all_idx = np.arange(len(x))
infinite_idx = all_idx[inf_logl_mask]
finite_idx = all_idx[~inf_logl_mask]
idx = np.random.choice(finite_idx, size=len(infinite_idx), replace=True)
x[infinite_idx] = x[idx]
u[infinite_idx] = u[idx]
logdetj[infinite_idx] = logdetj[idx]
logp[infinite_idx] = logp[idx]
logl[infinite_idx] = logl[idx]
if self.have_blobs:
blobs[infinite_idx] = blobs[idx]

self.current_particles = dict(u=u,x=x,logl=logl,logp=logp,logdetj=logdetj,
logw=-1e300 * np.ones(self.n_active), blobs=blobs, iter=self.t,
calls=self.calls, steps=1, efficiency=1.0, ess=self.n_effective,
Expand Down

0 comments on commit 6d63137

Please sign in to comment.