I want to implement a new Criterion in torch7.
Basically, I have pair of samples for which I have a normalised similarity real value (let's denote it 'd').
Among existing Criterion, the closest I can have is the CosineEmbeddingCriterion which provides the following loss :
⎧ 1 - cos(x1, x2), if y == 1
loss(x, y) = ⎨
⎩ max(0, cos(x1, x2) - margin), if y == -1
Obviously this is designed for pairs, but this is for classification problems.
In my problem, I want to implement a Criterion that provide the following loss function :
loss(x1, y2, d) = | d - cos(x1,x2) |
Unfortunately, unlike in this question, it does not appear to me that I cannot simply combine existing criterion to do that.
So I plan to go on the painful way to create a new module from torch7 source file.
My questions are as follows :
(it seems to me very easy to write a criterion that seems correct to me -- but not in practise)
Thank you in advance for any clue !!
You just need to write the updateOutput
and updateGradInput
functions for your criterion. Then, you can use it like any other criterion. Here is a skeleton.