Skip to content

Instantly share code, notes, and snippets.

@amiltonwong
Created July 30, 2015 20:02
Show Gist options
  • Save amiltonwong/8bae6414839f8b2d8b0d to your computer and use it in GitHub Desktop.
Save amiltonwong/8bae6414839f8b2d8b0d to your computer and use it in GitHub Desktop.
require 'nn'
local ReQU = torch.class('nn.ReQU', 'nn.Module')
function ReQU:updateOutput(input)
-- TODO
self.output:resizeAs(input):copy(input)
-- ...something here...
--[[
if input > 0 then
self.output = torch.cmul(input,input)
else
self.output:zero()
--]]
self.output[torch.lt(self.output,0)] = 0
self.output[torch.gt(self.output,0)] = torch.pow(self.output[torch.gt(self.output,0)],2)
return self.output
end
function ReQU:updateGradInput(input, gradOutput)
-- TODO
self.gradInput:resizeAs(gradOutput):copy(gradOutput)
-- ...something here...
local dz_dx = torch.Tensor{}
dz_dx:resizeAs(input):copy(input)
dz_dx[torch.lt(dz_dx,0)] = 0
self.gradInput = gradOutput:cmul(dz_dx)
return self.gradInput
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment