Class: Neuronet::Layer
- Inherits:
-
Array
- Object
- Array
- Neuronet::Layer
- Defined in:
- lib/neuronet.rb
Overview
Just a regular Layer
Instance Method Summary collapse
-
#connect(layer, weight = 0.0) ⇒ Object
Allows one to fully connect layers.
-
#initialize(length) ⇒ Layer
constructor
A new instance of Layer.
-
#partial ⇒ Object
updates layer with current values of the previous layer.
-
#train(targets, learning) ⇒ Object
Takes the real world targets for each node in this layer and backpropagates the error to each node.
-
#values ⇒ Object
Returns the real world values of this layer.
Constructor Details
Instance Method Details
#connect(layer, weight = 0.0) ⇒ Object
Allows one to fully connect layers.
134 135 136 137 |
# File 'lib/neuronet.rb', line 134 def connect(layer, weight=0.0) # creates the neuron matrix... note that node can be either Neuron or Node class. self.each{|neuron| layer.each{|node| neuron.connect(node,weight) }} end |
#partial ⇒ Object
updates layer with current values of the previous layer
140 141 142 |
# File 'lib/neuronet.rb', line 140 def partial self.each{|neuron| neuron.partial} end |
#train(targets, learning) ⇒ Object
Takes the real world targets for each node in this layer and backpropagates the error to each node. Note that the learning constant is really a value that needs to be determined for each network.
148 149 150 151 152 153 |
# File 'lib/neuronet.rb', line 148 def train(targets, learning) 0.upto(self.length-1) do |index| node = self[index] node.backpropagate(learning*(targets[index] - node.value)) end end |
#values ⇒ Object
Returns the real world values of this layer.
156 157 158 |
# File 'lib/neuronet.rb', line 156 def values self.map{|node| node.value} end |