Probabilistic-Programming-and-Bayesian-Methods-for-Hackers icon indicating copy to clipboard operation
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard

Chapter 3 (TFP) joint log probability calculation issue

Open mvuksano opened this issue 6 years ago • 0 comments

I'm a bit confused about joint_log_prob function used in Chapter 3 (Tensorflow Probability).

I can see that rv_prob is a Uniform random variable from in the range [0, 1]. We don't really do anything with that variable but we use it to calculate how likely sample_prob_1 and sample_prob_2 are to be from that distribution.

I assume that:

  1. we can remove the two lines of code that use rv_prob in the calculation of joint log probability OR
  2. sample rv_prob (as p) and use that as probability of sampling from first distribution and use 1 - p as probability of sampling from the second distribution. Something like:
p = rv_prob.sample()
rv_assignments=tfd.Categorical(probs=tf.stack([p, 1-p]))
rv_observations = tfd.MixtureSameFamily(
  mixture_distribution=rv_assignments,
  component_distribution=tdf.Normal(loc=sample_centers, scale=sample_sds))

And then we could include rv_assignments.log_prob(sample_prob_1) + rv_assignments.log_prob(sample_prob_2) in joint_log_probability calculation.

mvuksano avatar Jul 03 '19 23:07 mvuksano