Implement a deterministic variational-autoencoder forward pass by connecting the encoder, reparameterization step, and Bernoulli decoder.
μ=XWμ+bμ logσ2=XWlogσ2+blogσ2 Z=μ+exp(21logσ2)⊙ε X=σ(ZWdec+bdec)Here, X is the input batch, ε is supplied noise, Z is the latent sample, and X is the Bernoulli reconstruction. Return a Python dictionary with exactly reconstruction, mu, log_var, and z. Every value must be a float64 NumPy array.
Examples
Input: x = [[1,0,-1],[0.5,0.5,0.5]], epsilon = [[0.5,-0.5],[1,0]], W_mu = [[0.1,0.2],[-0.1,0.3],[0.2,-0.1]], b_mu = [0,0], W_logvar = [[0.1,-0.1],[0,0.1],[-0.1,0]], b_logvar = [0,0], W_dec = [[-0.2,0.1,0.3],[0.1,-0.2,0.1]], b_dec = [0,0,0]
Output: {"reconstruction":[[0.473007,0.520085,0.529519],[0.450166,0.517493,0.586618]],"mu":[[-0.1,0.3],[0.1,0.2]],"log_var":[[0.2,-0.1],[0,0]],"z":[[0.452585,-0.175615],[1.1,0.2]]}
Explanation: The supplied parameters deterministically connect posterior estimation, latent sampling, and reconstruction.
Input: x = [[1,-1]], epsilon = [[0.25]], W_mu = [[0.3],[-0.2]], b_mu = [0.1], W_logvar = [[0.1],[0.2]], b_logvar = [-0.1], W_dec = [[0.4,-0.5]], b_dec = [0.1,0.2]
Output: {"reconstruction":[[0.605989,0.446925]],"mu":[[0.6]],"log_var":[[-0.2]],"z":[[0.826209]]}
Input: x = [[0.2,0.8],[-0.5,0.5]], epsilon = [[0,0],[0,0]], W_mu = [[0.2,-0.1],[0.3,0.4]], b_mu = [0,0.1], W_logvar = [[-0.2,0.1],[0.1,-0.3]], b_logvar = [0,0], W_dec = [[0.5,-0.2],[0.1,0.3]], b_dec = [-0.1,0.05]
Output: {"reconstruction":[[0.519989,0.528469],[0.490001,0.536187]],"mu":[[0.28,0.4],[0.05,0.35]],"log_var":[[0.04,-0.22],[0.15,-0.2]],"z":[[0.28,0.4],[0.05,0.35]]}
Hint 1
Compute mu and log_var before constructing z.
Hint 2
Use the supplied epsilon in the reparameterization expression.
Hint 3
Apply sigmoid only after the decoder affine projection.
Requirements
- Use NumPy and only the supplied deterministic parameters.
- Compute both encoder projections.
- Reparameterize with the supplied epsilon.
- Apply the decoder projection and sigmoid.
- Return exactly the four documented float64 arrays.
Constraints
- x has shape (B, D), and epsilon has shape (B, L).
- Encoder weights have shape (D, L), and encoder biases have shape (L).
- W_dec has shape (L, D), and b_dec has shape (D).
- Every numeric input has dtype float64 and contains finite values.
- B, D, and L are positive.
All steps in VAE
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Complete VAE
Implement a deterministic variational-autoencoder forward pass by connecting the encoder, reparameterization step, and Bernoulli decoder.
μ=XWμ+bμ logσ2=XWlogσ2+blogσ2 Z=μ+exp(21logσ2)⊙ε X=σ(ZWdec+bdec)Here, X is the input batch, ε is supplied noise, Z is the latent sample, and X is the Bernoulli reconstruction. Return a Python dictionary with exactly reconstruction, mu, log_var, and z. Every value must be a float64 NumPy array.
Examples
Input: x = [[1,0,-1],[0.5,0.5,0.5]], epsilon = [[0.5,-0.5],[1,0]], W_mu = [[0.1,0.2],[-0.1,0.3],[0.2,-0.1]], b_mu = [0,0], W_logvar = [[0.1,-0.1],[0,0.1],[-0.1,0]], b_logvar = [0,0], W_dec = [[-0.2,0.1,0.3],[0.1,-0.2,0.1]], b_dec = [0,0,0]
Output: {"reconstruction":[[0.473007,0.520085,0.529519],[0.450166,0.517493,0.586618]],"mu":[[-0.1,0.3],[0.1,0.2]],"log_var":[[0.2,-0.1],[0,0]],"z":[[0.452585,-0.175615],[1.1,0.2]]}
Explanation: The supplied parameters deterministically connect posterior estimation, latent sampling, and reconstruction.
Input: x = [[1,-1]], epsilon = [[0.25]], W_mu = [[0.3],[-0.2]], b_mu = [0.1], W_logvar = [[0.1],[0.2]], b_logvar = [-0.1], W_dec = [[0.4,-0.5]], b_dec = [0.1,0.2]
Output: {"reconstruction":[[0.605989,0.446925]],"mu":[[0.6]],"log_var":[[-0.2]],"z":[[0.826209]]}
Input: x = [[0.2,0.8],[-0.5,0.5]], epsilon = [[0,0],[0,0]], W_mu = [[0.2,-0.1],[0.3,0.4]], b_mu = [0,0.1], W_logvar = [[-0.2,0.1],[0.1,-0.3]], b_logvar = [0,0], W_dec = [[0.5,-0.2],[0.1,0.3]], b_dec = [-0.1,0.05]
Output: {"reconstruction":[[0.519989,0.528469],[0.490001,0.536187]],"mu":[[0.28,0.4],[0.05,0.35]],"log_var":[[0.04,-0.22],[0.15,-0.2]],"z":[[0.28,0.4],[0.05,0.35]]}
Hint 1
Compute mu and log_var before constructing z.
Hint 2
Use the supplied epsilon in the reparameterization expression.
Hint 3
Apply sigmoid only after the decoder affine projection.
Requirements
- Use NumPy and only the supplied deterministic parameters.
- Compute both encoder projections.
- Reparameterize with the supplied epsilon.
- Apply the decoder projection and sigmoid.
- Return exactly the four documented float64 arrays.
Constraints
- x has shape (B, D), and epsilon has shape (B, L).
- Encoder weights have shape (D, L), and encoder biases have shape (L).
- W_dec has shape (L, D), and b_dec has shape (D).
- Every numeric input has dtype float64 and contains finite values.
- B, D, and L are positive.
All steps in VAE
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array