Class: DNN::Regularizers::L2
- Inherits:
-
Regularizer
- Object
- Regularizer
- DNN::Regularizers::L2
- Defined in:
- lib/dnn/core/regularizers.rb
Instance Attribute Summary collapse
-
#l2_lambda ⇒ Object
Returns the value of attribute l2_lambda.
Attributes inherited from Regularizer
Class Method Summary collapse
Instance Method Summary collapse
- #backward ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(l2_lambda = 0.01) ⇒ L2
constructor
A new instance of L2.
- #to_hash ⇒ Object
Constructor Details
#initialize(l2_lambda = 0.01) ⇒ L2
Returns a new instance of L2.
56 57 58 |
# File 'lib/dnn/core/regularizers.rb', line 56 def initialize(l2_lambda = 0.01) @l2_lambda = l2_lambda end |
Instance Attribute Details
#l2_lambda ⇒ Object
Returns the value of attribute l2_lambda.
50 51 52 |
# File 'lib/dnn/core/regularizers.rb', line 50 def l2_lambda @l2_lambda end |
Class Method Details
.from_hash(hash) ⇒ Object
52 53 54 |
# File 'lib/dnn/core/regularizers.rb', line 52 def self.from_hash(hash) L2.new(hash[:l2_lambda]) end |
Instance Method Details
#backward ⇒ Object
64 65 66 |
# File 'lib/dnn/core/regularizers.rb', line 64 def backward @param.grad += @l2_lambda * @param.data end |
#forward(x) ⇒ Object
60 61 62 |
# File 'lib/dnn/core/regularizers.rb', line 60 def forward(x) x + 0.5 * @l2_lambda * (@param.data**2).sum end |
#to_hash ⇒ Object
68 69 70 |
# File 'lib/dnn/core/regularizers.rb', line 68 def to_hash super(l2_lambda: @l2_lambda) end |