Probabilistic programming is a programming paradigm in which you declare a probabilistic model, using random variables for unknown quantities, and the system performs inference automatically. It lets you tell a generative story about your data instead of building a black box.
This page is for data and AI teams that must reason under uncertainty. It covers random variables, inference methods, common languages, applications and how to start.
Wikipedia describes it as a programming paradigm based on the declarative specification of probabilistic models, with inference carried out automatically. The aim is to combine probabilistic modelling with general purpose programming. Languages in this paradigm are called probabilistic programming languages, or PPLs.
The PyMC overview puts it this way: probabilistic programming allows for automatic Bayesian inference on user defined probabilistic models.
In an ordinary program a variable holds one value. In a probabilistic program, unknowns are random variables with prior distributions. PyMC explains that you assign a prior distribution to the unknown variables in the model, and that observed variables represent the likelihood of the data. Deterministic variables are fully fixed by their parents, while stochastic variables depend on them only in part.
The result is a generative story: the model states how the data could have been produced, instead of acting as a black box.
You write the model and the engine infers the unknowns. PyMC describes two families. Gradient based Markov chain Monte Carlo sampling, such as the No U Turn Sampler, and variational inference, which the docs say can be more efficient than MCMC for some problems at the cost of generalisability.
Other languages use other methods. Wikipedia mentions Gibbs sampling in WinBUGS and importance sampling and exact inference in other systems.
| Language | How its own site or page describes it |
|---|---|
| Stan | Software for Bayesian data analysis, with an active community and a commitment to open source |
| PyMC | Specify models in Python; automatic Bayesian inference |
| Pyro | A universal probabilistic programming language in Python with PyTorch as its backend, aiming to unify modern deep learning and Bayesian modelling |
| Others listed on Wikipedia | Turing.jl, Infer.NET, NumPyro, Gen, Edward, WebPPL, ProbLog and more |
See the Stan and Pyro sites for details.
| Question | Probabilistic programming | Typical black box model |
|---|---|---|
| What you write | A model of how the data arises | A function fitted to examples |
| Uncertainty | Part of the output, as distributions | Often a single point estimate |
| Prior knowledge | Encoded as priors | Usually implicit in features or architecture |
| Explanation | The model structure is readable | Harder to inspect |
This is a comparison of approaches in general, not a claim about any one tool.
Wikipedia lists predicting stock prices, recommending movies, diagnosing computers, detecting cyber intrusions and image detection, along with vision and robotics tasks, pharmaceutical and economics work, and Bayesian cognitive science. These are all settings where information is uncertain or incomplete.
An agent that acts on uncertain information benefits from knowing how uncertain it is. A probabilistic model can supply that estimate as a distribution, and a policy can then decide when the agent acts and when it asks a human. ElixirClaw, XenonStack's AI agents computing platform, is where such agents are built and run.
To map one decision your agents make under uncertainty, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.
It is a way of writing a model of uncertain data as a program, then letting the system work out the unknowns automatically.
A language built so that you declare a probabilistic model and inference runs automatically. Stan, PyMC and Pyro are examples.
No. Bayesian statistics is the method. Probabilistic programming is the tooling that lets you write Bayesian models as code and run inference automatically.
PyMC describes gradient based MCMC sampling and variational inference. Other tools use methods such as Gibbs sampling.
Yes. Pyro describes itself as aiming to unify modern deep learning and Bayesian modelling, with PyTorch as its backend.