Class: DNN::Activations::SoftmaxWithLoss
- Inherits:
-
OutputLayer
- Object
- DNN::Activations::SoftmaxWithLoss
- Defined in:
- lib/dnn/core/activations.rb
Instance Method Summary collapse
Instance Method Details
#backward(y) ⇒ Object
118 119 120 |
# File 'lib/dnn/core/activations.rb', line 118 def backward(y) @out - y end |
#forward(x) ⇒ Object
114 115 116 |
# File 'lib/dnn/core/activations.rb', line 114 def forward(x) @out = NMath.exp(x) / NMath.exp(x).sum(1).reshape(x.shape[0], 1) end |
#loss(y) ⇒ Object
122 123 124 125 |
# File 'lib/dnn/core/activations.rb', line 122 def loss(y) batch_size = y.shape[0] -(y * NMath.log(@out + 1e-7)).sum / batch_size + ridge end |