pyro-ppl / pyro

Deep universal probabilistic programming with Python and PyTorch
http://pyro.ai
Apache License 2.0
8.57k stars 986 forks source link

Call for User-Contributed Examples and Tutorials! #1461

Open martinjankowiak opened 6 years ago

martinjankowiak commented 6 years ago

Goal

Add creative examples of Pyro code developed by users out in the real world to our catalog of examples and tutorials. This is great for the community as a whole and helps the Pyro dev team focus on features that are useful to you and the broader community.

Context

The Pyro dev team met a bunch of Pyro users at ProbProg 2018 and heard about a variety of interesting applications of Pyro.

What is being asked

We realize that writing a clean piece of code that can be read by and is useful to a wide audience is difficult. We are also aware that some code/data cannot easily be made public. Wherever possible we are eager to help you overcome some of these potential barriers by

Who?

Anyone reading this!

martinjankowiak commented 6 years ago

Some people we'd love to hear from include (no pressure though!): @mbabadi @chart90 @robertness @desmond-ong @wsgharvey @justinchiu @stuhlmueller @mhw32 @null-a

desmond-ong commented 6 years ago

happy to contribute! @ndgAtUber and I have some stuff baking right now (and an application paper that should be accepted soon), so hopefully soon, we'll have something in a shape to have the dev team take a look at.

maedoc commented 6 years ago

sorry to jump on here, (but I could neither join the forum by github or direct sign up (I never received the verification email)), I would like to not only +1 this issue, but also suggest that porting example models from other software (e.g. Stan) would save potential users a lot of time. In my case, it took me a few hours to figure out how to write down a simple AR model (which is my fault more that anything), and having this example (which is given in the Stan guide) would've gotten me jump started.

Also, examples to get users get started transitioning from CPU to GPU would be helpful (where I'm currently stuck).

Btw I'd be happy to trade my AR example for tips on getting it working for CUDA, which could be attractive for Pyro since it (AR) is a stepping stone to ODE/SDE support.

edit I figured out the CUDA problem was part of using autoguides (they need their params predefined on the cuda device), but this could be mentioned in the docs or an example.

edit 2 put in bold the contribution to this issue to distinguish from my whining

SourabhKul commented 6 years ago

Would a vanilla Bayesian Network implementing a heart disease example be a good example/tutorial? I have it coded in python from scratch and could try to port it.

martinjankowiak commented 6 years ago

@SourabhKul sounds like it could be useful. can you please give some more details?

SourabhKul commented 6 years ago

@martinjankowiak This work was a homework assignment in a PGM class I took. The code is available here.

It is a 9-node Bayesian network, with categorical variables (Heart rate, age, gender etc.). In the tutorial I could show how to instantiate the Bayesian network (nodes, edges), populate CPTs through maximum likelihood estimate and perform exact as well as sampling based inference. It could be helpful for users to model their own Bayesian Networks using this tutorial, and going forward it may be helpful to natively support Bayesian Networks in pyro.

I am new to pyro as well as new to contributing to open source and this would be an interesting first project. I can also do tutorials for other basic PGMs like Markov random fields, And some more advanced examples like Stochastic variational inference over factor analysis model and other mixture models.

martinjankowiak commented 6 years ago

@SourabhKul sure that sounds great. i suggest you start with a pretty minimal version and try to keep your first PR from getting too large. improvements can always be added in follow-up PRs. it's also probably best to keep abstractions to a minimum, since too many abstractions can make it harder for readers to parse example code.

activatedgeek commented 5 years ago

Hey @martinjankowiak, allow me to suggest something.

I'm sure the Bayesian literature has collected plenty of tutorial data sets and tasks over the years (think counterparts for MNIST/CIFAR/COCO from the DL world). It would be a good idea to create issues tagged with "Help Wanted" or "Examples" which state those problems. Anyone interested (including me) to explore the Pyro API and Bayesian Learning in general can help contribute. Eventually, we can reach feature parity against the literature.

Not sure if this aligns with the goals of Pyro, but may be listing some classic examples from references texts would be helpful for starters?

SourabhKul commented 5 years ago

@SourabhKul sure that sounds great. i suggest you start with a pretty minimal version and try to keep your first PR from getting too large. improvements can always be added in follow-up PRs. it's also probably best to keep abstractions to a minimum, since too many abstractions can make it harder for readers to parse example code.

Hi, sorry for responding late. In my attempt to encode graph-based models like Bayesian networks in pyro, I realize that there really needs to be a better way to do it. Let me elaborate:

Typical flow to solve real-world problems through graph-based models is i) model each feature of the data as a random variable (optionally have some latent variables) ii) define relationships between these variables through connections (causal in Bayes nets, non-causal in Markov nets). These relationships could be learnt through structure learning or hand-made through expert knowledge, or a combination of both iii) define conditional probability tables/distributions over the relations to be random variables themselves iv) perform inference over these parameters to learn the model v) perform inference over the learnt model by sampling the learnt parameter distributions

