liveBook · Manning

Fully bayes parameter estimation

As explained in Math and Architectures of Deep Learning

A Bayesian parameter-estimation approach that combines observed data likelihood with a prior distribution to obtain a posterior over the unknown parameter.

Fully Bayes parameter estimation combines the likelihood of observed data with a prior distribution to estimate unknown model parameters. In unsupervised generative modeling, the resulting probability density can approximate a data set such as cat images, generate new samples, and score new observations. section 13.0 section 13.3

The posterior is proportional to likelihood times prior. Unlike MLE, which uses only observed data, Bayesian estimation incorporates prior belief: limited data leaves the prior influential, while abundant data makes the posterior approach the MLE. section 13.1.1 section 13.3

Gaussian parameter-estimation cases include:

  • Unknown mean with known precision: model the mean with a Gaussian prior and obtain a Gaussian posterior. section 13.3
  • Known mean with unknown precision: use a gamma prior and obtain a gamma posterior through conjugacy. section 13.6.1
  • Extend the treatment to unknown mean and variance, covering both univariate and multivariate cases. section 13.1.1

Posterior estimation in PyTorch

For an unknown Gaussian mean with known variance, compute the sample mean, combine it with the prior mean and scale, calculate posterior parameters, and return torch.Normal(mu_n, sigma_n). For unknown variance with known mean, update gamma concentration and rate and return torch.Gamma(alpha_n, beta_n). section 13.3 section 13.6.1

Listing 13.1 PyTorch- Bayesian estimation with unknown mean, known variance
import torch

def inference_unknown_mean(X, prior_dist, sigma_known):
    mu_mle = X.mean()
    n = X.shape[0]

    mu_0 = prior_dist.mean
    sigma_0 = prior_dist.scale                             #1


    mu_n = mu_mle / (1 + sigma_known**2 / (n * sigma_0**2)) +
             mu_0 / (1 + n * sigma_0**2 / sigma_known**2)  #2

    sigma_n = math.sqrt(
        (sigma_0**2 * sigma_known**2) /
        (n*sigma_0**2+sigma_known**2))                     #3

    posterior_dist = torch.Normal(mu_n, sigma_n)
    return posterior_dist

Use the executable listing to connect the posterior formulas for an unknown mean to a concrete PyTorch implementation. section 13.3

How Math and Architectures of Deep Learning covers it

How deep it goes
Derives Gaussian and gamma posterior updates across known and unknown parameters, then connects them to PyTorch implementations.
Examples
Uses cat-image density modeling, unknown-mean Gaussian estimation, unknown-variance Gaussian estimation, and PyTorch code listings.
What it assumes
Assumes Gaussian likelihoods, likelihood maximization, probability distributions, and the distinction between variance and precision.
What you can do after
Apply Bayesian Gaussian estimation in PyTorch by updating posterior parameters for unknown means, variances, or precisions.
How it connects
Connects likelihood, prior distribution, posterior distribution, MLE, MAP estimation, Gaussian likelihoods, precision, variance, and conjugate priors.

Also explained in

Compare how 2 books explain fully bayes parameter estimation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.