liveBook · Manning

Reparameterization trick

As explained in Grokking Bayes

The reparameterization trick expresses a random variable as a differentiable transformation of fixed noise and distribution parameters so gradients can be computed through stochastic sampling.

Sampling is useful in variational inference, but a random draw blocks gradients: automatic differentiation cannot see how changing distribution parameters changes the sampled value. The reparameterization trick rewrites that draw as a differentiable transformation of fixed noise, allowing optimization to continue. section 6.5 section 6.15

For a Normal approximating distribution with mean μ and standard deviation σ, generate a sample with θᵢ = μ + σ εᵢ, where εᵢ comes from the standard Normal distribution 𝒩(0, 1). The randomness stays in fixed noise εᵢ; μ and σ enter through addition and multiplication, which are differentiable. section 6.5

Rerouting the gradient

Imagine a water pipe blocked by the sampling step. A direct random draw stops the gradient’s flow. Reparameterization routes the flow around the block: fixed noise enters a simple transformation, and the resulting sample remains connected to μ and σ. Gradient descent can then maximize the ELBO. section 6.5

Use the equation to trace how fixed standard-Normal noise becomes a sample from the parameterized Normal distribution. section 6.5

How Grokking Bayes covers it

How deep it goes
Defines the transformation and explains its gradient path for Normal distributions, while deferring cases without a fixed-noise rewrite.
Examples
Uses a Normal transformation and a water-pipe analogy to illustrate fixed noise, differentiable operations, and restored gradient flow.
What it assumes
Assumes variational inference, ELBO optimization, sampling, and automatic differentiation; teaches the gradient-blocking problem through analogy.
What you can do after
Apply the trick to rewrite Normal samples so gradient-based variational inference can optimize distribution parameters.
How it connects
Connects sampling with variational inference, ELBO, automatic differentiation, gradient descent, and fixed distributions.

Also explained in

Compare how 4 books explain reparameterization trick →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Bayes. The section links point to the parts of the book it draws on.