As per my understanding, this flow is not supported; the flow currently supported (e.g. the nn api) is a layer-by-layer organization which does not permit within-layer connectivity.

It may be important to support the above flow natively in pyro. Thoughts?

fritzo commented 5 years ago

@SourabhKul you can use Pyro easily for your Bayesian network workflow, except structure learning which you would need to hand-code on top of Pyro. I'm sorry if you found Pyro confusing coming from a Bayes net background. We could definitely use help with documentation.

SourabhKul commented 5 years ago

@SourabhKul you can use Pyro easily for your Bayesian network workflow, except structure learning which you would need to hand-code on top of Pyro. I'm sorry if you found Pyro confusing coming from a Bayes net background. We could definitely use help with documentation.

Thanks for the feedback, I'll give it another try after I go through more examples. It might just be that I need to be more familiar with pyro.

fritzo commented 5 years ago

@SourabhKul Great. If you have any intro questions, the best place to ask is https://forum.pyro.ai

patrickeganfoley commented 5 years ago

Just made a super simple classic ELO model for NCAA Men's Basketball 2002-2018 here. Would you be interested in it as an example if I cleaned it up a bit?

Super pumped to be able to have the variational posterior on the team quality terms - it's cool you can see that the D2/D3 teams that only play a few games a year have very high uncertainty.

martinjankowiak commented 5 years ago

@patrickeganfoley that would be great! i know at least two people who would love to see that

fehiepsi commented 5 years ago

Sorry for an interuption. I have no idea why I did unpin/pin this thread. :( I'll revert this back to the original pinned thread.

deepaks4077 commented 4 years ago

@martinjankowiak: I've been meaning to use Pyro for a causal inference in genomics task (to conduct a GWAS). I already have the code to generate a decent amount of synthetic data. I could make it more complicated by adding some latent confounding as well. What do you guys think? My code is all in Pytorch so it'll be reasonably instructive to port it to Pyro.

Also, @martinjankowiak : This could be a nice project for GSoc 2020.

JamesTrick commented 4 years ago

I've just started the process of (likely slowly) porting examples from Bayesian Data Analysis by Gelman et. al. to Pyro which may be of interest. Repo is here

EvanZ commented 3 years ago

I have a couple of projects involving Pyro and basketball:

Bayesian Neural Network Win Probability https://github.com/EvanZ/bayesian-win-probability/blob/master/bayes-wp.ipynb

NBA Player Ratings Model https://github.com/EvanZ/ppl-pm/blob/main/xpm.ipynb

Bayesian Meta-Mock Draft (Aggregating Draft Rankings) https://github.com/EvanZ/bayesian-meta-mock/blob/master/bayesian-meta-mock-draft.ipynb

eb8680 commented 3 years ago

@EvanZ these look awesome! I have been meaning to create a community tutorials/examples page on our website highlighting externally hosted examples, and your projects look like a great incentive for me to finish that. Have you been publishing them anywhere that I should link to, e.g. as blog entries?

We would also be happy to host them here along with the rest of the Pyro examples - if you would prefer that option, please open separate pull requests for each notebook.

EvanZ commented 3 years ago

Hi @eb8680 sorry didn't get back sooner. No, I've really just been putting them in git repos. Feel free to link to those!

EvanZ commented 3 years ago

Here's another post I made yesterday.

Are The Boston Celtics Better Than Random In Preventing Wide Open 3s? https://github.com/EvanZ/open_3pt_inference/blob/master/inference.ipynb

jaronowitz commented 3 years ago

Would there be interest in an example concerning solving multiarmed bandits using randomized probability matching? I'm really excited about Pyro and would love to be able to contribute!

martinjankowiak commented 3 years ago

@jaronowitz sure sounds great! feel free to start by opening an issue to discuss scope/details or just directly submit a PR if you have a good idea of what you'd like to contribute. either way we're happy to offer advice and suggestions, help improve the code, etc