network.rb
# Runs the network with given input.
# Results are stored in the output layer.
#
# Input can be given in two forms:
# * A vector of values.
# * A NetworkLayer consisting of NetworkNeurons.
Runs the network with given input.
Results are stored in the output layer.

Input can be given in two forms:
A vector of values.
Runs the network with given input . Results are stored in the output layer . Input can be given in two forms : A vector of values .
def run(input=nil)
		if !input.nil?
			if input.kind_of?(NetworkLayer)
				last_layer = input
			elsif input.kind_of?(Array)
				last_layer = NetworkLayer.new(input.size)
				last_layer.getNeurons.each do |n|
					n.output = input.shift()
				end
			end
		else
			l = @layers 
			last_layer = l.shift() 
		end
		@layers.each do |l|
			l.getNeurons.each do |n|
				sum = 0.0
				for neuron in last_layer.getNeurons
					sum = n.weight * neuron.output + sum
				end
				value = eval("%s(sum)" % n.activation_function)
				if !@squash.nil? 
					if n.threshold < value
						n.output = @MIN
					else
						n.output = @MAX
					end
				else 
					n.output = value
				end
			end	
			last_layer = l
		end
		if @return_vector.nil?
			return last_layer 
		else
			d = Array.new
			last_layer.getNeurons.each do |n|
				d.push(n.output)
			end
			return d 
		end
	end
def run ( input = nil ) if ! input . nil? if input . kind_of? ( NetworkLayer ) last_layer = input elsif input . kind_of? ( Array ) last_layer = NetworkLayer . new ( input . size ) last_layer . getNeurons . each do | n | n . output = input . shift ( ) end end else l = @layers last_layer = l . shift ( ) end @layers . each do | l | l . getNeurons . each do | n | sum = 0.0 for neuron in last_layer . getNeurons sum = n . weight * neuron . output + sum end value = eval ( "%s(sum)" % n . activation_function ) if ! @squash . nil? if n . threshold < value n . output = @MIN else n . output = @MAX end else n . output = value end end last_layer = l end if @return_vector . nil? return last_layer else d = Array . new last_layer . getNeurons . each do | n | d . push ( n . output ) end return d end end
Runs the network with given input.
Runs the network with given input .
# If input isn't nil, then a vector or layer is being passed in instead of a preinit'ed input layer # Copy the layers array # Pop input layer off copied stack # Process the data # Sum the weight of the neuron against the input values # Smooth the sum using the neurons activation function # Squash the value # Return the raw value # Last layer will be the output layer # Return back a vector instead of a layer
input
<not_specific>