Class: DNN::Losses::SigmoidCrossEntropy
- Inherits:
-
Loss
- Object
- Loss
- DNN::Losses::SigmoidCrossEntropy
show all
- Defined in:
- lib/dnn/core/losses.rb
Instance Attribute Summary collapse
Class Method 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.
171
172
173
|
# File 'lib/dnn/core/losses.rb', line 171
def initialize(eps: 1e-7)
@eps = eps
end
|
Instance Attribute Details
#eps ⇒ Object
Returns the value of attribute eps.
160
161
162
|
# File 'lib/dnn/core/losses.rb', line 160
def eps
@eps
end
|
Class Method Details
.sigmoid(y) ⇒ Object
Also known as:
activation
163
164
165
|
# File 'lib/dnn/core/losses.rb', line 163
def sigmoid(y)
Layers::Sigmoid.new.forward(y)
end
|
Instance Method Details
#backward(y, t) ⇒ Object
180
181
182
|
# File 'lib/dnn/core/losses.rb', line 180
def backward(y, t)
@x - t
end
|
#forward(y, t) ⇒ Object
175
176
177
178
|
# File 'lib/dnn/core/losses.rb', line 175
def forward(y, t)
@x = SigmoidCrossEntropy.sigmoid(y)
-(t * Xumo::NMath.log(@x) + (1 - t) * Xumo::NMath.log(1 - @x))
end
|
#load_hash(hash) ⇒ Object
188
189
190
|
# File 'lib/dnn/core/losses.rb', line 188
def load_hash(hash)
initialize(eps: hash[:eps])
end
|
#to_hash ⇒ Object
184
185
186
|
# File 'lib/dnn/core/losses.rb', line 184
def to_hash
super(eps: @eps)
end
|