Class: CooCoo::ActivationFunctions::SoftMax

Inherits:
Identity show all
Defined in:
lib/coo-coo/activation_functions.rb

Overview

Computes the Softmax function given a Vector:

y_i = e ** x_i / sum(e ** x)

Direct Known Subclasses

ShiftedSoftMax

Instance Method Summary collapse

Methods inherited from Identity

#initial_bias, #initial_weights, method_missing, #name, #prep_input, #prep_output_target, #to_s

Instance Method Details

#call(x) ⇒ Object



215
216
217
218
# File 'lib/coo-coo/activation_functions.rb', line 215

def call(x)
  e = x.exp
  e / e.sum
end

#derivative(x, y = nil) ⇒ Object



220
221
222
223
224
# File 'lib/coo-coo/activation_functions.rb', line 220

def derivative(x, y = nil)
  y ||= call(x)
  s = x.exp.sum
  y * (s - x) / s
end