Class: CooCoo::LinearLayer
Instance Attribute Summary collapse
-
#activation_function ⇒ Object
Returns the value of attribute activation_function.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #adjust_weights!(deltas) ⇒ Object
- #backprop(input, output, errors, hidden_state) ⇒ Object
- #forward(input, hidden_state) ⇒ Object
-
#initialize(size, activation_function = CooCoo::ActivationFunctions::Identity.instance) ⇒ LinearLayer
constructor
A new instance of LinearLayer.
- #num_inputs ⇒ Object
- #to_hash(network = nil) ⇒ Object
- #transfer_error(deltas) ⇒ Object
- #weight_deltas(inputs, deltas) ⇒ Object
Constructor Details
#initialize(size, activation_function = CooCoo::ActivationFunctions::Identity.instance) ⇒ LinearLayer
Returns a new instance of LinearLayer.
12 13 14 15 |
# File 'lib/coo-coo/linear_layer.rb', line 12 def initialize(size, activation_function = CooCoo::ActivationFunctions::Identity.instance) @size = size @activation_function = activation_function end |
Instance Attribute Details
#activation_function ⇒ Object
Returns the value of attribute activation_function.
9 10 11 |
# File 'lib/coo-coo/linear_layer.rb', line 9 def activation_function @activation_function end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
10 11 12 |
# File 'lib/coo-coo/linear_layer.rb', line 10 def size @size end |
Class Method Details
.from_hash(h, network = nil) ⇒ Object
55 56 57 |
# File 'lib/coo-coo/linear_layer.rb', line 55 def self.from_hash(h, network = nil) new(h[:size], ActivationFunctions.from_name(h[:f])) end |
Instance Method Details
#==(other) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/coo-coo/linear_layer.rb', line 41 def ==(other) other.kind_of?(self.class) && num_inputs == other.num_inputs && size == other.size && activation_function == other.activation_function end |
#adjust_weights!(deltas) ⇒ Object
33 34 35 |
# File 'lib/coo-coo/linear_layer.rb', line 33 def adjust_weights!(deltas) self end |
#backprop(input, output, errors, hidden_state) ⇒ Object
25 26 27 |
# File 'lib/coo-coo/linear_layer.rb', line 25 def backprop(input, output, errors, hidden_state) [ errors * @activation_function.derivative(input, output), hidden_state ] end |
#forward(input, hidden_state) ⇒ Object
21 22 23 |
# File 'lib/coo-coo/linear_layer.rb', line 21 def forward(input, hidden_state) [ @activation_function.call(input), hidden_state ] end |
#num_inputs ⇒ Object
17 18 19 |
# File 'lib/coo-coo/linear_layer.rb', line 17 def num_inputs size end |
#to_hash(network = nil) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/coo-coo/linear_layer.rb', line 48 def to_hash(network = nil) { type: self.class.name, size: size, f: @activation_function.name } end |
#transfer_error(deltas) ⇒ Object
29 30 31 |
# File 'lib/coo-coo/linear_layer.rb', line 29 def transfer_error(deltas) deltas end |
#weight_deltas(inputs, deltas) ⇒ Object
37 38 39 |
# File 'lib/coo-coo/linear_layer.rb', line 37 def weight_deltas(inputs, deltas) deltas end |