Class: Neuronet::Neuron
Overview
A Neuron with bias and connections
Instance Attribute Summary collapse
-
#bias ⇒ Object
Returns the value of attribute bias.
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
Attributes inherited from Node
Instance Method Summary collapse
-
#backpropagate(error) ⇒ Object
Adjusts bias according to error and backpropagates the error to the connections.
-
#connect(node, weight = 0.0) ⇒ Object
Connects the neuron to another node.
-
#initialize(bias = 0.0) ⇒ Neuron
constructor
A new instance of Neuron.
-
#partial ⇒ Object
Updates the activation with the current values of bias and connections For when connections are already updated.
-
#update ⇒ Object
Updates the activation with the current value of bias and updated values of connections.
Methods inherited from Node
Constructor Details
#initialize(bias = 0.0) ⇒ Neuron
Returns a new instance of Neuron.
80 81 82 83 84 |
# File 'lib/neuronet.rb', line 80 def initialize(bias=0.0) super(bias) @connections = [] @bias = bias end |
Instance Attribute Details
#bias ⇒ Object
Returns the value of attribute bias.
79 80 81 |
# File 'lib/neuronet.rb', line 79 def bias @bias end |
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
78 79 80 |
# File 'lib/neuronet.rb', line 78 def connections @connections end |
Instance Method Details
#backpropagate(error) ⇒ Object
Adjusts bias according to error and backpropagates the error to the connections.
99 100 101 102 |
# File 'lib/neuronet.rb', line 99 def backpropagate(error) @bias += error * Neuronet.noise @connections.each{|connection| connection.backpropagate(error)} end |
#connect(node, weight = 0.0) ⇒ Object
Connects the neuron to another node. Updates the activation with the new connection. The default weight=0 means there is no initial association
107 108 109 110 |
# File 'lib/neuronet.rb', line 107 def connect(node, weight=0.0) @connections.push(Connection.new(node,weight)) update end |
#partial ⇒ Object
Updates the activation with the current values of bias and connections For when connections are already updated.
93 94 95 |
# File 'lib/neuronet.rb', line 93 def partial self.value = @bias + @connections.inject(0.0){|sum,connection| sum + connection.value} end |
#update ⇒ Object
Updates the activation with the current value of bias and updated values of connections.
87 88 89 |
# File 'lib/neuronet.rb', line 87 def update self.value = @bias + @connections.inject(0.0){|sum,connection| sum + connection.update} end |