Hi Everyone,
I hope to implement a criterion function that performing the weighted MSE. This criterion will be very useful when we solving some multi-output regression problems in deep learning. I know there are some existed functions such as MultiCriterion that used to compute the 'weighted' stuffs. However, MultiCriterion assign same weights to all the samples. I hope to assign different weights to different variables in different samples. For example:
1. The Target of Sample 1 includes 3 variables: [a1, b1, c1]. The corresponding output of our DNN is: [a01, b01, c01]. The Weighted MSE should be:
1/3*((w11*(a1-a01)^2 + w12*(b1-b01)^2 + w13*(c1-c01)^2).
2. The Target of Sample 2 also have 3 variables: [a2, b2, c2]. The corresponding output of the DNN is: [a02, b02, c02]. The Weighted MSE should be:
1/3*((w21*(a2-a02)^2 + w22*(b2-b02)^2 + w23*(c2-c02)^2).
We assigned different weights [w11,w12,w13];[w21,w22,w23] to the MSE of different samples (1 and 2). Is there a way to implement this criterion ?
I have an idea but I'm not sure whether it could work:
Could we do something like this ?
function Weighted_MSECriterion:updateOutput(input, target)
self.output = 0
for i=1,#self.criterions do
self.output = self.output + self.weights[i]*(input[i] - target[i])^2
end
return self.output
end
But, I carefully read the existed files and not sure whether we could do something like 'input[i]' when define a criterion function. They always transfer the whole 'input' and 'target' into a *.c file to compute the criterion without explicitly indexing any elements in 'input' like 'input[i]'. Could we use input[i] and target[i] in Weighted_MSECriterion:updateOutput ? Why the original developers do not use this simple expression to compute MSE ?
Thank you so much !