Class: DNN::Initializers::RandomNormal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Initializer

from_hash

Constructor Details

#initialize(mean = 0, std = 0.05, seed: true) ⇒ RandomNormal

Returns a new instance of RandomNormal.

Parameters:

  • mean (Float) (defaults to: 0)

    Average of initialization value.

  • std (Float) (defaults to: 0.05)

    Variance of initialization value.



72
73
74
75
76
# File 'lib/dnn/core/initializers.rb', line 72

def initialize(mean = 0, std = 0.05, seed: true)
  super(seed: seed)
  @mean = mean
  @std = std
end

Instance Attribute Details

#meanObject (readonly)

Returns the value of attribute mean.



67
68
69
# File 'lib/dnn/core/initializers.rb', line 67

def mean
  @mean
end

#stdObject (readonly)

Returns the value of attribute std.



68
69
70
# File 'lib/dnn/core/initializers.rb', line 68

def std
  @std
end

Instance Method Details

#init_param(layer, param) ⇒ Object



78
79
80
81
# File 'lib/dnn/core/initializers.rb', line 78

def init_param(layer, param)
  Xumo::SFloat.srand(@seed)
  param.data = param.data.rand_norm(@mean, @std)
end

#load_hash(hash) ⇒ Object



87
88
89
# File 'lib/dnn/core/initializers.rb', line 87

def load_hash(hash)
  initialize(hash[:mean], hash[:std], seed: hash[:seed])
end

#to_hashObject



83
84
85
# File 'lib/dnn/core/initializers.rb', line 83

def to_hash
  super(mean: @mean, std: @std)
end