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

Examples pymc2 => pymc3 #2022

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

Comments

Projects
None yet
3 participants
@denadai2
Contributor

denadai2 commented Apr 12, 2017

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

This comment has been minimized.

Show comment
Hide comment
@junpenglao

junpenglao Apr 13, 2017

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.

Member

junpenglao commented Apr 13, 2017

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

This comment has been minimized.

Show comment
Hide comment
@denadai2

denadai2 Apr 13, 2017

Contributor

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 :))

Contributor

denadai2 commented Apr 13, 2017

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

This comment has been minimized.

Show comment
Hide comment
@junpenglao

junpenglao Apr 13, 2017

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.

Member

junpenglao commented Apr 13, 2017

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

This comment has been minimized.

Show comment
Hide comment
@junpenglao

junpenglao Apr 14, 2017

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

Member

junpenglao commented Apr 14, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@denadai2

denadai2 Apr 15, 2017

Contributor

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

Contributor

denadai2 commented Apr 15, 2017

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

This comment has been minimized.

Show comment
Hide comment
@twiecki

twiecki Apr 15, 2017

Member

@junpenglao definitely make a PR

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