Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SoftSign.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 480894c7198a9d446d6c84463b6ccb50f02df8cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local SoftSign = torch.class('nn.SoftSign', 'nn.Module')

function SoftSign:updateOutput(input)
   self.temp = self.temp or input.new()
   self.temp:resizeAs(input):copy(input):abs():add(1)
   self.output:resizeAs(input):copy(input):cdiv(self.temp)
   return self.output
end

function SoftSign:updateGradInput(input, gradOutput)
   self.tempgrad = self.tempgrad or input.new()
   self.tempgrad:resizeAs(self.output):copy(input):abs():add(1):cmul(self.tempgrad)
   self.gradInput:resizeAs(input):copy(gradOutput):cdiv(self.tempgrad)
   return self.gradInput
end