Problems
Loading...
Step 2 of 6
Reparameterization Trick
Easy

Implement the reparameterization step of a variational autoencoder using the supplied noise.

σ=exp⁡(12log⁡σ2)\sigma = \exp\left(\frac{1}{2}\log \sigma^2\right) Z=μ+σ⊙εZ = \mu + \sigma \odot \varepsilon

Here, μ\mu and log⁡σ2\log \sigma^2 describe a diagonal Gaussian, ε\varepsilon is the supplied standard-normal noise, and ⊙\odot denotes elementwise multiplication. Using supplied noise makes the operation deterministic and differentiable with respect to the distribution parameters. Return ZZ as a float64 NumPy array with the same shape as μ\mu.

Loading visualization...

Examples

Input: mu = [[0.5,-0.3],[0.1,0.8]], log_var = [[-1,0.5],[0.2,-0.5]], epsilon = [[0.3,-0.7],[1.2,0.1]]

Output: [[0.681959,-1.198818],[1.426205,0.87788]]

Explanation: The standard deviation scales the supplied noise before it is shifted by the latent mean.

Input: mu = [[1,-2,0.5]], log_var = [[0,1,-1]], epsilon = [[0,0,0]]

Output: [[1,-2,0.5]]

Input: mu = [[0,0],[1,-1]], log_var = [[0,0],[0,0]], epsilon = [[-0.5,0.25],[0.75,-0.2]]

Output: [[-0.5,0.25],[1.75,-1.2]]

Hint 1

Compute the standard deviation with np.exp(0.5 * log_var).

Hint 2

Combine the three arrays elementwise.

Requirements

  • Use NumPy.
  • Convert log-variance to standard deviation.
  • Use the supplied epsilon without sampling new noise.
  • Return a float64 NumPy array with the documented shape.

Constraints

  • mu, log_var, and epsilon have the same shape (B, L).
  • All three arrays have dtype float64 and contain finite values.
  • B and L are positive.

All steps in VAE

  1. VAE Encoder
  2. Reparameterization Trick
  3. VAE Decoder
  4. KL Divergence
  5. ELBO Loss
  6. Complete VAE