Class: DNN::Activations::SoftmaxWithLoss
Instance Method Summary
collapse
#build, #built?, #initialize, #prev_layer, #shape, #to_hash
Instance Method Details
#backward(y) ⇒ Object
217
218
219
|
# File 'lib/dnn/core/activations.rb', line 217
def backward(y)
@out - y
end
|
#forward(x) ⇒ Object
213
214
215
|
# File 'lib/dnn/core/activations.rb', line 213
def forward(x)
@out = Xumo::NMath.exp(x) / Xumo::NMath.exp(x).sum(1).reshape(x.shape[0], 1)
end
|
#loss(y) ⇒ Object
221
222
223
224
|
# File 'lib/dnn/core/activations.rb', line 221
def loss(y)
batch_size = y.shape[0]
-(y * Xumo::NMath.log(@out + 1e-7)).sum / batch_size + ridge
end
|