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

TanhShrink.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96df6c5b7ddd89f2a0ce7fae38b7ac24e076a496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local TanhShrink, parent = torch.class('nn.TanhShrink','nn.Module')

function TanhShrink:__init()
   parent.__init(self)
   self.tanh = nn.Tanh()
end

function TanhShrink:updateOutput(input)
   local th = self.tanh:updateOutput(input)
   self.output:resizeAs(input):copy(input)
   self.output:add(-1,th)
   return self.output
end

function TanhShrink:updateGradInput(input, gradOutput)
   local dth = self.tanh:updateGradInput(input,gradOutput)
   self.gradInput:resizeAs(input):copy(gradOutput)
   self.gradInput:add(-1,dth)
   return self.gradInput
end