Class: Neuronet::Connection
- Inherits:
-
Object
- Object
- Neuronet::Connection
- Defined in:
- lib/neuronet/connection.rb
Overview
Connections between neurons are there own separate objects. In Neuronet, a neuron contains it’s bias, and a list of it’s connections. Each connection contains it’s weight (strength) and connected neuron.
Instance Attribute Summary collapse
-
#neuron ⇒ Object
Returns the value of attribute neuron.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#backpropagate(error) ⇒ Object
Connection#backpropagate modifies the connection’s weight in proportion to the error given and passes that error to its connected neuron via the neuron’s backpropagate method.
-
#initialize(neuron = Neuron.new, weight: 0.0) ⇒ Connection
constructor
Connection#initialize takes a neuron and a weight with a default of 0.0.
-
#inspect ⇒ Object
A connection inspects itself as “weight*label:…”.
-
#kappa ⇒ Object
The connection kappa is a component of the neuron’s sum kappa: 𝜿 := 𝑾 𝝀‘.
-
#mju ⇒ Object
The connection’s mju is 𝑾𝓑𝒂‘.
-
#mu ⇒ Object
(also: #activation)
The connection’s mu is the activation of the connected neuron.
-
#to_s ⇒ Object
A connection puts itself as “weight*label”.
-
#update ⇒ Object
Connection#update returns the updated activation of a connection, which is the weighted updated activation of the neuron it’s connected to: weight * neuron.update This method is the one to use whenever the value of the inputs are changed (or right after training).
-
#weighted_activation ⇒ Object
(also: #partial)
The weighted activation of the connected neuron.
Constructor Details
#initialize(neuron = Neuron.new, weight: 0.0) ⇒ Connection
Connection#initialize takes a neuron and a weight with a default of 0.0.
12 13 14 15 |
# File 'lib/neuronet/connection.rb', line 12 def initialize(neuron = Neuron.new, weight: 0.0) @neuron = neuron @weight = weight end |
Instance Attribute Details
#neuron ⇒ Object
Returns the value of attribute neuron.
9 10 11 |
# File 'lib/neuronet/connection.rb', line 9 def neuron @neuron end |
#weight ⇒ Object
Returns the value of attribute weight.
9 10 11 |
# File 'lib/neuronet/connection.rb', line 9 def weight @weight end |
Instance Method Details
#backpropagate(error) ⇒ Object
Connection#backpropagate modifies the connection’s weight in proportion to the error given and passes that error to its connected neuron via the neuron’s backpropagate method.
46 47 48 49 50 51 52 53 |
# File 'lib/neuronet/connection.rb', line 46 def backpropagate(error) @weight += @neuron.activation * Neuronet.noise[error] if @weight.abs > Neuronet.maxw @weight = @weight.positive? ? Neuronet.maxw : -Neuronet.maxw end @neuron.backpropagate(error) self end |
#inspect ⇒ Object
A connection inspects itself as “weight*label:…”.
60 |
# File 'lib/neuronet/connection.rb', line 60 def inspect = "#{Neuronet.format % @weight}*#{@neuron.inspect}" |
#kappa ⇒ Object
The connection kappa is a component of the neuron’s sum kappa:
𝜿 := 𝑾 𝝀'
26 |
# File 'lib/neuronet/connection.rb', line 26 def kappa = @weight * @neuron.lamda |
#mju ⇒ Object
The connection’s mju is 𝑾𝓑𝒂‘.
22 |
# File 'lib/neuronet/connection.rb', line 22 def mju = @weight * @neuron.derivative |
#mu ⇒ Object Also known as: activation
The connection’s mu is the activation of the connected neuron.
18 |
# File 'lib/neuronet/connection.rb', line 18 def mu = @neuron.activation |
#to_s ⇒ Object
A connection puts itself as “weight*label”.
63 |
# File 'lib/neuronet/connection.rb', line 63 def to_s = "#{Neuronet.format % @weight}*#{@neuron}" |
#update ⇒ Object
Connection#update returns the updated activation of a connection, which is the weighted updated activation of the neuron it’s connected to:
weight * neuron.update
This method is the one to use whenever the value of the inputs are changed (or right after training). Otherwise, both update and value should give the same result. When back calculation are not needed, use Connection#weighted_activation instead.
41 |
# File 'lib/neuronet/connection.rb', line 41 def update = @neuron.update * @weight |
#weighted_activation ⇒ Object Also known as: partial
The weighted activation of the connected neuron.
29 |
# File 'lib/neuronet/connection.rb', line 29 def weighted_activation = @neuron.activation * @weight |