From 1b0156a8ea67818178989c9328fb51887a691b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asr=C4=B1n=20Do=C4=9Fan?= <33391270+Syntriax@users.noreply.github.com> Date: Wed, 25 Dec 2019 20:29:29 +0300 Subject: [PATCH] Missing Indexes --- Genetic.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Genetic.cpp b/Genetic.cpp index 882caa4..0593ea8 100644 --- a/Genetic.cpp +++ b/Genetic.cpp @@ -688,14 +688,14 @@ double RandomDouble(int min, int max) void SetInput(double, int); void NextGeneration(); void WriteBestToFile(); - void UpdateScores(); + void UpdateScores(int); void ResetScores(); bool CreateNetworks(int, int); bool ConnectNetworks(); bool SetInputNeurons(int); bool SetHiddenNeurons(int, int); bool SetOutputNeurons(int); - double GetBestPrediction(int); + double GetPredictionOfBestNetwork(int); double GetError(int); int GetStep(); }; @@ -770,13 +770,13 @@ double RandomDouble(int min, int max) std::cout << "Target -> " << target << "\tBest -> " << networks -> GetPrediction(index) << "\n"; } - void Generation::UpdateScores() + void Generation::UpdateScores(int index = 0) { double scoreToAdd; int i; for (i = 0; i < size; i++) { - scoreToAdd = (networks + i) -> GetError(0, target); + scoreToAdd = (networks + i) -> GetError(index, target); (networks + i) -> SetScore((networks + i) -> GetScore() + scoreToAdd); } } @@ -788,7 +788,7 @@ double RandomDouble(int min, int max) (networks + i) -> SetScore(0.0); } - double Generation::GetBestPrediction(int index = 0) + double Generation::GetPredictionOfBestNetwork(int index = 0) { return networks -> GetPrediction(index); } @@ -990,7 +990,7 @@ int main() generation.NextGeneration(); } } - std::cout << "Best Score -> " << generation.GetBestPrediction() << "\n"; + std::cout << "Best Score -> " << generation.GetPredictionOfBestNetwork() << "\n"; std::cout << "Train is Over!\n"; // break; To test it after the train is done case -1: @@ -1002,8 +1002,8 @@ int main() generation.SetTarget(testInputs[inputCounter][4]); generation.Fire(); - currentError = testInputs[inputCounter][4] - generation.GetBestPrediction() < 0 ? generation.GetBestPrediction() - testInputs[inputCounter][4] : testInputs[inputCounter][4] - generation.GetBestPrediction(); - fprintf(outputFile, "%lf,%lf,%lf\n", testInputs[inputCounter][4], generation.GetBestPrediction(), currentError); + currentError = testInputs[inputCounter][4] - generation.GetPredictionOfBestNetwork() < 0 ? generation.GetPredictionOfBestNetwork() - testInputs[inputCounter][4] : testInputs[inputCounter][4] - generation.GetPredictionOfBestNetwork(); + fprintf(outputFile, "%lf,%lf,%lf\n", testInputs[inputCounter][4], generation.GetPredictionOfBestNetwork(), currentError); } fclose(outputFile); std::cout << "Test is Over!\n";