Stan: a probabilistic programming language
mc-stan.org
mc-stan.org
If you want to get started as fast as possible with computational Bayesian inference and don't need the performance and advanced features Stan, I'd recommend emcee [2] which is a lightweight python MCMC sampler.
Final recommendation to the HN crowd: Bayesian Data Analysis 3rd Edition [3] should be on your desk if you are thinking about using any of this software.
[1] http://research.microsoft.com/en-us/um/cambridge/projects/in...]
[2] http://dan.iel.fm/emcee/current/
[3] https://www.crcpress.com/Bayesian-Data-Analysis-Third-Editio...
we're also working on making it more robust to initialization and step-sizes. stay tuned.
As someone working with large datasets I think automating variational inference + SGD to work with a broad class of models is really the way forwards and a big force multiplier for machine learning.
David Barber "Bayesian Reasoning and Machine Learning" http://web4.cs.ucl.ac.uk/staff/D.Barber/pmwiki/pmwiki.php?n=... -- Thorough and systematic, accompanied by a Matlab library
Marc Steyvers "Computational Statistics with Matlab" http://psiexp.ss.uci.edu/research/teachingP205C/205C.pdf -- Somewhat unfinished but very good hands-on guide for a total novice
David Draper "Bayesian Modeling, Inference and Prediction" https://users.soe.ucsc.edu/~draper/draper-BMIP-dec2005.pdf -- Quite good if you're already familiar with a field, might be slightly daunting for a beginner
and the classic, David MacKay's "Information Theory, Inference, and Learning Algorithms" http://www.inference.phy.cam.ac.uk/itprnn/book.html
The syntax is similar, but the class of models Stan fits is far more general. The class of algorithms we have available also goes beyond MCMC, e.g., variational inference, optimization, and interfaces to Stan exist on all primary programming languages. It's more helpful to think of Stan as its own probabilistic programming language, and arguably the biggest entity with the largest user base.
This is mostly true, but last time I checked, Stan still couldn't sample discrete variables like BUGS can. Stan can only fit models with discrete parameters (e.g. finite mixtures) if the programmer is smart enough to integrate them out.
To ask an intentionally over-simplified question: if the key value add of Stan in the functionality and approach -- why bother with the overhead of an external DSL? Why not use an internal DSL -- e.g. borrow data structures and/or syntax of another language?
Arguments for an external DSL are, hopefully: cross-language portability and domain-clarity for people.
But how does this play out if you want to support multiple languages and interop?
Let's say I'm using Python, for example, and want to build up a model programmatically. The example at https://github.com/stan-dev/pystan shows using a heredoc. That's simple and easy to start.
However, a big downside of a plain-text DSL is that it can be hard to manipulate programatically. To do that, each language implementation has to be 'business' of converting to and from text. This reminds me of the 'SQL' problem ... many language SQL wrappers spend considerable time munging text. Ug.
Given my bias towards data-oriented programming, I see another approach: why not use a rich data structure language (other than plain text) as the foundation?
Why not edn, for example? If the LISPy nature of that is not preferred, then why not something else? (Does the C-community have some kind of generic data description language? I wouldn't recommend JSON necessarily but that would be better than a hand-rolled DSL, in my opinion.)
Here's why I recommend starting with 'rich' data as opposed to parsing text...
I'm not saying human DSLs are bad. I'm just saying they don't have to be the foundation. If you want a human external DSL, great -- but why not convert the human DSL to a canonical data structure? Then build everything around the data, rather than build everything around the text format?
The second is to go out and meet the practitioners where they are. That means making Stan models look like the equations in your paper. It means connecting to existing research software ecosystems. It means making it easy to adapt. In this case, if you end up tightly coupled to, say, specific R data structure then it becomes much, much harder to make it also work well for Python, and for Stata, etc. Additionally, it means that if I start on a model in Python then I cannot easily switch to using R (or vice-versa).
Using a DSL also has the nice property of cleanly separating Stan world vs R world. That makes it easier for users to build an accurate mental model for what happens when/where, which hopefully then leads to better performance.
Most importantly though, Stan code is incredibly concise and clear for specifying models.
And programmatic manipulation (while not impossible) of a Stan program was not high on our priority list. Since the underlying language is C++, you can bypass the Stan language and write (or generate) the C++ directly with a lot of effort. It uses standard (including Eigen) data structures.
Did you mean "without" a lot of effort? :)
[1] https://drmeister.wordpress.com/2014/09/18/announcing-clasp/
For those who haven't used it, the typical usage is to use Stan in combination with other languages (most commonly R). In the Stan language you define a model, specifying the data you'll get, potentially transformations to that data, then a set of parameters you want to fit, then finally a model saying how those parameters interact with each other and the data. You can also define priors for parameters. Then typically you save that model, and using R pass in the variables to a Stan call. The resulting fit object is returned to your original environment automatically.
It actually fits the work style reasonably well. All data munging happens as before, but instead of having some complicated model expression in, say, a glm() call, you have it in Stan language.
If you're interested in this, Gelman has two great books. Gelman & Hill's Hierarchical Models[2] which is applied and geared towards social science researchers, and Bayesian Data Analysis[3].
If you have even vague interest in applied statistics in fields with lesser ability to design experimental controls then you should investigate this tool.
This one has more of a CS feel to it: http://www.stat.columbia.edu/~gelman/research/published/stan...
Lastly, here is my own turbulent experience with getting started with Stan: http://ericnovik.github.io/2015/08/14/Getting-Started-with-S...
That being said, there's still a huge gulf between practitioners in science and social science that are building parametric Bayesian models and practitioners in the deep learning / ML community that are focused on building more general, scalable, machine learning algorithms for tasks like machine translation and question answering. It would be amazing if somebody could reconcile these communities by showing deep learning models can be expressed and fit effectively side-by-side with more parametric models.
Seems most (if not all) probabilistic programming languages use sampling as a general algorithm for training models.
So, I guess it would be a hard job to express something like HMMs or CRFs that would fit into the framework (I guess one can easily train HMMs/CRFs with a fixed length of a sequence, but not undefined length).
See http://forestdb.org/ for some examples. E.g. an infinite HMM.
I have no experience with Stan. There was some controversy on whether it is Turing-complete, but I cannot elaborate on that.
The obvious disadvantage of using a language that is too expressive for something as simple as an HMM is that you loose the nice performance guarantees given by all specialized algorithms such as Viterbi. Theoretically, they can achieve good efficiency by performing program transformations (e.g. with abstract interpretation). But in practice, we are still a bit far from that.
A nice trick is to implement your generative model in something very efficient (e.g. Probabilisitic C or something GPU-based). You can then forget the burden of having to encode your own sampling procedure, but at the same time inference might be tractable.
But obviously that doesn't cover classes as big as "anything expressible in Church", so there's a pretty big gap. It's possible that languages like Church could use techniques like that as part of an optimizing compiler that recognizes specializable patterns, the way regular compilers do loop transformations and auto-vectorization and such. But, like auto-vectorization, not that easy to do.
I haven't done any HMMs or CRFs with Stan, but don't see why you couldn't do them. Passing in the data likely requires some tricks with arrays and indexing, but it's totally doable. Probably unlikely that you'd beat standard, custom algorithms, but if your HMM was part of a larger model, it might make sense.
happy to answer any questions here.
ADVI [1] is a variant of BBVI [2] where we fully leverage all of the amazing things that Stan has to offer (like automatic differentiation and automatic transformations of constrained parameters).
you can use ADVI to get an approximation to the Bayesian posterior. the advantage of using ADVI over sampling is that ADVI is typically faster for large models (both in terms of # of parameters and # of data observations). ADVI also a bit better at handling models with multi-modal posteriors, such as mixture models.
ADVI is currently in cmdStan (but not in RStan or PyStan). we're continuing to make the algorithm more robust.
[1] http://arxiv.org/abs/1506.03431 [2] http://www.jmlr.org/proceedings/papers/v33/ranganath14.pdf
What in general are the disadvantages of variational inference vs full MCMC? Are there in general significant advantages besides the speed up?
the key disadvantages of VI (particularly ADVI) are:
1. mean-field variational inference cannot model posterior correlations. so if you expect your model + dataset to give a "skewed" posterior, then mean-field variational inference will have a difficult time describing such a posterior. (it will under estimate marginal variances.)
2. full-rank variational inference can model posterior correlations. but it can become too expensive for big models. there is a lot of great research coming up in this vein, such as [1,2].
3. in either case, the version of variational inference we have in Stan (ADVI) uses a normal approximation in a transformed parameter space. thus, there is an additional mismatch of the shape of the variational posterior to the full MCMC posterior.
in terms of advantages:
1. variational inference is (in general) a non-convex optimization problem. so it's easy to know when we've converged to a local optimum. convergence in MCMC is a bit more tricky to assess.
2. if your model has a multi-modal posterior, then variational inference will focus on just one of the modes. this is sometimes desirable as MCMC techniques might end up jumping around all of the modes and producing poor samples.
this is just the tip of the iceberg. but i hope it helps!
[1] http://arxiv.org/pdf/1506.03159.pdf [2] http://arxiv.org/pdf/1502.07685.pdf
If you're like me you'd probably start with some kind of "grid search" by giving it evenly spaced parameters. Then you would evaluate it at each one and do some kind of gradient descent / ascent type algorithm. This will work, but in a high dimensional space (ie. a function with many arguments) you have no chance of covering even a tiny fraction of the parameter space. The key is, you don't want to waste time evaluating a set of parameters if it doesn't tell you anything new. ie. if you get back a similar answer to what you already had. This is what the GP means (I think) by trying to avoid "dependence between adjacent draws".
I could be wrong about all this, I'm trying to learn it too.