class CooCoo::ActivationFunctions::Identity

The base for all the ActivationFunctions. Implements a do nothing activation function for a {Layer}.

Public Class Methods

method_missing(mid, *args, &block) click to toggle source

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

call(x) click to toggle source

Perform the activation. @param x [Numeric, Vector] @return [Numeric, Vector]

# File lib/coo-coo/activation_functions.rb, line 43
def call(x)
  x
end
derivative(x, y = nil) click to toggle source

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(size) click to toggle source

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(num_inputs, size) click to toggle source

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
name() click to toggle source

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
prep_input(x) click to toggle source

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
prep_output_target(x) click to toggle source

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
to_s() click to toggle source
# File lib/coo-coo/activation_functions.rb, line 36
def to_s
  name
end