From 172c941cabefab0b36f32f3f9e5c13577e26491c Mon Sep 17 00:00:00 2001 From: Jackie Date: Tue, 5 Aug 2025 12:54:59 -0700 Subject: [PATCH] Fix: Handle zero valid samples in importance_reweight to avoid ValueError crash --- src/nbi/engine.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nbi/engine.py b/src/nbi/engine.py index 0faeb9b..5e58a5e 100644 --- a/src/nbi/engine.py +++ b/src/nbi/engine.py @@ -633,6 +633,10 @@ def importance_reweight(self, x_obs, x, y): log_weights = loglike + logprior - logproposal bad = np.isnan(log_weights) + np.isinf(log_weights) + valid_weights = log_weights[~bad] + if len(valid_weights) == 0: + print("All log weights are NaN or Inf — skipping this round!") + return np.zeros_like(log_weights) log_weights -= log_weights[~bad].max() weights = np.exp(log_weights)