Sobes.tech
Senior

What is probabilistic programming (PyMC, Stan, NumPyro)?

sobes.tech AI

Answer from AI

Probabilistic programming is an approach to programming that allows describing statistical models and automatically performing inference of probabilistic distributions of parameters based on data. Frameworks like PyMC, Stan, NumPyro provide tools for defining models with uncertainties and conducting Bayesian inference.

The main idea is to assign probability distributions to model parameters instead of fixed values, and then use methods such as MCMC (Markov Chain Monte Carlo) or variational methods to compute the posterior distributions of the parameters.

This is especially useful in tasks where accounting for uncertainty is important, such as Bayesian optimization (BO), Gaussian processes (GP), and other areas of machine learning.

Example: in PyMC, you can define a model with a normal distribution for a parameter and observed data, then obtain the distribution of the parameter:

import pymc as pm
import numpy as np

with pm.Model() as model:
    mu = pm.Normal('mu', mu=0, sigma=1)
    obs = pm.Normal('obs', mu=mu, sigma=1, observed=np.array([1.0, 2.0, 1.5]))
    trace = pm.sample()

pm.plot_posterior(trace, var_names=['mu'])

Thus, probabilistic programming simplifies building complex statistical models and obtaining inferences considering uncertainty.