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.55k stars 7.85k forks source link

Privacy Algorithm implementation in Ch2_MorePyMC_PyMC3 #379

Open njordhov opened 6 years ago

njordhov commented 6 years ago

The "Privacy Algorithm" implementation in Chapter 2 can perhaps be improved using a theano switch expression:

val = pm.math.switch(first_coin_flips, true_answers, second_coin_flips) 

It is currently implemented as:

val = first_coin_flips*true_answers + (1 - first_coin_flips)*second_coin_flips

A python conditional expression unfortunately doesn't do the trick:

val = true_answers if first_coin_flips else second_coin_flips