tensorflow / tensorflow/probability
Distributions are not independent for Empirical
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
While the documentation states that
The first k dimensions index into a batch of independent distributions
this is not the case for the implementation.
As can be seen from this MWE, the samples for every distribution are always the same:
import numpy as np
import tensorflow_probability as tfp
a = np.random.randint(0, 100, size=1000)
dist = tfp.distributions.Empirical([a, a])
n = 3
dist.sample(n)
# output
# <tf.Tensor: shape=(3, 2), dtype=int32, numpy=
# array([[66, 66],
# [33, 33],
# [98, 98]], dtype=int32)>
The root cause seems to be at this location, where indices are sampled only once but re-used for every distribution:
https://github.com/tensorflow/probability/blob/fbc5ebe9b1d343113fb917010096cfd88b32eecf/tensorflow_probability/python/distributions/empirical.py#L236-L238
I now fear that there might be more issues in the implementation of Empirical, rendering it unusable in contexts where I require independency between distributions.
Also the shaping of the output seems strange, which is (n, k), while I would expect it to be (k, n).
Maybe I also completely misunderstood the documentation.
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 tensorflow_probability/python/distributions/empirical.py at the referenced lines 236-238, then run the Python MWE to inspect how samples are produced for batched Empirical distributions. Check the documented independence and output-shape expectations against the observed results; done means the behavior and its tests agree with the documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100