Class: CooCoo::ActivationFunctions::Identity

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/coo-coo/activation_functions.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(mid, *args, &block) ⇒ Object

Forwards missing class methods to the #instance.



27
28
29
# File 'lib/coo-coo/activation_functions.rb', line 27

def self.method_missing(mid, *args, &block)
  instance.send(mid, *args, &block)
end

Instance Method Details

#call(x) ⇒ Numeric, Vector

Perform the activation.

Parameters:

Returns:



43
44
45
# File 'lib/coo-coo/activation_functions.rb', line 43

def call(x)
  x
end

#derivative(x, y = nil) ⇒ Object

Calculate the derivative at x.

Parameters:



50
51
52
53
54
55
56
# 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) ⇒ Vector

Initial bias for a Layer.

Parameters:

  • size (Integer)

    Number of bias elements to return.

Returns:



70
71
72
# File 'lib/coo-coo/activation_functions.rb', line 70

def initial_bias(size)
  CooCoo::Vector.ones(size)
end

#initial_weights(num_inputs, size) ⇒ Vector

Initial weights a Layer should use when using this function. between -1.0 and 1.0.

Parameters:

  • num_inputs (Integer)

    Number of inputs into the Layer

  • size (Integer)

    The size or number of outputs of the Layer.

Returns:

  • (Vector)

    of weights that are randomly distributed



63
64
65
# 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

#nameObject

A file friendly name for the activation function.



32
33
34
# File 'lib/coo-coo/activation_functions.rb', line 32

def name
  self.class.name.split("::").last
end

#prep_input(x) ⇒ Vector

Adjusts a Network‘s inputs to the domain of the function.

Parameters:

Returns:



77
78
79
# File 'lib/coo-coo/activation_functions.rb', line 77

def prep_input(x)
  x
end

#prep_output_target(x) ⇒ Vector

Adjusts a training set’s target domain from 0..1 to domain of the function’s output.

Parameters:

Returns:



85
86
87
# File 'lib/coo-coo/activation_functions.rb', line 85

def prep_output_target(x)
  x
end

#to_sObject



36
37
38
# File 'lib/coo-coo/activation_functions.rb', line 36

def to_s
  name
end