Class: Neuronet::Layer

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

Overview

Just a regular Layer

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ Layer

Returns a new instance of Layer.



128
129
130
131
# File 'lib/neuronet.rb', line 128

def initialize(length)
  super(length)
  0.upto(length-1){|index| self[index] = Neuronet::Neuron.new }
end

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

#partialObject

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

#valuesObject

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