CamDavidsonPilon / Probabilistic-Programming-and-Bayesian-Methods-for-Hackers

aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)
http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
MIT License
26.51k stars 7.84k forks source link

Chapter 3 | creating Poisson data N>1 likelihood error | TFP version #433

Open Pindar777 opened 5 years ago

Pindar777 commented 5 years ago

Hi there, when trying to run the code with N>1 (introduction of part 3) these lines are not executed likelihood_x_ = evaluate(tfd.Poisson(rate=x_).prob(data_[:, 0])) likelihood_y_ = evaluate(tfd.Poisson(rate=y_).prob(data_[:, 1]))

Error message: ValueError: Dimensions must be equal, but are 10 and 100 for 'Poisson_20/prob/mul' (op: 'Mul') with input shapes: [10], [100].

mmalekzadeh commented 5 years ago

For N>1 Replace the last three lines of code with:

likelihood_x_ = evaluate(tfd.Poisson(rate=x_).prob(data_[:, 0][:, np.newaxis]))
likelihood_y_ = evaluate(tfd.Poisson(rate=y_).prob(data_[:, 1][:, np.newaxis]))
L_ = evaluate(tf.matmul((likelihood_x_.T), (likelihood_y_)))

It'll work.