The ML framework has a limited set of loss functions available. How can I extend this by creating my own custom ones?
For example, for L2-regularized training, Mathematica recommends
NetTrain[
net, data, All,
Method -> {"SGD", "L2Regularization" -> 0.01}
]
Question: How is L2Regularization implemented here? Is there a way to probe how Mathematica implements this and the functional form of the loss function?
Instead, I would like to have a loss function that has L2-regularization: $$loss = MSE + \lambda(||parameter||_2) $$
This would be a starting point to play around with different kinds of regularization.
As another example (Example 3.2 : https://reference.wolfram.com/language/ref/LossFunction.html), they created a MSE loss function; I want to add regularization (l1 and l2) to it.
Edit: To make it precise, how can I add regularization in the loss net below:
lossNet =
NetGraph[<|"net" -> net, "loss" -> ThreadingLayer[(#1 - #2)^2 &]|>, {{"net", NetPort["Target"]} -> "loss" -> NetPort["Loss"]}]
FindFit
in version 12 offersFitRegularization
as an option. $\endgroup$FitRegularization
help me construct loss function for neural net? $\endgroup$LinearModelFit
orNonlinearModelFit
.) $\endgroup$