Class: DNN::Layers::Dropout
- Includes:
- LayerNode
- Defined in:
- lib/dnn/core/layers/basic_layers.rb
Instance Attribute Summary collapse
-
#dropout_ratio ⇒ Object
Returns the value of attribute dropout_ratio.
-
#use_scale ⇒ Object
readonly
Returns the value of attribute use_scale.
Attributes inherited from Layer
Instance Method Summary collapse
- #backward_node(dy) ⇒ Object
- #forward_node(x) ⇒ Object
-
#initialize(dropout_ratio = 0.5, seed: rand(1 << 31), use_scale: true) ⇒ Dropout
constructor
A new instance of Dropout.
- #load_hash(hash) ⇒ Object
- #to_hash ⇒ Object
Methods included from LayerNode
Methods inherited from Layer
#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash
Constructor Details
#initialize(dropout_ratio = 0.5, seed: rand(1 << 31), use_scale: true) ⇒ Dropout
Returns a new instance of Dropout.
427 428 429 430 431 432 433 434 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 427 def initialize(dropout_ratio = 0.5, seed: rand(1 << 31), use_scale: true) super() @dropout_ratio = dropout_ratio @seed = seed @use_scale = use_scale @mask = nil @rnd = Random.new(@seed) end |
Instance Attribute Details
#dropout_ratio ⇒ Object
Returns the value of attribute dropout_ratio.
421 422 423 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 421 def dropout_ratio @dropout_ratio end |
#use_scale ⇒ Object (readonly)
Returns the value of attribute use_scale.
422 423 424 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 422 def use_scale @use_scale end |
Instance Method Details
#backward_node(dy) ⇒ Object
447 448 449 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 447 def backward_node(dy) dy * @mask end |
#forward_node(x) ⇒ Object
436 437 438 439 440 441 442 443 444 445 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 436 def forward_node(x) if DNN.learning_phase Xumo::SFloat.srand(@rnd.rand(1 << 31)) @mask = Xumo::SFloat.cast(Xumo::SFloat.new(*x.shape).rand >= @dropout_ratio) x = x * @mask elsif @use_scale x *= (1 - @dropout_ratio) end x end |
#load_hash(hash) ⇒ Object
455 456 457 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 455 def load_hash(hash) initialize(hash[:dropout_ratio], seed: hash[:seed], use_scale: hash[:use_scale]) end |
#to_hash ⇒ Object
451 452 453 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 451 def to_hash super(dropout_ratio: @dropout_ratio, seed: @seed, use_scale: @use_scale) end |