Problems
Loading...
Step 3 of 6
VAE Decoder
Easy

Implement a Bernoulli variational-autoencoder decoder. Project each latent vector into the data width, add the supplied bias, and apply a sigmoid so every reconstructed feature lies between zero and one.

X^=σ(ZWdec+bdec)\widehat{X} = \sigma(ZW_{\mathrm{dec}} + b_{\mathrm{dec}}) σ(a)=11+e−a\sigma(a) = \frac{1}{1+e^{-a}}

Here, Z∈RB×LZ \in \mathbb{R}^{B \times L} contains latent samples, Wdec∈RL×DW_{\mathrm{dec}} \in \mathbb{R}^{L \times D} is the decoder weight matrix, and bdec∈RDb_{\mathrm{dec}} \in \mathbb{R}^{D} is the decoder bias. Return X^\widehat{X} as a float64 NumPy array with shape (B,D)(B,D).

Loading visualization...

Examples

Input: z = [[0.5,-0.3],[1,0.2]], W_dec = [[0.4,-0.2,0.1],[0.3,0.5,-0.4]], b_dec = [0.1,-0.1,0.2]

Output: [[0.552308,0.413382,0.591459],[0.636453,0.450166,0.554779]]

Explanation: The affine decoder logits are converted into Bernoulli feature probabilities by sigmoid.

Input: z = [[-1,0.5],[0,2]], W_dec = [[0.6],[-0.2]], b_dec = [0.05]

Output: [[0.34299],[0.413382]]

Input: z = [[0,0,0]], W_dec = [[0.1,0.2],[-0.3,0.4],[0.5,-0.2]], b_dec = [-0.4,0.7]

Output: [[0.401312,0.668188]]

Hint 1

Broadcast b_dec across the rows of z @ W_dec.

Hint 2

Apply np.exp inside the sigmoid expression.

Requirements

  • Use NumPy.
  • Apply the supplied affine decoder projection.
  • Apply sigmoid elementwise to the projected values.
  • Return a float64 NumPy array with shape (B, D).

Constraints

  • z has shape (B, L) and dtype float64.
  • W_dec has shape (L, D) and dtype float64.
  • b_dec has shape (D) and dtype float64.
  • B, L, and D are positive.