Class: DNN::Initializers::Xavier

Inherits:
Initializer show all
Defined in:
lib/dnn/core/initializers.rb

Instance Method Summary collapse

Methods inherited from Initializer

from_hash, #load_hash, #to_hash

Constructor Details

#initialize(seed: true) ⇒ Xavier

Returns a new instance of Xavier.



119
120
121
# File 'lib/dnn/core/initializers.rb', line 119

def initialize(seed: true)
  super
end

Instance Method Details

#init_param(layer, param) ⇒ Object



123
124
125
126
127
# File 'lib/dnn/core/initializers.rb', line 123

def init_param(layer, param)
  Xumo::SFloat.srand(@seed)
  num_prev_units = layer.input_shape.reduce(:*)
  param.data = param.data.rand_norm / Math.sqrt(num_prev_units)
end