Class: DNN::Activations::SigmoidWithLoss
Instance Method Summary
collapse
#build, #built?, #prev_layer, #shape, #to_hash
Constructor Details
156
157
158
|
# File 'lib/dnn/core/activations.rb', line 156
def initialize
@sigmoid = Sigmoid.new
end
|
Instance Method Details
#backward(y) ⇒ Object
164
165
166
|
# File 'lib/dnn/core/activations.rb', line 164
def backward(y)
@out - y
end
|
#forward(x) ⇒ Object
160
161
162
|
# File 'lib/dnn/core/activations.rb', line 160
def forward(x)
@out = @sigmoid.forward(x)
end
|
#loss(y) ⇒ Object
168
169
170
171
|
# File 'lib/dnn/core/activations.rb', line 168
def loss(y)
batch_size = y.shape[0]
-(y * Xumo::NMath.log(@out + 1e-7) + (1 - y) * Xumo::NMath.log(1 - @out + 1e-7)).sum / batch_size + ridge
end
|