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) σ(a)=1+e−a1Here, Z∈RB×L contains latent samples, Wdec∈RL×D is the decoder weight matrix, and bdec∈RD is the decoder bias. Return X as a float64 NumPy array with shape (B,D).
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.
All steps in VAE
Accepts: array
Accepts: array
Accepts: array
VAE Decoder
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) σ(a)=1+e−a1Here, Z∈RB×L contains latent samples, Wdec∈RL×D is the decoder weight matrix, and bdec∈RD is the decoder bias. Return X as a float64 NumPy array with shape (B,D).
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.
All steps in VAE
Accepts: array
Accepts: array
Accepts: array