Class: Neuronet::Connection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#neuronObject

Returns the value of attribute neuron.



9
10
11
# File 'lib/neuronet/connection.rb', line 9

def neuron
  @neuron
end

#weightObject

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

#inspectObject

A connection inspects itself as “weight*label:…”.



60
# File 'lib/neuronet/connection.rb', line 60

def inspect = "#{Neuronet.format % @weight}*#{@neuron.inspect}"

#kappaObject

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

#mjuObject

The connection’s mju is 𝑾𝓑𝒂‘.



22
# File 'lib/neuronet/connection.rb', line 22

def mju = @weight * @neuron.derivative

#muObject 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_sObject

A connection puts itself as “weight*label”.



63
# File 'lib/neuronet/connection.rb', line 63

def to_s = "#{Neuronet.format % @weight}*#{@neuron}"

#updateObject

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_activationObject 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