Skip to content

Examples pymc2 => pymc3 #2022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
denadai2 opened this issue Apr 12, 2017 · 6 comments
Closed

Examples pymc2 => pymc3 #2022

denadai2 opened this issue Apr 12, 2017 · 6 comments

Comments

@denadai2
Copy link
Contributor

Hello everybody,
first of all thanks for this library. I like it A LOT!

I'm new to pymc3 (and probabilistic programming) and I find many Pymc examples on the web that I cannot convert to pymc3. Would it be possible to add a page on the website to help people converting pymc2 instructions to pymc3?

(example: http://stackoverflow.com/questions/43328715/car-model-from-pymc2-to-pymc3 disclamer I'm the one who asked it)

@junpenglao
Copy link
Member

For you particular problem, it is worth to have a look at the GP smoothing notebook in the example and the new pymc3.gp.GP class as this kind of local smoothing problem could be expressed in Gaussian Process quite naturally.

As for you general question of porting pymc2 code into pymc3 (or even generally porting WinBugs, JAGS, or STAN code into pymc3), from my experience you should try to think in matrix/tensor.
The underlying mechanism in pymc3 is very different compared to pymc2, using for-loop to generate RV or stacking multiple RV with arguments such as [pm.Binomial('obs%'%i, p[i], n) for i in range(K)] generate unnecessary large number of nodes in theano graph, which then slow down the compiling to an unbearable amount.

If you are interested in more information of how to port WinBugs, JAGS, or STAN code into pymc3, you can have a look of my port of Lee and Wagenmakers' book. For example, in Chapter 19, the STAN code use a for loop to generate the likelihood function, and I generate the matrix outside and use matrix multiplication etc to archive the same purpose.

@denadai2
Copy link
Contributor Author

Great answer and examples! Thanks! The problem is how to model in pymc3 these type of parameters:

screen shot 2017-04-13 at 17 27 18

where you have strong dependencies between prios (b and lambda in this case). A guide would be super useful for everyone :))

@junpenglao
Copy link
Member

You will need to define your custom likelihood function with pymc3.DensityDist using the theano loop theano.scan. Something similar to the timeseries distribution.

I dont think there is any guide for that yet - but I can try to reformulate the CAR model in your question which has something similar.

@junpenglao
Copy link
Member

@denadai2 I am working on a Gist for porting the CAR model from PyMC2 (and Winbugs) into PyMC3. Will add it to the docs when ready. #1968

@denadai2
Copy link
Contributor Author

Wow this is really awesome! Thanks to you I implemented the BYM model of CAR
I think that your notebook could be really helpful for many people, to understand how pymc3 works

@twiecki
Copy link
Member

twiecki commented Apr 15, 2017

@junpenglao definitely make a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants