Losses

Losses#

Sparsity objectives minimized during training.

Loss functions for sparse basis training.

Mirror of upstream src/loss.jl. loss_function is the loss of one image; basis_loss and mean_loss are the closures over a basis that the trainers differentiate.

Contents

L1Norm

L1 norm loss: minimizes sum(|T(x)|) to encourage sparsity.

MSELoss

MSE loss with top-k truncation: ||x - T^{-1}(truncate(T(x), k))||^2.

AbstractLoss

Marker protocol for loss types.

loss_function

Compute scalar loss for a single image under the given circuit.

basis_loss

(tensors, image) -> scalar: loss of one image under basis's circuit.

mean_loss

(tensors, batch) -> scalar: the mean of basis_loss over a stack of images.

topk_truncate

Keep the k coefficients with largest absolute value; zero the rest.