Class: Neuronet::Neuron
- Inherits:
-
Object
- Object
- Neuronet::Neuron
- 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
Instance Attribute Summary collapse
-
#activation ⇒ Object
readonly
activation is read-only.
-
#bias ⇒ Object
bias is settable.
-
#connections ⇒ Object
readonly
activation is read-only.
Instance Method Summary collapse
-
#connect(neuron, weight = 0.0) ⇒ Object
Creates a weighted connection to another neuron.
-
#initialize ⇒ Neuron
constructor
Initializes a neuron with default activation 0.5 and zero bias.
-
#set(value) ⇒ Object
Sets activation by applying squash to raw input value.
-
#update ⇒ Object
Updates activation by squashing the current value(see above).
-
#value ⇒ Object
Computes(raw output)value: bias + sum of incoming connection values.
Methods included from Squash
Methods included from Backpropagate
#backpropagate, #backpropagate!, #reset_backpropagated!, #update_bias, #update_connections
Methods included from NeuronStats
#downstream_params_tally, #mju, #nju
Constructor Details
#initialize ⇒ Neuron
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
#activation ⇒ Object (readonly)
activation is read-only
22 23 24 |
# File 'lib/neuronet/neuron.rb', line 22 def activation @activation end |
#bias ⇒ Object
bias is settable
21 22 23 |
# File 'lib/neuronet/neuron.rb', line 21 def bias @bias end |
#connections ⇒ Object (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 |
#update ⇒ Object
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 |
#value ⇒ Object
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 |