Class: Neuron
- Inherits:
-
Object
- Object
- Neuron
- Defined in:
- lib/db_mlp/neuron.rb
Instance Attribute Summary collapse
-
#delta ⇒ Object
Returns the value of attribute delta.
-
#last_output ⇒ Object
readonly
Returns the value of attribute last_output.
-
#layer_index ⇒ Object
readonly
Returns the value of attribute layer_index.
Instance Method Summary collapse
- #fire(input) ⇒ Object
-
#initialize(number_of_inputs, layer_index) ⇒ Neuron
constructor
A new instance of Neuron.
- #inspect ⇒ Object
- #update_weight(inputs, training_rate) ⇒ Object
- #weights ⇒ Object
Constructor Details
#initialize(number_of_inputs, layer_index) ⇒ Neuron
Returns a new instance of Neuron.
7 8 9 10 |
# File 'lib/db_mlp/neuron.rb', line 7 def initialize(number_of_inputs, layer_index) create_weights(number_of_inputs) @layer_index = layer_index end |
Instance Attribute Details
#delta ⇒ Object
Returns the value of attribute delta.
3 4 5 |
# File 'lib/db_mlp/neuron.rb', line 3 def delta @delta end |
#last_output ⇒ Object (readonly)
Returns the value of attribute last_output.
5 6 7 |
# File 'lib/db_mlp/neuron.rb', line 5 def last_output @last_output end |
#layer_index ⇒ Object (readonly)
Returns the value of attribute layer_index.
5 6 7 |
# File 'lib/db_mlp/neuron.rb', line 5 def layer_index @layer_index end |
Instance Method Details
#fire(input) ⇒ Object
12 13 14 |
# File 'lib/db_mlp/neuron.rb', line 12 def fire(input) @last_output = activation_function(input) end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/db_mlp/neuron.rb', line 24 def inspect weights end |
#update_weight(inputs, training_rate) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/db_mlp/neuron.rb', line 16 def update_weight(inputs, training_rate) inputs << -1 # Add the bias node weights.each_index do |i| weights[i] += training_rate * delta * inputs[i] end end |
#weights ⇒ Object
28 29 30 |
# File 'lib/db_mlp/neuron.rb', line 28 def weights @weights ||= [] end |