Skip to content

Commit

Permalink
refactor/cleanup of ParallelCriterion
Browse files Browse the repository at this point in the history
  • Loading branch information
soumith committed Jun 11, 2015
1 parent b526153 commit 346de6b
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions ParallelCriterion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,19 @@ end

function ParallelCriterion:updateOutput(input, target)
self.output = 0
if not self.repeatTarget then
for i,criterion in ipairs(self.criterions) do
self.output = self.output + self.weights[i]*criterion:updateOutput(input[i],target[i])
end
else
for i,criterion in ipairs(self.criterions) do
self.output = self.output + self.weights[i]*criterion:updateOutput(input[i],target)
end
for i,criterion in ipairs(self.criterions) do
local target = self.repeatTarget and target or target[i]
self.output = self.output + self.weights[i]*criterion:updateOutput(input[i],target)
end
return self.output
end

function ParallelCriterion:updateGradInput(input, target)
if not self.repeatTarget then
for i,criterion in ipairs(self.criterions) do
self.gradInput[i] = input[i].new() or self.gradInput[i]
self.gradInput[i]:resizeAs(input[i]):zero()
self.gradInput[i]:add(self.weights[i], criterion:updateGradInput(input[i],target[i]))
end
else
for i,criterion in ipairs(self.criterions) do
self.gradInput[i] = input[i].new() or self.gradInput[i]
self.gradInput[i]:resizeAs(input[i]):zero()
self.gradInput[i]:add(self.weights[i], criterion:updateGradInput(input[i],target))
end
for i,criterion in ipairs(self.criterions) do
local target = self.repeatTarget and target or target[i]
self.gradInput[i] = self.gradInput[i] or input[i].new()
self.gradInput[i]:resizeAs(input[i]):zero()
self.gradInput[i]:add(self.weights[i], criterion:updateGradInput(input[i],target))
end
return self.gradInput
end
Expand Down

0 comments on commit 346de6b

Please sign in to comment.