PIXELBANKv9.1.0
Menu

Implement the forward pass of a simple autoencoder with one hidden (bottleneck) layer.

An autoencoder has:

  • Encoder: z=ReLU(Weâ‹…x+be)z = \text{ReLU}(W_e \cdot x + b_e) — compress input to bottleneck
  • Decoder: x^=Wdâ‹…z+bd\hat{x} = W_d \cdot z + b_d — reconstruct from bottleneck

Given input xx, encoder weights/bias, and decoder weights/bias, compute both the bottleneck representation zz and the reconstruction x^\hat{x}.

Return a tuple (z, x_hat) both as lists rounded to 4 decimal places.

Example:

Input:
x = [1, 2, 3]
W_e = [[0.5, 0.5, 0.5]]
b_e = [0]
W_d = [[1], [1], [1]]
b_d = [0, 0, 0]
Output:
([3.0], [3.0, 3.0, 3.0])
Reasoning:
  • First, we calculate the bottleneck representation zz using the encoder: z=ReLU(Weâ‹…x+be)=ReLU([0.5,0.5,0.5]â‹…[1,2,3]+[0])=ReLU([0.5∗1+0.5∗2+0.5∗3]+[0])=ReLU([1.5+1+1.5]+[0])=ReLU([4]+[0])=ReLU([4])=[3.0]z = \text{ReLU}(W_e \cdot x + b_e) = \text{ReLU}([0.5, 0.5, 0.5] \cdot [1, 2, 3] + [0]) = \text{ReLU}([0.5*1 + 0.5*2 + 0.5*3] + [0]) = \text{ReLU}([1.5 + 1 + 1.5] + [0]) = \text{ReLU}([4] + [0]) = \text{ReLU}([4]) = [3.0]
  • Then, we calculate the reconstruction x^\hat{x} using the decoder: x^=Wdâ‹…z+bd=[[1],[1],[1]]â‹…[3.0]+[0,0,0]=[3.0,3.0,3.0]\hat{x} = W_d \cdot z + b_d = [[1], [1], [1]] \cdot [3.0] + [0, 0, 0] = [3.0, 3.0, 3.0]
  • The final output is a tuple containing the bottleneck representation zz and the reconstruction x^\hat{x}: ([3.0],[3.0,3.0,3.0])([3.0], [3.0, 3.0, 3.0])

Constraints:

  • x: 1D list (d_in)
  • W_e: 2D list (d_hidden x d_in), b_e: 1D list (d_hidden)
  • W_d: 2D list (d_in x d_hidden), b_d: 1D list (d_in)
  • Return (z, x_hat) both rounded to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.
Autoencoder Bottleneck - Easy | PixelBank