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
66 67 68 |
# File 'lib/dnn/core/regularizers.rb', line 66 def initialize(l2_lambda = 0.01) @l2_lambda = l2_lambda end |
Instance Attribute Details
#l2_lambda ⇒ Object
Returns the value of attribute l2_lambda.
63 64 65 |
# File 'lib/dnn/core/regularizers.rb', line 63 def l2_lambda @l2_lambda end |
Instance Method Details
#backward ⇒ Object
74 75 76 |
# File 'lib/dnn/core/regularizers.rb', line 74 def backward @param.grad += @l2_lambda * @param.data end |
#forward(x) ⇒ Object
70 71 72 |
# File 'lib/dnn/core/regularizers.rb', line 70 def forward(x) x + 0.5 * @l2_lambda * (@param.data**2).sum end |
#load_hash(hash) ⇒ Object
82 83 84 |
# File 'lib/dnn/core/regularizers.rb', line 82 def load_hash(hash) initialize(hash[:l2_lambda]) end |
#to_hash ⇒ Object
78 79 80 |
# File 'lib/dnn/core/regularizers.rb', line 78 def to_hash super(l2_lambda: @l2_lambda) end |