Class: DNN::Activations::SoftmaxWithLoss

Inherits:
OutputLayer
  • Object
show all
Defined in:
lib/dnn/core/activations.rb

Instance Method Summary collapse

Instance Method Details

#backward(y) ⇒ Object



92
93
94
# File 'lib/dnn/core/activations.rb', line 92

def backward(y)
  @out - y
end

#forward(x) ⇒ Object



88
89
90
# File 'lib/dnn/core/activations.rb', line 88

def forward(x)
  @out = NMath.exp(x) / NMath.exp(x).sum(1).reshape(x.shape[0], 1)
end

#loss(y) ⇒ Object



96
97
98
# File 'lib/dnn/core/activations.rb', line 96

def loss(y)
  -(y * NMath.log(@out + 1e-7)).sum / @model.batch_size + ridge
end