Class: DNN::Initializers::RandomUniform

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min = -0.05,, max = 0.05, seed: true) ⇒ RandomUniform

Returns a new instance of RandomUniform.

Parameters:

  • min (Float) (defaults to: -0.05,) —

    Min of initialization value.

  • max (Float) (defaults to: 0.05) —

    Max of initialization value.



93
94
95
96
97
# File 'lib/dnn/core/initializers.rb', line 93

def initialize(min = -0.05, max = 0.05, seed: true)
  super(seed: seed)
  @min = min
  @max = max
end

Instance Attribute Details

#max ⇒ Object (readonly)

Returns the value of attribute max.



85
86
87
# File 'lib/dnn/core/initializers.rb', line 85

def max
  @max
end

#min ⇒ Object (readonly)

Returns the value of attribute min.



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

def min
  @min
end

Class Method Details

.from_hash(hash) ⇒ Object



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

def self.from_hash(hash)
  self.new(hash[:min], hash[:max], seed: hash[:seed])
end

Instance Method Details

#init_param(layer, param) ⇒ Object



99
100
101
102
# File 'lib/dnn/core/initializers.rb', line 99

def init_param(layer, param)
  Xumo::SFloat.srand(@seed)
  param.data = param.data.rand(@min, @max)
end

#to_hash ⇒ Object



104
105
106
# File 'lib/dnn/core/initializers.rb', line 104

def to_hash
  super(min: @min, max: @max)
end