Class: DNN::Losses::SigmoidCrossEntropy
- Inherits:
-
Loss
- Object
- Loss
- DNN::Losses::SigmoidCrossEntropy
show all
- Defined in:
- lib/dnn/core/losses.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Loss
from_hash, #loss, #regularizers_backward, #regularizers_forward
Constructor Details
Returns a new instance of SigmoidCrossEntropy.
164
165
166
|
# File 'lib/dnn/core/losses.rb', line 164
def initialize(eps: 1e-7)
@eps = eps
end
|
Instance Attribute Details
#eps ⇒ Object
Returns the value of attribute eps.
161
162
163
|
# File 'lib/dnn/core/losses.rb', line 161
def eps
@eps
end
|
Instance Method Details
#backward(y, t) ⇒ Object
173
174
175
|
# File 'lib/dnn/core/losses.rb', line 173
def backward(y, t)
@x - t
end
|
#forward(y, t) ⇒ Object
168
169
170
171
|
# File 'lib/dnn/core/losses.rb', line 168
def forward(y, t)
@x = Activations::Sigmoid.new.forward(y)
-(t * Xumo::NMath.log(@x) + (1 - t) * Xumo::NMath.log(1 - @x))
end
|
#load_hash(hash) ⇒ Object
181
182
183
|
# File 'lib/dnn/core/losses.rb', line 181
def load_hash(hash)
initialize(eps: hash[:eps])
end
|
#to_hash ⇒ Object
177
178
179
|
# File 'lib/dnn/core/losses.rb', line 177
def to_hash
super(eps: @eps)
end
|