Class: DNN::Activations::SoftmaxWithLoss
Instance Method Summary
collapse
#build, #built?, #initialize, #prev_layer, #shape, #to_hash
Instance Method Details
#backward(y) ⇒ Object
150
151
152
|
# File 'lib/dnn/core/activations.rb', line 150
def backward(y)
@out - y
end
|
#forward(x) ⇒ Object
146
147
148
|
# File 'lib/dnn/core/activations.rb', line 146
def forward(x)
@out = NMath.exp(x) / NMath.exp(x).sum(1).reshape(x.shape[0], 1)
end
|
#loss(y) ⇒ Object
154
155
156
157
|
# File 'lib/dnn/core/activations.rb', line 154
def loss(y)
batch_size = y.shape[0]
-(y * NMath.log(@out + 1e-7)).sum / batch_size + ridge
end
|