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.
58 59 60 |
# File 'lib/dnn/core/regularizers.rb', line 58 def initialize(l2_lambda = 0.01) @l2_lambda = l2_lambda end |
Instance Attribute Details
#l2_lambda ⇒ Object
Returns the value of attribute l2_lambda.
51 52 53 |
# File 'lib/dnn/core/regularizers.rb', line 51 def l2_lambda @l2_lambda end |
Class Method Details
.from_hash(hash) ⇒ Object
53 54 55 |
# File 'lib/dnn/core/regularizers.rb', line 53 def self.from_hash(hash) self.new(hash[:l2_lambda]) end |
Instance Method Details
#backward ⇒ Object
66 67 68 |
# File 'lib/dnn/core/regularizers.rb', line 66 def backward @param.grad += @l2_lambda * @param.data end |
#forward(x) ⇒ Object
62 63 64 |
# File 'lib/dnn/core/regularizers.rb', line 62 def forward(x) x + 0.5 * @l2_lambda * (@param.data ** 2).sum end |
#to_hash ⇒ Object
70 71 72 |
# File 'lib/dnn/core/regularizers.rb', line 70 def to_hash super(l2_lambda: @l2_lambda) end |