lib/newral/networks/backpropagation_network.rb
def train( input: [], output: [] )
        before_error =  calculate_error( input: input,output: output )
        input.each_with_index do |input,idx| 
          calculated_output = update_with_vector( input )
          @layers["output"].neurons.each_with_index do |neuron,neuron_idx|
            neuron.adjust_weights( expected: output[ idx ][ neuron_idx ])
          end 

          @layers["hidden"].neurons.each do |neuron|
            neuron.adjust_weights( expected: output[ idx ], layer: :hidden, output: calculated_output, weights_at_output_nodes: output_weights( neuron ))
          end 
        end
        new_error =  calculate_error( input: input,output: output )
        before_error-new_error
      end
# gets an array of inputs and the corresponding expected outputs
# first we update our output layer then our hidden layer
gets an array of inputs and the corresponding expected outputs
first we update our output layer then our hidden layer
gets an array of inputs and the corresponding expected outputs first we update our output layer then our hidden layer
def train( input: [], output: [] )
        before_error =  calculate_error( input: input,output: output )
        input.each_with_index do |input,idx| 
          calculated_output = update_with_vector( input )
          @layers["output"].neurons.each_with_index do |neuron,neuron_idx|
            neuron.adjust_weights( expected: output[ idx ][ neuron_idx ])
          end 
          @layers["hidden"].neurons.each do |neuron|
            neuron.adjust_weights( expected: output[ idx ], layer: :hidden, output: calculated_output, weights_at_output_nodes: output_weights( neuron ))
          end 
        end
        new_error =  calculate_error( input: input,output: output )
        before_error-new_error
      end
def train ( input : [ ] , output : [ ] ) before_error = calculate_error ( input : input , output : output ) input . each_with_index do | input , idx | calculated_output = update_with_vector ( input ) @layers [ "output" ] . neurons . each_with_index do | neuron , neuron_idx | neuron . adjust_weights ( expected : output [ idx ] [ neuron_idx ] ) end @layers [ "hidden" ] . neurons . each do | neuron | neuron . adjust_weights ( expected : output [ idx ] , layer : :hidden , output : calculated_output , weights_at_output_nodes : output_weights ( neuron ) ) end end new_error = calculate_error ( input : input , output : output ) before_error - new_error end
gets an array of inputs and the corresponding expected outputs
first we update our output layer then our hidden layer
gets an array of inputs and the corresponding expected outputs first we update our output layer then our hidden layer
input
output