My general question is how can I add a customized and complex loss function to neural network?

I have to address this issue ASAP, because I did not find any good examples that can do it. In the loss function documentation there is a short and simple example, but I did not succeed to expand it to more complex loss function and to implement a code that do what I want. I think I'm missing something, and I wish for a well organized tutorial for this purpose, if someone can refer to me, please.

I have one example, but I do not want to limit the answers only for this example.

So, if I have a 1D signal as an input (x), and I trained a net to get a similar 1D signal as the output (y). The network is using the default loss function (e.g. CrossEntropyLossLayer). I want to add an expression to the loss function (and sill use the CrossEntropyLossLayer in addition to it) , so it will minimize the values between two succeeding samples. For examples something like:

∑n ‖x(n+1)-x(n) ‖

This loss does not deal with y, only with x.

How can I do it ? What is the right way to customize the loss function ?

I hope someone can help me. I;m using Mathematica 11.3

Thank you very much!

  • 1
    $\begingroup$ Maybe this will help: mathematica.stackexchange.com/q/183685/242 $\endgroup$ – Niki Estner Jan 30 '19 at 12:28
  • $\begingroup$ You will need to create a NetChain or NetGraph constructed from the net layers. By "two succeeding samples", do you mean, sample[[n]] and sample[[n+1]], or two samples that are successful (in some way)? If it's the first case, you may find this difficult because (I believe) typically the loss functions do not know specifics about previous or future examples. $\endgroup$ – Carl Lange Jan 30 '19 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.