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.
What is probabilistic programming?
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.
What are random variables in a probabilistic program?
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.
How does inference work?
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.
Which probabilistic programming languages are common?
| 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.
How does probabilistic programming differ from standard machine learning?
| 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.
Where is it applied?
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.
How does probabilistic programming relate to AI agents?
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.
What should you do first?
- Pick one decision where uncertainty matters.
- Write down what you already know as priors.
- Build a small model in PyMC, Stan or Pyro.
- Check the model against held back data.
- Record which model version informed each decision.
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.
Frequently asked questions
What is probabilistic programming in simple terms?
It is a way of writing a model of uncertain data as a program, then letting the system work out the unknowns automatically.
What is a probabilistic programming language?
A language built so that you declare a probabilistic model and inference runs automatically. Stan, PyMC and Pyro are examples.
Is probabilistic programming the same as Bayesian statistics?
No. Bayesian statistics is the method. Probabilistic programming is the tooling that lets you write Bayesian models as code and run inference automatically.
What inference methods do these tools use?
PyMC describes gradient based MCMC sampling and variational inference. Other tools use methods such as Gibbs sampling.
Can it be combined with deep learning?
Yes. Pyro describes itself as aiming to unify modern deep learning and Bayesian modelling, with PyTorch as its backend.