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
Instance Method Summary collapse
- #backward ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(l2_lambda = 0.01) ⇒ L2
constructor
A new instance of L2.
- #load_hash(hash) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Regularizer
Constructor Details
#initialize(l2_lambda = 0.01) ⇒ L2
Returns a new instance of L2.
67 68 69 |
# File 'lib/dnn/core/regularizers.rb', line 67 def initialize(l2_lambda = 0.01) @l2_lambda = l2_lambda end |
Instance Attribute Details
#l2_lambda ⇒ Object
Returns the value of attribute l2_lambda.
64 65 66 |
# File 'lib/dnn/core/regularizers.rb', line 64 def l2_lambda @l2_lambda end |
Instance Method Details
#backward ⇒ Object
75 76 77 |
# File 'lib/dnn/core/regularizers.rb', line 75 def backward @param.grad += @l2_lambda * @param.data end |
#forward(x) ⇒ Object
71 72 73 |
# File 'lib/dnn/core/regularizers.rb', line 71 def forward(x) x + 0.5 * @l2_lambda * (@param.data ** 2).sum end |
#load_hash(hash) ⇒ Object
83 84 85 |
# File 'lib/dnn/core/regularizers.rb', line 83 def load_hash(hash) initialize(hash[:l2_lambda]) end |
#to_hash ⇒ Object
79 80 81 |
# File 'lib/dnn/core/regularizers.rb', line 79 def to_hash super(l2_lambda: @l2_lambda) end |