public void train(double[,] inputs_array, double[,] targets_array) { //converts the array into a useable matrices object Matrix_Math inputs = new Matrix_Math(inputs_array); Matrix_Math targets = new Matrix_Math(targets_array); //Multiplie the input-hidden weight matrix with the inputs to create the input of the hidden layer Matrix_Math hidden_inputs = Matrix_Math.multiply(this.Winput_hidden, inputs); //Sigmoids the input of the hidden layer to create the output of the hidden layer Matrix_Math hidden_outputs = Matrix_Math.Map(hidden_inputs, sigmoid); //Multiplie the hidden-output weight matrix with the output of the hidden layer to create the input of the final layer Matrix_Math final_inputs = Matrix_Math.multiply(this.Whidden_output, hidden_outputs); //Sigmoids the input of the hidden layer to create the output of the final layer Matrix_Math final_outputs = Matrix_Math.Map(final_inputs, sigmoid); //Calculates the error for the output layer - (target - actual) Matrix_Math output_errors = Matrix_Math.Subtract(targets, final_outputs); //Calculates the errors of the hidden layer by multiplying the transposed weights of the hidden - output layer by the errors of the output layer Matrix_Math hidden_errors = Matrix_Math.multiply(Matrix_Math.Transpose(this.Whidden_output), output_errors); //OOF, this multiples the learning rate by the dot product of the multipication of the output erros, the output of the final layer and (1 - the output of the final layer) and the transposed output of the hidden layer this.Whidden_output.AddSelf(Matrix_Math.multiply(Matrix_Math.multiply(Matrix_Math.MultiplyHadamard(Matrix_Math.MultiplyHadamard(output_errors, final_outputs), Matrix_Math.Map(final_outputs, dsigmoid)), Matrix_Math.Transpose(hidden_outputs)), this.lr)); //OOF, this multiples the learning rate by the dot product of the multipication of the hidden erros, the output of the hiddedn layer and (1 - the output of the hidden layer) and the transposed output of the input layer this.Winput_hidden.AddSelf(Matrix_Math.multiply(Matrix_Math.multiply(Matrix_Math.MultiplyHadamard(Matrix_Math.MultiplyHadamard(hidden_errors, hidden_outputs), Matrix_Math.Map(hidden_outputs, dsigmoid)), Matrix_Math.Transpose(inputs)), this.lr)); }
public Matrix_Math query(double[,] inputs_array) { //converts the array into a useable matrix object Matrix_Math inputs = new Matrix_Math(inputs_array); //Multiplie the input-hidden weight matrix with the inputs to create the input of the hidden layer Matrix_Math hidden_inputs = Matrix_Math.multiply(this.Winput_hidden, inputs); //Sigmoids the input of the hidden layer to create the output of the hidden layer Matrix_Math hidden_outputs = Matrix_Math.Map(hidden_inputs, sigmoid); //Multiplie the hidden-output weight matrix with the output of the hidden layer to create the input of the final layer Matrix_Math final_inputs = Matrix_Math.multiply(this.Whidden_output, hidden_outputs); //Sigmoids the input of the hidden layer to create the output of the final layer Matrix_Math final_outputs = Matrix_Math.Map(final_inputs, sigmoid); return(final_outputs); }