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
#clean, from_hash, #loss, #regularizers_backward, #regularizers_forward
Constructor Details
Returns a new instance of SigmoidCrossEntropy.
174
175
176
|
# File 'lib/dnn/core/losses.rb', line 174
def initialize(eps: 1e-7)
@eps = eps
end
|
Instance Attribute Details
#eps ⇒ Object
Returns the value of attribute eps.
163
164
165
|
# File 'lib/dnn/core/losses.rb', line 163
def eps
@eps
end
|
Class Method Details
.sigmoid(y) ⇒ Object
Also known as:
activation
166
167
168
|
# File 'lib/dnn/core/losses.rb', line 166
def sigmoid(y)
Layers::Sigmoid.new.forward(y)
end
|
Instance Method Details
#backward(y, t) ⇒ Object
183
184
185
|
# File 'lib/dnn/core/losses.rb', line 183
def backward(y, t)
@x - t
end
|
#forward(y, t) ⇒ Object
178
179
180
181
|
# File 'lib/dnn/core/losses.rb', line 178
def forward(y, t)
@x = SigmoidCrossEntropy.sigmoid(y)
-(t * Xumo::NMath.log(@x + @eps) + (1 - t) * Xumo::NMath.log(1 - @x + @eps)).mean(0).sum
end
|
#load_hash(hash) ⇒ Object
191
192
193
|
# File 'lib/dnn/core/losses.rb', line 191
def load_hash(hash)
initialize(eps: hash[:eps])
end
|
#to_hash ⇒ Object
187
188
189
|
# File 'lib/dnn/core/losses.rb', line 187
def to_hash
super(eps: @eps)
end
|