/// <summary> /// Used internally to calculate the error for a training set. /// </summary> /// <param name="trainingSet"> The training set to calculate for. </param> /// <returns> The error value. </returns> private double determineError(DataSet trainingSet) { double result = 0d; IEnumerator <DataSetRow> iterator = trainingSet.iterator(); while (iterator.MoveNext() && !Stopped) { DataSetRow trainingSetRow = iterator.Current; double[] input = trainingSetRow.Input; Network.Input = input; Network.calculate(); double[] output = Network.Output; double[] desiredOutput = trainingSetRow.DesiredOutput; double[] patternError = ErrorFunction.calculatePatternError(desiredOutput, output); double sqrErrorSum = 0; foreach (double error in patternError) { sqrErrorSum += (error * error); } result += sqrErrorSum / (2 * patternError.Length); } return(result); }
/// <summary> /// Trains network with the input and desired output pattern from the specified training element /// </summary> /// <param name="trainingElement"> supervised training element which contains input and desired output </param> protected internal virtual void learnPattern(DataSetRow trainingElement) { double[] input = trainingElement.Input; this.neuralNetwork.Input = input; this.neuralNetwork.calculate(); double[] output = this.neuralNetwork.Output; double[] desiredOutput = trainingElement.DesiredOutput; double[] patternError = errorFunction.calculatePatternError(output, desiredOutput); this.updateNetworkWeights(patternError); }