tensorflow / tensorflow/probability
Sampling from a categorical distribution without replacement
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
As discussed in https://github.com/tensorflow/tensorflow/issues/9260 this issue probably belongs here:
Both tf.multinomial() and tf.contrib.distributions.Categorical.sample() allow to sample from a multinomial distribution. However, they only allow sampling with replacement.
In constrast, Numpy's numpy.random.choice() has a replace parameter that allows sampling without replacement. Would it be possible to add a similar functionality to TensorFlow?
In particular, the proposal is to implement it with Gumbel-max trick: https://github.com/tensorflow/tensorflow/issues/9260#issuecomment-408950922 Corresponding implementation in PyTorch: https://github.com/pytorch/pytorch/commit/af05158c56af29e062580f458a86a32b8f4c2b85
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 tf.multinomial() and tf.contrib.distributions.Categorical.sample(), then review the linked TensorFlow discussion and the PyTorch implementation of the Gumbel-max approach. Compare the requested behavior with numpy.random.choice(replace=False). Done means categorical sampling supports an explicitly defined without-replacement mode with documented behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100