Class: Neuronet::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/neuronet.rb

Overview

A weighted connection to a neuron (or node).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, weight = 0.0) ⇒ Connection

Returns a new instance of Connection.



53
54
55
# File 'lib/neuronet.rb', line 53

def initialize(node, weight=0.0)
  @node, @weight = node, weight
end

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



52
53
54
# File 'lib/neuronet.rb', line 52

def node
  @node
end

#weightObject

Returns the value of attribute weight.



52
53
54
# File 'lib/neuronet.rb', line 52

def weight
  @weight
end

Instance Method Details

#backpropagate(error) ⇒ Object

Adjusts the connection weight according to error and backpropagates the error to the connected node.



70
71
72
73
# File 'lib/neuronet.rb', line 70

def backpropagate(error)
  @weight += @node.activation * error * Neuronet.noise
  @node.backpropagate(error)
end

#updateObject

Updates and returns the value of the connection. Updates the connected node.



64
65
66
# File 'lib/neuronet.rb', line 64

def update
  @node.update * @weight
end

#valueObject

The value of a connection is the weighted activation of the connected node.



58
59
60
# File 'lib/neuronet.rb', line 58

def value
  @node.activation * @weight
end