Class: CooCoo::ActivationFunctions::ZeroSafeNormalize
Overview
Like the Normalize but safe when the input is all the same value.
Instance Method Summary
collapse
Methods inherited from Identity
#initial_bias, #initial_weights, method_missing, #name, #prep_input, #to_s
Instance Method Details
316
317
318
319
320
321
322
323
324
325
326
327
|
# 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) ⇒ Object
329
330
331
332
333
334
335
336
337
|
# 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) ⇒ Object
339
340
341
|
# File 'lib/coo-coo/activation_functions.rb', line 339
def prep_output_target(x)
x.normalize
end
|