Class: Neuronet::Neuron

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

Overview

A Neuron with bias and connections

Instance Attribute Summary collapse

Attributes inherited from Node

#activation

Instance Method Summary collapse

Methods inherited from Node

#value, #value=

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

#biasObject

Returns the value of attribute bias.



79
80
81
# File 'lib/neuronet.rb', line 79

def bias
  @bias
end

#connectionsObject (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

#partialObject

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

#updateObject

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