From 950501578347d5d7b2c759ed837153b6e951dbee Mon Sep 17 00:00:00 2001 From: Minas Karamanis Date: Fri, 14 Jun 2024 08:38:58 +0200 Subject: [PATCH] infinite likelihood fix --- README.md | 2 +- docs/source/index.rst | 6 +++++- pocomc/_version.py | 2 +- pocomc/sampler.py | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84ad3d7..2aa1934 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/source/index.rst b/docs/source/index.rst index a1b04d1..ebfc352 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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 @@ -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. diff --git a/pocomc/_version.py b/pocomc/_version.py index 1350d4e..6654167 100644 --- a/pocomc/_version.py +++ b/pocomc/_version.py @@ -1 +1 @@ -version = "1.2.0" \ No newline at end of file +version = "1.2.1" \ No newline at end of file diff --git a/pocomc/sampler.py b/pocomc/sampler.py index eb3f2eb..0190af3 100644 --- a/pocomc/sampler.py +++ b/pocomc/sampler.py @@ -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,