class CooCoo::ActivationFunctions::Identity
The base for all the ActivationFunctions
. Implements a do nothing activation function for a {Layer}.
Public Class Methods
Forwards missing class methods to the instance.
# File lib/coo-coo/activation_functions.rb, line 27 def self.method_missing(mid, *args, &block) instance.send(mid, *args, &block) end
Public Instance Methods
Perform the activation. @param x [Numeric, Vector] @return [Numeric, Vector]
# File lib/coo-coo/activation_functions.rb, line 43 def call(x) x end
Calculate the derivative at x
. @param x [Numeric, Vector] @param y [Numeric, Vector, nil] Optional precomputed return value from call
.
# File lib/coo-coo/activation_functions.rb, line 50 def derivative(x, y = nil) if (y || x).kind_of?(Numeric) 1.0 else (y || x).class.ones((y || x).size) end end
Initial bias for a {Layer}. @param size [Integer] Number of bias elements to return. @return [Vector]
# File lib/coo-coo/activation_functions.rb, line 70 def initial_bias(size) CooCoo::Vector.ones(size) end
Initial weights a {Layer} should use when using this function. @param num_inputs [Integer] Number of inputs into the {Layer} @param size [Integer] The size or number of outputs of the {Layer}. @return [Vector] of weights that are randomly distributed between -1.0 and 1.0.
# File lib/coo-coo/activation_functions.rb, line 63 def initial_weights(num_inputs, size) (CooCoo::Vector.rand(num_inputs * size) * 2.0 - 1.0) / num_inputs.to_f.sqrt end
A file friendly name for the activation function.
# File lib/coo-coo/activation_functions.rb, line 32 def name self.class.name.split("::").last end
Adjusts a {Network}'s inputs to the domain of the function. @param x [Vector] @return [Vector]
# File lib/coo-coo/activation_functions.rb, line 77 def prep_input(x) x end
Adjusts a training set's target domain from 0..1
to domain of the function's output. @param x [Vector] @return [Vector]
# File lib/coo-coo/activation_functions.rb, line 85 def prep_output_target(x) x end
# File lib/coo-coo/activation_functions.rb, line 36 def to_s name end