Class: DNN::Layers::Lasso
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(l1_lambda = 0.01) ⇒ Lasso
Returns a new instance of Lasso.
377
378
379
380
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 377
def initialize(l1_lambda = 0.01)
super()
@l1_lambda = l1_lambda
end
|
Instance Attribute Details
#l1_lambda ⇒ Object
Returns the value of attribute l1_lambda.
374
375
376
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 374
def l1_lambda
@l1_lambda
end
|
Instance Method Details
#backward_node(dy) ⇒ Object
387
388
389
390
391
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 387
def backward_node(dy)
dx = Xumo::SFloat.ones(*@x.shape)
dx[@x < 0] = -1
@l1_lambda * dx
end
|
#forward_node(x) ⇒ Object
382
383
384
385
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 382
def forward_node(x)
@x = x
@l1_lambda * x.abs.sum
end
|
#load_hash(hash) ⇒ Object
397
398
399
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 397
def load_hash(hash)
initialize(hash[:l1_lambda])
end
|
#to_hash ⇒ Object
393
394
395
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 393
def to_hash
super(l1_lambda: @l1_lambda)
end
|