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

Added Chapter 4 in Tensorflow Probability #404

Closed matthew-mcateer closed 5 years ago

matthew-mcateer commented 5 years ago

Added a notebook with a complete rewrite of Chapter 4 using Tensorflow Probability instead of Pymc3 or pymc2. Also reduced the amount of numpy and scipy usage.

matthew-mcateer commented 5 years ago

Hey @CamDavidsonPilon , Here is the PR for Chapter 4 of Tensorflow Probability. In addition to the code changes, we also changed the formatting on the headers a little bit, since the way that the header heirarchies showed up in colab was a little odd. This new method also seems more intuitive.

As soon as this is approved by you, Chapter 2 can be uploaded. We're still reviewing it, but we believe that Chapter should be ready by tonight or tomorrow. How does that sound? The other chapters are also almost ready, they're still just being reviewed.

CamDavidsonPilon commented 5 years ago

Average height vs. County Population

The code that produces this graph is quite slow - lots of time spent creating tf variables. Any way to make that faster?

CamDavidsonPilon commented 5 years ago

Other than that, everything runs fine (except the google colab part...)

matthew-mcateer commented 5 years ago

@CamDavidsonPilon yes there is a way to make it faster. I'm fixing that as we speak.

What do you mean "except the google colab part..."?

matthew-mcateer commented 5 years ago

Hi @CamDavidsonPilon

in response to your point about one of the cells taking a long time, would you prefer if the cells in all our notebooks included the %time magic at the top of the cells? This way users could see exactly how much time an output takes to get there.

For example, with the following code snippet:

%time
N = 10000
print("Probability Estimate: ", len(np.where(evaluate(tfd.Exponential(rate=0.5).sample(sample_shape=N)) > 5))/N )

The output would be the following:

CPU times: user 4 µs, sys: 1 µs, total: 5 µs 
Wall time: 9.54 µs 
Probability Estimate: 0.0001
matthew-mcateer commented 5 years ago

Okay @CamDavidsonPilon, The cell in question has been updated. It's much faster, though keep in mind it's still sampling 4000000 times. It should be much more manageable now. Was that your only concern?

CamDavidsonPilon commented 5 years ago

Yup, all good - merging!