public static int TrainAdaptiveWithConfidenceAndPerformance(this NeuralNet net, List <List <double> > inputs, List <List <double> > expectedResults, double performanceThreshold, int iterationLimit, Reading testData) { Contract.Equals(inputs.Count, expectedResults.Count); bool trained; int iteration = 0; double performanceOnOneBefore = -1; double performance = -1; List <double> performances; do { performances = new List <double>(inputs.Count); var setsTrained = inputs.Count; trained = true; performanceOnOneBefore = net.CalculatePerformance(); for (int i = 0; i < inputs.Count; i++) { performances.Add(net.CalculatePerformance()); net.ChangeData(inputs[i], expectedResults[i]); var setTrained = performances[i] >= performanceThreshold; trained &= setTrained; if (setTrained) { setsTrained--; } net.UpdateAdjustment(); } net.AdjustCumulatedWeights(); net.ResetValues(); net.ResetDerrivates(); performance = net.CalculatePerformance(); var performanceIncreased = performance > performanceOnOneBefore; var performanceIncreaseUnderThreshold = performance - performanceOnOneBefore < 0.0000000001; if (performanceIncreased && performanceIncreaseUnderThreshold) //+2 { Link.RenewalFactor = 0.000001; } else { Link.RenewalFactor = 0; } iteration++; if (iteration % 1000 == 0) { Debug.WriteLine("Iteration: " + iteration++ + " performance:" + net.CalculatePerformance() + "Performance average" + performances.Sum() / performances.Count + " Sets untrained:" + setsTrained); ComputeResultsAndConfidence(iteration, net, testData); } if (iteration % iterationLimit == 0) { Link.RenewalFactor = 1; } }while (!trained); Debug.WriteLine("Iteration: " + iteration); return(iteration); }