Class: CooCoo::ActivationFunctions::Identity
- 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.
Direct Known Subclasses
LeakyReLU, Logistic, MinMax, Normalize, ReLU, SoftMax, TanH, ZeroSafeMinMax, ZeroSafeNormalize
Class Method Summary collapse
-
.method_missing(mid, *args, &block) ⇒ Object
Forwards missing class methods to the #instance.
Instance Method Summary collapse
-
#call(x) ⇒ Numeric, Vector
Perform the activation.
-
#derivative(x, y = nil) ⇒ Object
Calculate the derivative at
x
. -
#initial_bias(size) ⇒ Vector
Initial bias for a Layer.
-
#initial_weights(num_inputs, size) ⇒ Vector
Initial weights a Layer should use when using this function.
-
#name ⇒ Object
A file friendly name for the activation function.
-
#prep_input(x) ⇒ Vector
Adjusts a Network‘s inputs to the domain of the function.
-
#prep_output_target(x) ⇒ Vector
Adjusts a training set’s target domain from
0..1
to domain of the function’s output. - #to_s ⇒ Object
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.
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
.
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.
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.
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 |
#name ⇒ Object
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.
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.
85 86 87 |
# File 'lib/coo-coo/activation_functions.rb', line 85 def prep_output_target(x) x end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/coo-coo/activation_functions.rb', line 36 def to_s name end |