class CooCoo::ActivationFunctions::ZeroSafeNormalize
Like the {Normalize} but safe when the input is all the same value.
Public Instance Methods
call(x)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 316 def call(x) if x.respond_to?(:normalize) m = x.magnitude if m == 0.0 0.0 else x / magnitude end else x.coerce(0) end end
derivative(x, y = nil)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 329 def derivative(x, y = nil) mag = x.magnitude() if mag == 0.0 0.0 else y ||= call(x) 1.0 / mag - y * y / mag end end
prep_output_target(x)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 339 def prep_output_target(x) x.normalize end