Class: DNN::Regularizers::L1

Inherits:
Regularizer show all
Defined in:
lib/dnn/core/regularizers.rb

Instance Attribute Summary

Attributes inherited from Regularizer

#param

Instance Method Summary collapse

Methods inherited from Regularizer

from_hash

Constructor Details

#initialize(l1_lambda = 0.01) ⇒ L1

Returns a new instance of L1.

Parameters:

  • l1_lambda (Float) (defaults to: 0.01)

    L1 regularizer coefficient.



33
34
35
# File 'lib/dnn/core/regularizers.rb', line 33

def initialize(l1_lambda = 0.01)
  @l1 = Layers::Lasso.new(l1_lambda)
end

Instance Method Details

#forward(x) ⇒ Object



37
38
39
# File 'lib/dnn/core/regularizers.rb', line 37

def forward(x)
  x + @l1.(@param)
end

#l1_lambdaObject



41
42
43
# File 'lib/dnn/core/regularizers.rb', line 41

def l1_lambda
  @l1.l1_lambda
end

#l1_lambda=(lam) ⇒ Object



45
46
47
# File 'lib/dnn/core/regularizers.rb', line 45

def l1_lambda=(lam)
  @l1.l1_lambda = lam
end

#load_hash(hash) ⇒ Object



53
54
55
# File 'lib/dnn/core/regularizers.rb', line 53

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

#to_hashObject



49
50
51
# File 'lib/dnn/core/regularizers.rb', line 49

def to_hash
  super(l1_lambda: l1_lambda)
end