Implement the reparameterization step of a variational autoencoder using the supplied noise.
σ=exp(21logσ2) Z=μ+σ⊙εHere, μ and logσ2 describe a diagonal Gaussian, ε is the supplied standard-normal noise, and ⊙ denotes elementwise multiplication. Using supplied noise makes the operation deterministic and differentiable with respect to the distribution parameters. Return Z as a float64 NumPy array with the same shape as μ.
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
- VAE Encoder
- Reparameterization Trick
- VAE Decoder
- KL Divergence
- ELBO Loss
- Complete VAE
Accepts: array
Accepts: array
Accepts: array
Reparameterization Trick
Implement the reparameterization step of a variational autoencoder using the supplied noise.
σ=exp(21logσ2) Z=μ+σ⊙εHere, μ and logσ2 describe a diagonal Gaussian, ε is the supplied standard-normal noise, and ⊙ denotes elementwise multiplication. Using supplied noise makes the operation deterministic and differentiable with respect to the distribution parameters. Return Z as a float64 NumPy array with the same shape as μ.
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
- VAE Encoder
- Reparameterization Trick
- VAE Decoder
- KL Divergence
- ELBO Loss
- Complete VAE
Accepts: array
Accepts: array
Accepts: array