Class: Neuron
- Inherits:
-
Object
- Object
- Neuron
- Defined in:
- lib/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.
6 7 8 |
# File 'lib/neuron.rb', line 6 def initialize(number_of_inputs) create_weights(number_of_inputs) end |
Instance Attribute Details
#delta ⇒ Object
Returns the value of attribute delta.
4 5 6 |
# File 'lib/neuron.rb', line 4 def delta @delta end |
#last_output ⇒ Object (readonly)
Returns the value of attribute last_output.
3 4 5 |
# File 'lib/neuron.rb', line 3 def last_output @last_output end |
#weights ⇒ Object (readonly)
Returns the value of attribute weights.
3 4 5 |
# File 'lib/neuron.rb', line 3 def weights @weights end |
Instance Method Details
#fire(input) ⇒ Object
10 11 12 |
# File 'lib/neuron.rb', line 10 def fire(input) @last_output = activation_function(input) end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/neuron.rb', line 21 def inspect @weights end |
#update_weight(inputs, training_rate) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/neuron.rb', line 14 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 |