Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard
Chapter 3 (TFP) joint log probability calculation issue
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:
- we can remove the two lines of code that use
rv_probin the calculation of joint log probability OR - sample
rv_prob(as p) and use that as probability of sampling from first distribution and use1 - pas 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.