Deep probabilistic programming is a method of implementing “Bayesian” probabilistic modeling on “differentiable” deep learning frameworks. This provides a style of language to define complex (composite, hierarchical) models with multiple components and incorporate probabilistic uncertainty about latent variables or model parameters into predictions.
Deep probabilistic programming can be characterized by approximate Bayesian inference 1 (calculating the approximate posterior probability distribution of latent variables or model parameters by incorporating the information from the observed data) on differentiable programming (parametric optimization by deep learning).
Why Deep and Differentiable Programming?
Deep learning frameworks (e.g., PyTorch, TensorFlow, MxNet) enable defining a target model in a deep and composite network structure assembling the building blocks of heterogenous component models (= parametric linear or non-linear functions including neural nets) that run in data-dependent, procedural and conditional manner. Each component may be based on different sets of feature variables. Also, they provide a tool to estimate the model parameters in terms of differentiable optimization like stochastic gradient decent (SGD) and back-propagation algorithms.
Since Bayesian modeling is based on a probabilistic model of the generative process relating the observed data with the uncertain latent variables (= generating parameters), it is very desirable to have the representational power of a deep and composite network model to sufficiently describe the potentially complex generative processes with multiple input variables. In addition, the exact calculation of the posterior distribution of latent variables requires doing the integral calculation to obtain the evidence of the observed data with the assumed prior distribtuion, so this is intractable in most problems. Thus, we need approximate Bayesian inference techniques, such as variational inference (VI). Thankfully, VI transforms the approximate posterior inference problems into the optimization problems searching for the best hyperparameters of approximate posterior distribution (often assumed to be Gaussian distributions). We will discuss it in detail below.
Why Bayesian Inference?
Bayesian probabilistic modeling provides a unified scheme on how to update the uncertain information (or infer the posterior distributions) about modeling parameters or latent variables using observed data. It also assumes the specification of generative processes (or model functions describing how outputs are produced from inputs) and prior distributions of modeling parameters or latent variables. This specification allows for easy incorporation of prior knowledge into the model form and associated parameter uncertainty.
Although the initial choice of compared models and associated prior distributions may depend on our domain knowledge about the underlying problems, bayesian reasoning provides an objective scheme to compare different models and priors.
Bayesian modeling allows us to build more robust and less overfitted models under uncertainty and predict probabilistic estimates about target variables in the model. By incorporating the known form of a physics-based equation describing the potental causal relationships of variables in the underlying phenomenon into our modeling and set the priors on the model parameters, we can build a heuristically reasonable, more generalizable and updatable model with insufficient data.
It sounds all good and simple, but a key difficulty in Bayesian probabilistic modeling arises from calculating the posterior distributions for a given complicated model structure and prior. It is very often intractable to compute the “exact” posterior distribution, but the variational inference (VI), one of the important methods in deep probabilistic programming, present a commonly-applicable approach to compute the “approximate” bayesian posterior.
Since VI transforms Bayesian posterior inference problems (i.e., learning uncertain modeling parameters or latent variables) into optimization problems, the SGD optimization in underlying deep learning frameworks can solve the posterior inference problems.
Deep Probabilistic Programming = Bayesian Differentiable Programming
Compared to non-probabilistic deep learning frameworks 2 that aim to make “deterministic” models for point-estimate predictions, deep probabilistic programming frameworks enables us to 1) specify “probabilistic” models involving the uncertain distributions of model parameters or latent variables, 2) provide approximate Bayesian inferences (e.g., variational inferences) using the powerful stochastic gradient decent algorithms of the original deep learning. Thus, deep probabilistic programming naturally integrates the benefits of bayesian modeling and deep learning.
Application: Bayesian Regression with a Parametric Function (e.g., knowledge-based known function form, NNs)
In Bayesian modeling we posit that the model parameters (a.k.a. latent or hidden variables) generating the observed data are uncertain in our knowledge. Thus, our information about the true values of generating variables is described by a probability. That is, we use a probability to denote our uncertainty about the hidden variables selected to describe the generating process.
Suppose we have a dataset where each data point has feature input vector and observed output variable The goal of Bayesian regression is to fit a function to the data: assuming that is the uncertain latent variables described by a probability distribution.
There are important modeling assumptions here.
- is an assumed generating function we specify with unexplained error .
- is a deterministic function for any sampled value of . The function may be any known form of an equation or a neural network involving the model parameters .
- The level of is assumed to be fixed as a constant value and also related to how accurately we may specify our function .
Whereas a non-Bayesian (deterministic) approach views as a fixed variable to be estimated, a Bayesian (probabilistic) approach regards as an uncertain variable whose probability distribution is to be estimated to explain the observed data. Maximum likelihood (ML) or maximum a posteriori (MAP) estimations are well-known non-Bayesian approaches determining a fixed .
Now let’s represent the above Bayesian regression in terms of probability distributions.
In the Bayesian perspective the complete generative process should be always described in the joint probability distribution of all observed and latent variables.
Since is given and and are known and fixed, the joint distribution for the complete generative process is where denotes the hypothesis space of model form .
Factorizing , we represent the complete generative process in the combination of the likelihood and the prior distributions. It is important to note that the exact forms of the likelihood and the prior distributions are part of our modeling assumptions.
- The likelihood is our assumed probability model to describe a generating process of the observed variable from a sample of latent variables . Assuming that the likelihood is normally distributed with as (= the expected value of ) and as the Gaussian noise level,
Note that a known deterministic physical model can be easily incorporated into the likelihood.
- The prior is our assumed probability model to represent the uncertain information of latent variables (= model parameters) before we consider the observed data . .
Bayesian posterior inference is to update our probabilistic information about after observing the data and considering the likelihood. Mathematically the Bayes’ rule (a.k.a. inverse probability) provides this update rule and the posterior distribution representing the uncertainty about is computed as
= .
The evidence is the normalizing constant of the posterior distribution and should be calculated to obtain the exact posterior distribution 3. It is the probability that the model observes the data with the assumed likelihood and the prior distributions. Note that it is also the marginalized probability of likelihood prior over the uncertain parameters . Since this is intractable to be exactly calculated, we involve an approximate Bayesian inference such as variational inference (VI) or Markov chain Monte Carlo (MCMC).
Importantly, the Bayesian prediction of for a new is essentially the marginalization of likelihood posterior over the uncertain parameters , incorporating the posterior uncertainty about parameters into predictions.
Variational Inference
For simpler notations, we define the generating parameters . Note that posits the likelihood variance (or unexplained error level) and posits the prior variance (or model parameter uncertainty). Now we can denote the prior by and the posteror by .
The prior distribution:
The posterior distribution: =
The aim of variational inference is to approximate the posterior by a simpler probability distribution where is called the variational parameters.
Therefore,
Note that the log evidence is lower-bounded because is always greater than 0. The lower bound is called the Evidence Lower Bound (ELBO) or the variational free energy. Since is fixed for a given (prior variance and likelihood variance ) and the hypothesis space of the model function form , the maximization of ELBO by adjusting the variational parameters (or ) minimizes , which makes the approximate posterior distribution closer to the true posterior distribution . Also, note that when ELBO is maximized up to the log evidence , becomes 0, making the approxmiate posterior the same as the exact posterior .
The existence of ELBO transforms the posterior inference problem into the optmization problem, which can be solved using the minus ELBO as the loss function of SGD algorithm in DL frameworks. In addition, ELBO can be represented in a different way to clarify how the approximate posterior distribution of parameters shaped by reckons the balance between the likelihood and the prior.
The first term motivates the distribution to concentrate on the values with which the model have higher likelihood , whereas the second term the minus inspires the approximate prior to be less deviated from the given prior distribution .
Prediction Errors as Probabilistic Interpretations
In Bayesian approach we make our assumptions on both likelihood and prior distributions. The likelihood distribution posits the model function form and the unexplained error level . The prior distribution has an assumed variance .
Importantly, the Bayesian prediction of for a new is essentially the marginalization of likelihood posterior over the uncertain parameters , incorporating the posterior uncertainty about parameters into predictions.
First,
Note that the unexplained error = = = , since where is the hidden true value (before a noise is being added) and is the inherent noise. Also, is the misspecified model bias error, and .
Thus, the likelihood for a given is shaped by both the misspecified model bias error and the inherent error. As the ratio of the ratio goes up, the likelihood goes down. In addition, the normalizing factor decreases the likelihood with higher .
Second, the term where put different weights over values. That is, closer to the current prior mean is more weighted, allowing for the tendency toward a smaller deviation from the current prior. In particular, when , corresponds to a regularization term preferring small values of decreasing the tendency of overfitting and higher model parameter uncertainty (= model variance error).
In general, when the set of features used in modeling are:
- only the essential features
- we tend to obtain a generalizable model with a good fit
- essential features + many irrelevant features
- too complicated model (overfit) and high model variance (model parameter uncertainty)
- insufficient essential features
- too simple model (underfit) and high model bias (model misspecification)
- insufficient essential features + many irrelevant features
- non-generalizable model with a bad fit
References
[1] https://eng.uber.com/pyro/
[2] https://www.facebook.com/yann.lecun/posts/10155003011462143
[3] David MacKay. Information Theory, Inference, and Learning Algorithms. http://www.inference.org.uk/mackay/Book.html
-
Learning the probability distributions of model parameters or latent variables is called inference in probabilistic modeling. Bayesian inference often involves approximating posterior distributions, since the exact calculations are often intractable. In parameterized models, variational inference (VI) approximate the posterior distributions through optimization (differential programming). ↩
-
Non-probabilistic deep learning models do not assume the uncertainty in model parameters (e.g., weights in NN). ↩
-
Compared to the Bayesian approach requiring the estimation of the evidence and the posterior distribution, the maximum a posteriori (MAP) estimation simply considers the point parameter estimate maximizing the numerator part of the posterior (= Likelihood Prior). ↩