void main() { NET Net; BOOL Stop; REAL MinTestError; InitializeRandoms(); GenerateNetwork(&Net); RandomWeights(&Net); InitializeApplication(&Net); Stop = FALSE; MinTestError = MAX_REAL; do { TrainNet(&Net, 10); TestNet(&Net); if (TestError < MinTestError) { fprintf(f, " - saving Weights ..."); MinTestError = TestError; SaveWeights(&Net); } else if (TestError > 1.2 * MinTestError) { fprintf(f, " - stopping Training and restoring Weights ..."); Stop = TRUE; RestoreWeights(&Net); } } while (NOT Stop); TestNet(&Net); EvaluateNet(&Net); FinalizeApplication(&Net); }
void MultiLayerPerceptron::Run(const char* fname, const int& maxiter) { int countTrain = 0; int countLines = 0; bool Stop = false; bool firstIter = true; double dMinTestError = 0.0; InitializeRandoms(); RandomWeights(); do { countLines += Train(fname); Test(fname); countTrain++; if(firstIter) { dMinTestError = dAvgTestError; firstIter = false; } printf( "%i \t TestError: %f", countTrain, dAvgTestError); if ( dAvgTestError < dMinTestError) { printf(" -> saving weights\n"); dMinTestError = dAvgTestError; SaveWeights(); } else if (dAvgTestError > 1.2 * dMinTestError) { printf(" -> stopping training and restoring weights\n"); Stop = true; RestoreWeights(); } else { printf(" -> ok\n"); } } while ( (!Stop) && (countTrain<maxiter) ); printf("bye\n"); }