Class: DNN::Layers::Lasso

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, #output_shape

Instance Method Summary collapse

Methods included from LayerNode

#forward

Methods inherited from Layer

#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash

Constructor Details

#initialize(l1_lambda = 0.01) ⇒ Lasso

Returns a new instance of Lasso.

Parameters:

  • l1_lambda (Float) (defaults to: 0.01)

    L1 regularizer coefficient.



364
365
366
367
# File 'lib/dnn/core/layers/basic_layers.rb', line 364

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

Instance Attribute Details

#l1_lambdaObject

Returns the value of attribute l1_lambda.



361
362
363
# File 'lib/dnn/core/layers/basic_layers.rb', line 361

def l1_lambda
  @l1_lambda
end

Instance Method Details

#backward_node(dy) ⇒ Object



374
375
376
377
378
# File 'lib/dnn/core/layers/basic_layers.rb', line 374

def backward_node(dy)
  dx = Xumo::SFloat.ones(*@x.shape)
  dx[@x < 0] = -1
  @l1_lambda * dx
end

#forward_node(x) ⇒ Object



369
370
371
372
# File 'lib/dnn/core/layers/basic_layers.rb', line 369

def forward_node(x)
  @x = x
  @l1_lambda * x.abs.sum
end

#load_hash(hash) ⇒ Object



384
385
386
# File 'lib/dnn/core/layers/basic_layers.rb', line 384

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

#to_hashObject



380
381
382
# File 'lib/dnn/core/layers/basic_layers.rb', line 380

def to_hash
  super(l1_lambda: @l1_lambda)
end