Class: DNN::Activations::SigmoidWithLoss
- Inherits:
-
OutputLayer
- Object
- DNN::Activations::SigmoidWithLoss
- Includes:
- Numo
- Defined in:
- lib/dnn/core/activations.rb
Instance Method Summary collapse
- #backward(y) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize ⇒ SigmoidWithLoss
constructor
A new instance of SigmoidWithLoss.
- #loss(y) ⇒ Object
Constructor Details
#initialize ⇒ SigmoidWithLoss
Returns a new instance of SigmoidWithLoss.
113 114 115 |
# File 'lib/dnn/core/activations.rb', line 113 def initialize @sigmoid = Sigmoid.new end |
Instance Method Details
#backward(y) ⇒ Object
121 122 123 |
# File 'lib/dnn/core/activations.rb', line 121 def backward(y) @out - y end |
#forward(x) ⇒ Object
117 118 119 |
# File 'lib/dnn/core/activations.rb', line 117 def forward(x) @out = @sigmoid.forward(x) end |
#loss(y) ⇒ Object
125 126 127 128 |
# File 'lib/dnn/core/activations.rb', line 125 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 |