Skip to content

Commit

Permalink
Refactor log_prob method in _MixtureBase class to handle negative inf…
Browse files Browse the repository at this point in the history
…inity values in sum_log_probs (#1874)
  • Loading branch information
Qazalbash authored Oct 4, 2024
1 parent 8e9313f commit 0791b1f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion numpyro/distributions/mixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def sample(self, key, sample_shape=()):
def log_prob(self, value, intermediates=None):
del intermediates
sum_log_probs = self.component_log_probs(value)
return jax.nn.logsumexp(sum_log_probs, axis=-1)
safe_sum_log_probs = jnp.where(
jnp.isneginf(sum_log_probs), -jnp.inf, sum_log_probs
)
return jax.nn.logsumexp(safe_sum_log_probs, axis=-1)


class MixtureSameFamily(_MixtureBase):
Expand Down

0 comments on commit 0791b1f

Please sign in to comment.