Class: DNN::Regularizers::L2

Inherits:
Regularizer show all
Defined in:
lib/dnn/core/regularizers.rb

Instance Attribute Summary

Attributes inherited from Regularizer

#param

Instance Method Summary collapse

Methods inherited from Regularizer

from_hash

Constructor Details

#initialize(l2_lambda = 0.01) ⇒ L2

Returns a new instance of L2.

Parameters:

  • l2_lambda (Float) (defaults to: 0.01)

    L2 regularizer coefficient.



60
61
62
# File 'lib/dnn/core/regularizers.rb', line 60

def initialize(l2_lambda = 0.01)
  @l2 = Layers::Ridge.new(l2_lambda)
end

Instance Method Details

#forward(x) ⇒ Object



64
65
66
# File 'lib/dnn/core/regularizers.rb', line 64

def forward(x)
  x + @l2.(@param)
end

#l2_lambdaObject



68
69
70
# File 'lib/dnn/core/regularizers.rb', line 68

def l2_lambda
  @l2.l2_lambda
end

#l2_lambda=(lam) ⇒ Object



72
73
74
# File 'lib/dnn/core/regularizers.rb', line 72

def l2_lambda=(lam)
  @l2.l2_lambda = lam
end

#load_hash(hash) ⇒ Object



80
81
82
# File 'lib/dnn/core/regularizers.rb', line 80

def load_hash(hash)
  initialize(hash[:l2_lambda])
end

#to_hashObject



76
77
78
# File 'lib/dnn/core/regularizers.rb', line 76

def to_hash
  super(l2_lambda: l2_lambda)
end