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

WhiteNoise.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f1defb6463a2a73a5b844e211d9432cdf87d6094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local WhiteNoise, parent = torch.class('nn.WhiteNoise', 'nn.Module')

function WhiteNoise:__init(mean, std)
   parent.__init(self)
   self.mean = mean or 0
   self.std = std or 0.1
   self.noise = torch.Tensor()
end

function WhiteNoise:updateOutput(input)
   self.output:resizeAs(input):copy(input)
   if self.train ~= false then
      self.noise:resizeAs(input)
      self.noise:normal(self.mean, self.std)
      self.output:add(self.noise)
   else
      if self.mean ~= 0 then
         self.output:add(self.mean)
      end
   end
   return self.output
end

function WhiteNoise:updateGradInput(input, gradOutput)
   if self.train ~= false then
      -- Simply return the gradients.
      self.gradInput:resizeAs(gradOutput):copy(gradOutput)
   else
      error('backprop only defined while training')
   end
   return self.gradInput
end

function WhiteNoise:clearState()
   self.noise:set()
end

function WhiteNoise:__tostring__()
  return string.format('%s mean: %f, std: %f', torch.type(self), self.mean, self.std)
end