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
- #set_activation_function(activation_function) ⇒ Object
Constructor Details
#initialize(number_of_inputs, number_of_outputs, activation_function) ⇒ Layer
Returns a new instance of Layer.
63 64 65 66 |
# File 'lib/nn.rb', line 63 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.
68 69 70 |
# File 'lib/nn.rb', line 68 def activation_function @activation_function end |
#neurons ⇒ Object (readonly)
Returns the value of attribute neurons.
68 69 70 |
# File 'lib/nn.rb', line 68 def neurons @neurons end |
Instance Method Details
#calc(inputs) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/nn.rb', line 85 def calc(inputs) outs = [] self.neurons.each do |neuron| outs << neuron.calc(inputs) end outs end |
#parameters ⇒ Object
70 71 72 73 74 |
# File 'lib/nn.rb', line 70 def parameters params = [] self.neurons.each { |n| params += n.parameters } params end |
#reset_params ⇒ Object
76 77 78 |
# File 'lib/nn.rb', line 76 def reset_params self.neurons.each { |n| n.reset_params } end |
#set_activation_function(activation_function) ⇒ Object
80 81 82 83 |
# File 'lib/nn.rb', line 80 def set_activation_function(activation_function) @activation_function = activation_function self.neurons.each { |n| n.set_activation_function(activation_function) } end |