tensorflow / tensorflow/probability
Mixture model (Zero-inflated) gives nan log-probablity at 0
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
To reproduce the result:
import tensorflow_probability as tfp
tfd = tfp.distributions
# Zero inflated log-normal
ziln = tfd.Mixture(
cat=tfd.Categorical(probs=[0.9, 0.1]),
components=[
tfd.Deterministic(loc=0),
tfd.LogNormal(loc=6, scale=1),
])
print(ziln.log_prob(0))
# Expected output: log(0.9)
# Output: nan
print(ziln.log_prob(1))
# Expected output: -21.221523
# Output: -21.221523
I think the log_prob should be
if x == 0:
log(0.9)
if x >0:
log(0.1 * lognormal.pdf(x))
Source code of mixture model log_prob:
def _log_prob(self, x):
x = tf.convert_to_tensor(x, name='x')
distribution_log_probs = [d.log_prob(x) for d in self.components]
cat_log_probs = self._cat_probs(log_probs=True)
final_log_probs = [
cat_lp + d_lp
for (cat_lp, d_lp) in zip(cat_log_probs, distribution_log_probs)
]
concat_log_probs = tf.stack(final_log_probs, 0)
log_sum_exp = tf.reduce_logsumexp(concat_log_probs, axis=[0])
return log_sum_exp
Now the mixture model assumes the same x is always in the support of all the distribution components, hence having a non-nan log_prob. It cannot handle cases like zero-inflated gamma / log-normal where the continuous distribution has support (0, inf).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Mixture._log_prob implementation shown in the issue and run the zero-inflated LogNormal reproduction. Check how out-of-support component log probabilities affect the combined result; done means the two reported inputs return the expected finite log probabilities without breaking ordinary mixture cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- backend, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100