All problems
Sparse Autoencoder Loss
Problem
Compute the sparse autoencoder objective: mean squared reconstruction error plus l1_coeff times the mean absolute feature activation.
The signature is sparse_autoencoder_loss(x, x_hat, features, l1_coeff).
Hint
The L1 term keeps the dictionary features sparse and interpretable.
Test cases
case 1
in: [[1,0],[1,0],[0.5,0],0.1]
expected: 0.025
case 2
in: [[1,1],[0,0],[0.5,0.5],1]
expected: 1.5
case 3
in: [[0.5],[0.5],[-0.2],2]
expected: 0.4
case 4
in: [[1,2,3],[1,2,3],[0,0,0],0.5]
expected: 0
Starter codePython
def sparse_autoencoder_loss(x, x_hat, features, l1_coeff):
# Your code here
pass4 test cases · run your code against them in the editor