Class: DNN::Activations::SigmoidWithLoss
Constant Summary
collapse
- NMath =
Xumo::NMath
Instance Method Summary
collapse
#build, #built?, #prev_layer, #shape, #to_hash
Constructor Details
Returns a new instance of SigmoidWithLoss.
244
245
246
|
# File 'lib/dnn/core/activations.rb', line 244
def initialize
@sigmoid = Sigmoid.new
end
|
Instance Method Details
#backward(y) ⇒ Object
252
253
254
|
# File 'lib/dnn/core/activations.rb', line 252
def backward(y)
@out - y
end
|
#forward(x) ⇒ Object
248
249
250
|
# File 'lib/dnn/core/activations.rb', line 248
def forward(x)
@out = @sigmoid.forward(x)
end
|
#loss(y) ⇒ Object
256
257
258
259
|
# File 'lib/dnn/core/activations.rb', line 256
def loss(y)
batch_size = y.shape[0]
-(y * NMath.log(@out + 1e-7) + (1 - y) * NMath.log(1 - @out + 1e-7)).sum / batch_size + lasso + ridge
end
|