class NeuralNetwork::Layer
Attributes
neurons[RW]
Public Class Methods
new(size)
click to toggle source
# File lib/neural_network/layer.rb, line 5 def initialize(size) @neurons = Array.new(size) { Neuron.new } end
Public Instance Methods
activate(values = nil)
click to toggle source
# File lib/neural_network/layer.rb, line 21 def activate(values = nil) values = Array(values) # coerce it to an array if nil @neurons.each_with_index do |neuron, index| neuron.activate(values[index]) end # optional: return mapping of neuron outputs @neurons.map { |n| n.output } end
connect(target_layer)
click to toggle source
# File lib/neural_network/layer.rb, line 9 def connect(target_layer) unless @neurons.any? {|neuron| neuron.bias? } @neurons << NeuralNetwork::BiasNeuron.new end @neurons.each do |source_neuron| target_layer.neurons.each do |target_neuron| source_neuron.connect(target_neuron) end end end
train(target_outputs = [])
click to toggle source
# File lib/neural_network/layer.rb, line 33 def train(target_outputs = []) @neurons.each_with_index do |neuron, index| neuron.train(target_outputs[index]) end end