Two autoencoder regularisers from Murphy's book, for a sigmoid encoder with W of shape (K, D), b of shape (K,) and inputs as rows of X (shape (N, D)).
contractive_penalty(W, b, X): the contractive autoencoder penalty (without ), averaged over the rows of X. Use the closed form of the sigmoid encoder's Jacobian. Return a Python float.
encoder_jacobian(W, b, x): the (K, D) Jacobian at a single input x.
kl_sparsity(H, rho): for hidden activations H (shape (N, K), entries in ) with mean activation , return as a Python float.
kl_sparsity_grad(H, rho): the (N, K) gradient of kl_sparsity with respect to H.