-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
after_evolution
method to search
/ evolution
classes
Issue #11
- Loading branch information
Showing
8 changed files
with
160 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* \remark This file is part of VITA. | ||
* | ||
* \copyright Copyright (C) 2024 EOS di Manlio Morini. | ||
* | ||
* \license | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/ | ||
* | ||
* \see | ||
* https://github.com/morinim/ultra/wiki/symbolic_regression | ||
*/ | ||
|
||
/* CHANGES IN THIS FILE MUST BE APPLIED TO THE LINKED WIKI PAGE */ | ||
|
||
#include "kernel/ultra.h" | ||
|
||
int main() | ||
{ | ||
using namespace ultra; | ||
|
||
// DATA SAMPLE | ||
// (the target function is `x + sin(x)`) | ||
std::istringstream training(R"( | ||
-9.456,-10.0 | ||
-8.989, -8.0 | ||
-5.721, -6.0 | ||
-3.243, -4.0 | ||
-2.909, -2.0 | ||
0.000, 0.0 | ||
2.909, 2.0 | ||
3.243, 4.0 | ||
5.721, 6.0 | ||
8.989, 8.0 | ||
)"); | ||
|
||
// READING INPUT DATA | ||
src::problem prob(training); | ||
|
||
// SETTING UP SYMBOLS | ||
prob.insert<real::sin>(); | ||
prob.insert<real::cos>(); | ||
prob.insert<real::add>(); | ||
prob.insert<real::sub>(); | ||
prob.insert<real::div>(); | ||
prob.insert<real::mul>(); | ||
|
||
// SEARCHING | ||
prob.params.evolution.generations = 50; | ||
src::search s(prob); | ||
|
||
// This is a callback function invoked at the end of every generation and | ||
// useful to gather statistical data. | ||
s.after_generation([](const auto &pop, const auto &) | ||
{ | ||
for (const auto &i : pop) | ||
std::cout << out::python_language << i << '\n'; | ||
std::cout << "--------------------------------------\n"; | ||
}); | ||
|
||
const auto result(s.run()); | ||
|
||
std::cout << "\nCANDIDATE SOLUTION\n" | ||
<< out::c_language << result.best_individual | ||
<< "\n\nFITNESS\n" << *result.best_measurements.fitness << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters