Class: NeuralNetworkRb::Loss::SoftmaxCrossEntropy

Inherits:
Object
  • Object
show all
Defined in:
lib/neural_network_rb/loss/softmax_cross_entropy.rb

Instance Method Summary collapse

Constructor Details

#initialize(next_layer, options = {}) ⇒ SoftmaxCrossEntropy

Returns a new instance of SoftmaxCrossEntropy.



5
6
7
# File 'lib/neural_network_rb/loss/softmax_cross_entropy.rb', line 5

def initialize(next_layer, options = {})
  @next_layer = next_layer
end

Instance Method Details

#call(input, target) ⇒ Object



18
19
20
21
# File 'lib/neural_network_rb/loss/softmax_cross_entropy.rb', line 18

def call(input, target)
  error = cross_entropy(softmax(input), target)
  grad(input, target) if target
end

#predict(input) ⇒ Object



14
15
16
# File 'lib/neural_network_rb/loss/softmax_cross_entropy.rb', line 14

def predict(input)
  @next_layer.predict(softmax(input))  
end

#train(input, target) ⇒ Object



9
10
11
12
# File 'lib/neural_network_rb/loss/softmax_cross_entropy.rb', line 9

def train(input, target)
  output = softmax(input)
  grad(output, target) * @next_layer.train(output, target)
end