Class: DNN::Activations::SigmoidWithLoss
Instance Method Summary
collapse
#build, #built?, #prev_layer, #shape, #to_hash
Constructor Details
Returns a new instance of SigmoidWithLoss.
131
132
133
|
# File 'lib/dnn/core/activations.rb', line 131
def initialize
@sigmoid = Sigmoid.new
end
|
Instance Method Details
#backward(y) ⇒ Object
139
140
141
|
# File 'lib/dnn/core/activations.rb', line 139
def backward(y)
@out - y
end
|
#forward(x) ⇒ Object
135
136
137
|
# File 'lib/dnn/core/activations.rb', line 135
def forward(x)
@out = @sigmoid.forward(x)
end
|
#loss(y) ⇒ Object
143
144
145
146
|
# File 'lib/dnn/core/activations.rb', line 143
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 + ridge
end
|