Browse Source

Fix gradient scale in WeightedMSECriterion

nagadomi 9 years ago
parent
commit
9d63ed2947
1 changed files with 2 additions and 1 deletions
  1. 2 1
      lib/WeightedMSECriterion.lua

+ 2 - 1
lib/WeightedMSECriterion.lua

@@ -19,6 +19,7 @@ function WeightedMSECriterion:updateOutput(input, target)
 end
 
 function WeightedMSECriterion:updateGradInput(input, target)
-   self.gradInput:resizeAs(input):copy(self.diff)
+   local norm = 2.0 / input:nElement()
+   self.gradInput:resizeAs(input):copy(self.diff):mul(norm)
    return self.gradInput
 end