Class: DNN::Regularizers::L1
- Inherits:
-
Regularizer
- Object
- Regularizer
- DNN::Regularizers::L1
- Defined in:
- lib/dnn/core/regularizers.rb
Instance Attribute Summary collapse
-
#l1_lambda ⇒ Object
Returns the value of attribute l1_lambda.
Attributes inherited from Regularizer
Instance Method Summary collapse
- #backward ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(l1_lambda = 0.01) ⇒ L1
constructor
A new instance of L1.
- #load_hash(hash) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Regularizer
Constructor Details
#initialize(l1_lambda = 0.01) ⇒ L1
Returns a new instance of L1.
39 40 41 |
# File 'lib/dnn/core/regularizers.rb', line 39 def initialize(l1_lambda = 0.01) @l1_lambda = l1_lambda end |
Instance Attribute Details
#l1_lambda ⇒ Object
Returns the value of attribute l1_lambda.
36 37 38 |
# File 'lib/dnn/core/regularizers.rb', line 36 def l1_lambda @l1_lambda end |
Instance Method Details
#backward ⇒ Object
47 48 49 50 51 |
# File 'lib/dnn/core/regularizers.rb', line 47 def backward dparam = Xumo::SFloat.ones(*@param.data.shape) dparam[@param.data < 0] = -1 @param.grad += @l1_lambda * dparam end |
#forward(x) ⇒ Object
43 44 45 |
# File 'lib/dnn/core/regularizers.rb', line 43 def forward(x) x + @l1_lambda * @param.data.abs.sum end |
#load_hash(hash) ⇒ Object
57 58 59 |
# File 'lib/dnn/core/regularizers.rb', line 57 def load_hash(hash) initialize(hash[:l1_lambda]) end |
#to_hash ⇒ Object
53 54 55 |
# File 'lib/dnn/core/regularizers.rb', line 53 def to_hash super(l1_lambda: @l1_lambda) end |