Reparameterization tricks pop up frequently in papers. Here, we explore approaches to reparameterization.We see the Gaussian reparameterization trick in VAEs (Kingma, 2013). We wish to sample 𝑥:𝑥𝒩︀(𝜇𝜃,𝜎2𝜃)Once directly sampled in this way, we cannot recover gradients for 𝜇𝜃 and 𝜎2𝜃. Instead, the usual trick is to reparameterize 𝑥 as “deterministic” components 𝜇𝜃 and 𝜎2𝜃 (coming from some neural network) and move the “stochastic” components into a separate 𝜀:𝑥=𝜇+𝜎·𝜀𝜀𝒩︀(0,1)We can now recover the gradients of 𝑥 with respect to our parameters. Intuitively, this makes sense—we’re shifting and scaling a standard normal distribution. But how can we justify this?Turns out, there are two approaches to reparameterization, an explicit and implicit approach (Figurnov et al., 2018).Our Gaussian problem is generally expressed as wanting to optimize some expectation𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]with respect to parameters 𝜙 of the distribution (in the Gaussian case, 𝜇, 𝜎2). The issue here is that we have stochastic 𝑧 inside the expectation while trying to optimize (differentiate) with respect to the parameters 𝜙 that are generating 𝑧 itself.Explicit approachThe explicit approach finds some standardization function that is differentiable and invertible:𝒮︀𝜙(𝑧)=𝜀𝑞(𝜀)𝑧=𝒮︀1𝜙(𝜀)In the Gaussian case, we have:𝜀=𝒮︀𝜙(𝑧)=𝑧𝜇𝜎𝒩︀(0,1)𝑧=𝒮︀1𝜙(𝜀)=𝜀·𝜎+𝜇(confirm this by substituting 𝜀 into 𝑧’s density to recover the standard normal density).We can then use our 𝒮︀𝜙 inside our expectation:𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]=𝔼𝑞(𝜀)[𝑓(𝒮︀1𝜙(𝜀))]𝜙𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]=𝜙𝔼𝑞(𝜀)[𝑓(𝒮︀1𝜙(𝜀))]=𝔼𝑞(𝜀)[𝜙𝑓(𝒮︀1𝜙(𝜀))]=𝔼𝑞(𝜀)[𝑧𝑓(𝒮︀1𝜙(𝜀))𝜙𝒮︀1𝜙(𝜀)]=𝔼𝑞(𝜀)[𝑧𝑓(𝑧)𝜙𝒮︀1𝜙(𝜀)]Since we’ve contained the derivative with respect to the parameters with the function of epsilon, we can now differentiate 𝑓 with respect to 𝑧 easily and combine the two.In the Gaussian case with an example 𝑓(𝑧),𝑞𝜙(𝑧)=1𝜎2𝜋exp((𝑧𝜇)22𝜎2)𝑓(𝑧)=2𝑧𝒮︀1𝜙(𝜀)=𝜀·𝜎+𝜇𝜕𝜕𝜇𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]=𝔼𝑞(𝜀)[𝑧𝑓(𝑧)𝜇𝒮︀1𝜙(𝜀)]=𝔼𝑞(𝜀)[2·1]=2𝜕𝜕𝜎𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]=𝔼𝑞(𝜀)[𝑧𝑓(𝑧)𝜎𝒮︀1𝜙(𝜀)]=𝔼𝑞(𝜀)[2·𝜀]=0While convenient for many functions, it may be difficult to find an appropriate inverse of the standardization function for many distributions. For example, the CDF is a feasible standardization function for univariate distributions but inverting/differentiating will be tricky.Implicit approachTo remove the need of finding the inverse of a standardization function, we turn to the implicit approach. First, we’ll rewrite our original equation:𝜙𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]=𝔼[𝑧𝑓(𝑧)𝜙𝑧]𝜙𝑧=𝜙𝒮︀1𝜙(𝜀)We don’t want to find the inverse. So instead, let’s start with the regular equation𝜀=𝒮︀𝜙(𝑧)Remember from single variable calculus how we do implicit differentation. We can write 𝑧=𝑧(𝜙), since if the parameters 𝜙 change, 𝑧 will change too. But 𝜀 is defined independent of 𝜙. Differentiating with respect to 𝜙 using the multivariable chain rule:0=dd𝜙𝒮︀𝜙(𝑧)0=𝑧𝒮︀𝜙(𝑧)𝜙𝑧+𝜙𝒮︀𝜙(𝑧)𝜙𝑧=(𝑧𝒮︀𝜙(𝑧))1(𝜙𝒮︀𝜙(𝑧))This formulation does not depend on the inverse.For the Gaussian case, remember our standardization function, and we need to compute three values:𝒮︀𝜙(𝑧)=𝑧𝜇𝜎𝑧𝒮︀𝜙(𝑧)=1𝜎𝜇𝒮︀𝜙(𝑧)=1𝜎𝜎𝒮︀𝜙(𝑧)=𝑧𝜇𝜎2𝜇𝑧=1𝜎𝑧=𝑧𝜇𝜎=𝜀which recovers values that we would obtain from the explicit approach. Using this, our final equation for the gradient of the expectation of 𝑓(𝑧) becomes:𝜙𝔼𝑞𝜙(𝑧)[𝑓(𝑧)]=𝔼𝑞𝜙(𝑧)[(𝑧𝑓(𝑧))(𝑧𝒮︀𝜙(𝑧))1(𝜙𝒮︀𝜙(𝑧))]