Class: Layer
- Inherits:
-
Object
- Object
- Layer
- Defined in:
- lib/nn.rb
Instance Attribute Summary collapse
-
#activation_function ⇒ Object
readonly
Returns the value of attribute activation_function.
-
#neurons ⇒ Object
readonly
Returns the value of attribute neurons.
Instance Method Summary collapse
- #calc(inputs) ⇒ Object
-
#initialize(number_of_inputs, number_of_outputs, activation_function) ⇒ Layer
constructor
A new instance of Layer.
- #parameters ⇒ Object
- #reset_params ⇒ Object
Constructor Details
#initialize(number_of_inputs, number_of_outputs, activation_function) ⇒ Layer
57 58 59 60 |
# File 'lib/nn.rb', line 57 def initialize(number_of_inputs, number_of_outputs, activation_function) @neurons = Array.new(number_of_outputs) { Neuron.new(number_of_inputs, activation_function) } @activation_function = activation_function end |
Instance Attribute Details
#activation_function ⇒ Object (readonly)
Returns the value of attribute activation_function.
62 63 64 |
# File 'lib/nn.rb', line 62 def activation_function @activation_function end |
#neurons ⇒ Object (readonly)
Returns the value of attribute neurons.
62 63 64 |
# File 'lib/nn.rb', line 62 def neurons @neurons end |
Instance Method Details
#calc(inputs) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/nn.rb', line 74 def calc(inputs) outs = [] self.neurons.each do |neuron| outs << neuron.calc(inputs) end outs end |
#parameters ⇒ Object
64 65 66 67 68 |
# File 'lib/nn.rb', line 64 def parameters params = [] self.neurons.each { |n| params += n.parameters } params end |
#reset_params ⇒ Object
70 71 72 |
# File 'lib/nn.rb', line 70 def reset_params self.neurons.each { |n| n.reset_params } end |