Class: DNN::Layers::Ridge

Inherits:
Layer
  • Object
show all
Includes:
LayerNode
Defined in:
lib/dnn/core/layers/basic_layers.rb

Instance Attribute Summary collapse

Attributes inherited from Layer

#input_shape

Instance Method Summary collapse

Methods included from LayerNode

#backward, #forward

Methods inherited from Layer

#build, #built?, #call, call, #clean, #forward, from_hash, #output_shape

Constructor Details

#initialize(l2_lambda = 0.01) ⇒ Ridge

Returns a new instance of Ridge.

Parameters:

  • l2_lambda (Float) (defaults to: 0.01)

    L2 regularizer coefficient.



408
409
410
411
# File 'lib/dnn/core/layers/basic_layers.rb', line 408

def initialize(l2_lambda = 0.01)
  super()
  @l2_lambda = l2_lambda
end

Instance Attribute Details

#l2_lambdaObject

Returns the value of attribute l2_lambda.



405
406
407
# File 'lib/dnn/core/layers/basic_layers.rb', line 405

def l2_lambda
  @l2_lambda
end

Instance Method Details

#backward_node(dy) ⇒ Object



418
419
420
# File 'lib/dnn/core/layers/basic_layers.rb', line 418

def backward_node(dy)
  @l2_lambda * @x
end

#forward_node(x) ⇒ Object



413
414
415
416
# File 'lib/dnn/core/layers/basic_layers.rb', line 413

def forward_node(x)
  @x = x
  0.5 * @l2_lambda * (x**2).sum
end

#load_hash(hash) ⇒ Object



426
427
428
# File 'lib/dnn/core/layers/basic_layers.rb', line 426

def load_hash(hash)
  initialize(hash[:l2_lambda])
end

#to_hashObject



422
423
424
# File 'lib/dnn/core/layers/basic_layers.rb', line 422

def to_hash
  super(l2_lambda: @l2_lambda)
end