Class: Chainer::Initializers::HeNormal

Inherits:
Chainer::Initializer show all
Defined in:
lib/chainer/initializers/normal.rb

Instance Attribute Summary

Attributes inherited from Chainer::Initializer

#dtype

Instance Method Summary collapse

Constructor Details

#initialize(scale: 1.0, dtype: nil) ⇒ HeNormal

Returns a new instance of HeNormal.



16
17
18
19
# File 'lib/chainer/initializers/normal.rb', line 16

def initialize(scale: 1.0, dtype: nil)
  @scale = scale
  super(dtype: dtype)
end

Instance Method Details

#call(array) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/chainer/initializers/normal.rb', line 21

def call(array)
  # TODO(sonots): pass device from outside
  device = Chainer::Device.default
  fan_in, fan_out = Chainer::Utils::Initializer.get_fans(array.shape, device: device)
  s = @scale * device.xm::NMath.sqrt(2.0 / fan_in)
  Normal.new(scale: s).(array)
end