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