Class: CooCoo::ActivationFunctions::ZeroSafeMinMax

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

Overview

Like the MinMax 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

#call(x) ⇒ Object



267
268
269
270
271
272
273
# File 'lib/coo-coo/activation_functions.rb', line 267

def call(x)
  if x.respond_to?(:minmax_normalize)
    x.minmax_normalize(true)
  else
    x
  end
end

#derivative(x, y = nil) ⇒ Object



275
276
277
278
279
280
281
282
283
# File 'lib/coo-coo/activation_functions.rb', line 275

def derivative(x, y = nil)
  min, max = x.minmax
  delta = max - min
  if delta == 0.0
    x.zero
  else
    (y || x).class.new((y || x).size, 1.0 / (max - min))
  end
end

#prep_output_target(x) ⇒ Object



285
286
287
# File 'lib/coo-coo/activation_functions.rb', line 285

def prep_output_target(x)
  call(x)
end