You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
local SafeLog, parent = torch.class('nn.SafeLog','nn.Module')
-- taking the log of 0 results in infinity; instead compute log(x + offset), where x >= 0. Since in the end we're interested in x*log(x), which -> 0 as x -> 0, this introduces very little error
function SafeLog:__init(offset)
parent.__init(self)
self.offset = offset or 1e-6
end
function SafeLog:updateOutput(input)
self.output:resizeAs(input):copy(input)
self.output:add(self.offset):log()
return self.output
end
function SafeLog:updateGradInput(input, gradOutput)