tensorflow / tensorflow/probability
Poisson random variable samples float instead of int, fails in hierarchical modeling as result
Open
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes, derived from tf example.
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS Mojave 10.14.4
- TensorFlow installed from (source or binary): pip
- TensorFlow version (use command below): v1.14.0-rc1-22-gaf24dc91b5 1.14.0 and 2.0
- Python version: Python 3.7.3
- Exact command to reproduce: I am implementing a hierarchical model, where the value of the Poisson sample is used to determine the batch size of the normal distribution. Since the Poisson sample is a float, the MCMC step function treats it as a float. This results in incorrect mathematics for MCMC to work.
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
tfb = tfp.bijectors
rv_m = tfd.Poisson(rate=1.)
m = rv_m.sample()
def joint_log_prob(m):
rv_m = tfd.Poisson(rate=1.)
m_int = tf.cast(m,'int32')
rv_norm = tfd.Normal(loc=tf.zeros(m_int),scale=1.)
return (tf.constant(-1.))
number_of_steps = 1000
burnin = 0
initial_chain_state = [m]
log_prob = lambda *args: joint_log_prob(*args)
[post_m], kernel_results = tfp.mcmc.sample_chain(num_results=number_of_steps,num_burnin_steps=burnin,current_state=initial_chain_state,kernel=tfp.mcmc.RandomWalkMetropolis(target_log_prob_fn=log_prob,seed=4))
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
Reproduce the supplied Python snippet, starting with tfd.Poisson.sample and the tfp.mcmc.RandomWalkMetropolis call. Trace where the Poisson sample's dtype enters the hierarchical model and MCMC state. Done means the reproduced model preserves the intended integer-valued Poisson state and its MCMC step uses it correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100