-1

Context

I would like to implement a custom loss function. Given the input and a predicted output there is a real life loss what can be calculated using the predicted output and some known real life facts which belongs to the input. I would prefer to use this real life meaning loss value as loss function instead of using any distance algorithm between the predicted output and expected output.

This real life loss for every given predicted output is between -10.0 and 50.0, where the higher the better, with other words this is the learning optimizing goal.

Question

What would Keras expect (or utilize in optimal way) as the loss function output? Should loss function output normalized between say between [1.0, 0.0]? Or just multiply [-10.0, 50.0] by -1 -> [-50.0, 10.0] and substract 10.0 -> [-60.0, 0.0]?

edit: I meant here: Or just multiply [-10.0, 50.0] by -1 -> [-50.0, 10.0] and add 50.0 -> [0.0, 60.0]?

Note

I am completely beginner in NN, so if I completely miss something here, just please point the right direction in the fewest words.

g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • This is not really a programming question, and this is usually answered in a basic NN/ML course. – Dr. Snoopy Jun 14 '22 at 07:38
  • Also note that it is very different to ask very basic programming questions (on topic) vs very basic machine learning questions (off-topic). – Dr. Snoopy Jun 14 '22 at 12:44
  • My point is that with an appropriate level of ML knowledge, you would notice that this does not depend on the framework. You are right that Keras should have a contract, but the contract does not cover the loss values. And again, there is a minimal level of ML that does not apply to programming, because this is a programming site, not a machine learning site. Keep that difference in mind. – Dr. Snoopy Jun 14 '22 at 13:25
  • Thx for the answer, if I understand correctly Keras have no expectation about custom loss function output, it would be in [0.0, max] with the optimal goal value 0.0 – g.pickardou Jun 14 '22 at 14:01
  • No, losses can be negative. – Dr. Snoopy Jun 14 '22 at 15:34

1 Answers1

1

By reading your question, I am able to interpret the "Real life loss value belonging to the input" as the "ground truth"/"expected output" of any input. The question seems vague to differentiate between your requirement and this.

  • 1
    many thx for your answer. I understand that is seems to be contradiction, that real life calculated loss *may* differ or *may* behave differently than creating an "expected" output, and use a conventional distance calculation between the predicted and the "expected". Still the question remain, if I calculate a *custom* loss, is there any convention or best practice, in which range the loss should be to allow built in fit function work correctly? – g.pickardou Jun 14 '22 at 06:05
  • I am still not very sure what you are trying to implement here, nevertheless, instead of actually trying to implement a second loss function, implement it as a metric (just like accuracy/precision/etc.). Take a look here -> https://stackoverflow.com/a/50648816/13748930 – Hetarth Chopra Jun 14 '22 at 06:19