I am new to Torch and I want to create a custom loss function in Torch which is a modification of ClassNLLCriterion. Concretely, ClassNLLCriterion loss is:
loss(x, class) = -x[class]
I want to modify this to be:
loss(x, class) = -x[class] + F(x)
where F(x) is a function that looks x up in a table (as a key) and outputs its value.
My question is, what's the correct way of implementing this custom criterion? The updateOutput() function seems straightforward, but how do I implement the updateGradInput() function?