Problems
Loading...
Step 6 of 6
Complete VAE
Easy

Implement a deterministic variational-autoencoder forward pass by connecting the encoder, reparameterization step, and Bernoulli decoder.

μ=XWμ+bμ\mu = XW_{\mu} + b_{\mu} log⁡σ2=XWlog⁡σ2+blog⁡σ2\log \sigma^2 = XW_{\log \sigma^2} + b_{\log \sigma^2} Z=μ+exp⁡(12log⁡σ2)⊙εZ = \mu + \exp\left(\frac{1}{2}\log \sigma^2\right) \odot \varepsilon X^=σ(ZWdec+bdec)\widehat{X} = \sigma(ZW_{\mathrm{dec}} + b_{\mathrm{dec}})

Here, XX is the input batch, ε\varepsilon is supplied noise, ZZ is the latent sample, and X^\widehat{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.

Loading visualization...

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.