Class: Neuronet::Neuron

Inherits:
Object
  • Object
show all
Includes:
Backpropagate, NeuronStats, Squash
Defined in:
lib/neuronet/neuron.rb

Overview

Neuron represents a single node in a neural network. It holds @activation, @bias, and incoming @connections.

Direct Known Subclasses

NoisyNeuron

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Squash

squash, unsquash

Methods included from Backpropagate

#backpropagate, #backpropagate!, #reset_backpropagated!, #update_bias, #update_connections

Methods included from NeuronStats

#downstream_params_tally, #mju, #nju

Constructor Details

#initializeNeuron

Initializes a neuron with default activation 0.5 and zero bias.



15
16
17
18
19
# File 'lib/neuronet/neuron.rb', line 15

def initialize
  @activation  = 0.5
  @bias        = 0.0
  @connections = [] # incoming connections
end

Instance Attribute Details

#activationObject (readonly)

activation is read-only



22
23
24
# File 'lib/neuronet/neuron.rb', line 22

def activation
  @activation
end

#biasObject

bias is settable



21
22
23
# File 'lib/neuronet/neuron.rb', line 21

def bias
  @bias
end

#connectionsObject (readonly)

activation is read-only



22
23
24
# File 'lib/neuronet/neuron.rb', line 22

def connections
  @connections
end

Instance Method Details

#connect(neuron, weight = 0.0) ⇒ Object

Creates a weighted connection to another neuron. See [Neuronet::Connection](connection.rb)



31
32
33
# File 'lib/neuronet/neuron.rb', line 31

def connect(neuron, weight = 0.0)
  @connections << Connection.new(neuron, weight)
end

#set(value) ⇒ Object

Sets activation by applying squash to raw input value.



25
26
27
# File 'lib/neuronet/neuron.rb', line 25

def set(value)
  @activation = squash(value)
end

#updateObject

Updates activation by squashing the current value(see above).



41
42
43
# File 'lib/neuronet/neuron.rb', line 41

def update
  @activation = squash(value)
end

#valueObject

Computes(raw output)value: bias + sum of incoming connection values.



36
37
38
# File 'lib/neuronet/neuron.rb', line 36

def value
  @bias + @connections.sum(&:value)
end