From bdbdc01cbb19503646eeddf58dde878671aa7284 Mon Sep 17 00:00:00 2001 From: beny Date: Sat, 6 Jul 2024 17:27:08 -0700 Subject: [PATCH 01/54] IPOP and IPOP restart mechanisms --- include/ensmallen.hpp | 2 + include/ensmallen_bits/cmaes/bipop_cmaes.hpp | 147 ++++++++++++++++ .../ensmallen_bits/cmaes/bipop_cmaes_impl.hpp | 113 +++++++++++++ include/ensmallen_bits/cmaes/cmaes.hpp | 12 ++ include/ensmallen_bits/cmaes/cmaes_impl.hpp | 3 + include/ensmallen_bits/cmaes/ipop_cmaes.hpp | 159 ++++++++++++++++++ .../ensmallen_bits/cmaes/ipop_cmaes_impl.hpp | 85 ++++++++++ tests/bipop_cmaes_test.cpp | 49 ++++++ tests/ipop_cmaes_test.cpp | 56 ++++++ 9 files changed, 626 insertions(+) create mode 100644 include/ensmallen_bits/cmaes/bipop_cmaes.hpp create mode 100644 include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp create mode 100644 include/ensmallen_bits/cmaes/ipop_cmaes.hpp create mode 100644 include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp create mode 100644 tests/bipop_cmaes_test.cpp create mode 100644 tests/ipop_cmaes_test.cpp diff --git a/include/ensmallen.hpp b/include/ensmallen.hpp index 72e6f248c..7d39da684 100644 --- a/include/ensmallen.hpp +++ b/include/ensmallen.hpp @@ -103,6 +103,8 @@ #include "ensmallen_bits/bigbatch_sgd/bigbatch_sgd.hpp" #include "ensmallen_bits/cmaes/cmaes.hpp" #include "ensmallen_bits/cmaes/active_cmaes.hpp" +#include "ensmallen_bits/cmaes/ipop_cmaes.hpp" +#include "ensmallen_bits/cmaes/bipop_cmaes.hpp" #include "ensmallen_bits/cd/cd.hpp" #include "ensmallen_bits/cne/cne.hpp" #include "ensmallen_bits/de/de.hpp" diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp new file mode 100644 index 000000000..7c46dee54 --- /dev/null +++ b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp @@ -0,0 +1,147 @@ +/** + * @file bipop_cmaes.hpp + * @author Marcus Edel + * @author Benjami Parellada + * + * Definition of the BIPOP Covariance Matrix Adaptation Evolution Strategy + * as proposed by N. Hansen in "Benchmarking a BI-population CMA-ES on the + * BBOB-2009 function testbed". + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef ENSMALLEN_CMAES_BIPOP_CMAES_HPP +#define ENSMALLEN_CMAES_BIPOP_CMAES_HPP + +#include "cmaes.hpp" + +namespace ens { + +/** + * BI-Population CMA-ES is a variant of the stochastic search algorithm + * CMA-ES - Covariance Matrix Adaptation Evolution Strategy. + * It implements a dual restart strategy with varying population sizes: one + * increasing and one with smaller, varied sizes. This BI-population approach + * is designed to optimize performance on multi-modal function testbeds by + * leveraging different exploration and exploitation dynamics. + * + * For more information, please refer to: + * + * @code + * @inproceedings{hansen2009benchmarking, + * title={Benchmarking a BI-population CMA-ES on the BBOB-2009 function testbed}, + * author={Hansen, Nikolaus}, + * booktitle={Proceedings of the 11th annual conference companion on genetic and evolutionary computation conference: late breaking papers}, + * pages={2389--2396}, + * year={2009}} + * @endcode + * + * BI-Population CMA-ES can efficiently handle separable, multimodal, and weak + * structure functions across various dimensions, as demonstrated in the + * comprehensive results of the BBOB-2009 function testbed. The optimizer + * utilizes an interlaced multistart strategy to balance between broad + * exploration and intensive exploitation, adjusting population sizes and + * step-sizes dynamically. + * + * @tparam CMAESType The type of CMA-ES used for optimization. Options include standard CMAES and variants like ActiveCMAES. + */ +template> +class BIPOPCMAES +{ + public: + /** + * Construct the BIPOP CMA-ES optimizer with the given CMAES object, + * and maximum number of restarts. The defaults + * here are not necessarily good for the given problem, so it is + * suggested that the values used be tailored to the task at hand. The + * maximum number of iterations refers to the maximum number of points that + * are processed (i.e., one iteration equals one point; one iteration does not + * equal one pass over the dataset). + * + * @param CMAES The CMAES object. + * @param populationFactor The factor by which population increases + * after each restart. + * @param maxRestarts Maximum number of restarts. + */ + BIPOPCMAES(const CMAESType& CMAES = CMAESType(), + const size_t maxRestarts = 9); + + /** + * Construct the BIPOP CMA-ES optimizer with the given function and parameters. + * The defaults here are not necessarily good for the given problem, so it + * is suggested that the values used be tailored to the task at hand. The + * maximum number of iterations refers to the maximum number of points that + * are processed (i.e., one iteration equals one point; one iteration does + * not equal one pass over the dataset). + * + * @param lambda The initial population size (0 use the default size). + * @param transformationPolicy Instantiated transformation policy used to + * map the coordinates to the desired domain. + * @param batchSize Batch size to use for the objective calculation. + * @param maxIterations Maximum number of iterations allowed(0 means no + limit). + * @param tolerance Maximum absolute tolerance to terminate algorithm. + * @param selectionPolicy Instantiated selection policy used to calculate the + * objective. + * @param stepSize Starting sigma/step size (will be modified). + * @param populationFactor The factor by which population increases + * after each restart. + * @param maxRestarts Maximum number of restarts. + */ +BIPOPCMAES(const size_t lambda = 0, + const typename CMAESType::transformationPolicyType& + transformationPolicy = typename CMAESType::transformationPolicyType(), + const size_t batchSize = 32, + const size_t maxIterations = 1000, + const double tolerance = 1e-5, + const typename CMAESType::selectionPolicyType& + selectionPolicy = typename CMAESType::selectionPolicyType(), + double stepSize = 0, + const size_t maxRestarts = 9); + + /** + * Optimize the given function using BIPOP CMA-ES. The given starting point will be + * modified to store the finishing point of the algorithm, and the final + * objective value is returned. + * + * @tparam SeparableFunctionType Type of the function to be optimized. + * @tparam MatType Type of matrix to optimize. + * @tparam CallbackTypes Types of callback functions. + * @param function Function to optimize. + * @param iterate Starting point (will be modified). + * @param callbacks Callback functions. + * @return Objective value of the final point. + */ + template + typename MatType::elem_type Optimize(SeparableFunctionType& function, + MatType& iterate, + CallbackTypes&&... callbacks); + + //! Get the maximum number of restarts. + size_t MaxRestarts() const { return maxRestarts; } + //! Modify the maximum number of restarts. + size_t& MaxRestarts() { return maxRestarts; } + + //! Get the CMAES object. + const CMAESType& CMAES() const { return cmaes; } + //! Modify the CMAES object. + CMAESType& CMAES() { return cmaes; } + + private: + //! Maximum number of restarts. + size_t maxRestarts; + + //! The CMAES object used for optimization. + CMAESType cmaes; +}; + +} // namespace ens + +// Include implementation. +#include "bipop_cmaes_impl.hpp" + +#endif \ No newline at end of file diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp new file mode 100644 index 000000000..35cbca623 --- /dev/null +++ b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp @@ -0,0 +1,113 @@ +/** + * @file bipop_cmaes_impl.hpp + * @author Benjami Parellada + * + * Implementation of the BIPOP Covariance Matrix Adaptation Evolution Strategy + * as proposed by N. Hansen in "Benchmarking a BI-population CMA-ES on the + * BBOB-2009 function testbed". + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ + +#ifndef ENSMALLEN_CMAES_BIPOP_CMAES_IMPL_HPP +#define ENSMALLEN_CMAES_BIPOP_CMAES_IMPL_HPP + +#include "bipop_cmaes.hpp" +#include +#include + +namespace ens { + +template +BIPOPCMAES::BIPOPCMAES(const CMAESType& CMAES, + const size_t maxRestarts) : + cmaes(CMAES), + maxRestarts(maxRestarts) +{ /* Nothing to do. */ } + +template +BIPOPCMAES::BIPOPCMAES(const size_t lambda, + const typename CMAESType::transformationPolicyType& transformationPolicy, + const size_t batchSize, + const size_t maxIterations, + const double tolerance, + const typename CMAESType::selectionPolicyType& selectionPolicy, + double stepSize, + const size_t maxRestarts) : + cmaes(lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), + maxRestarts(maxRestarts) +{ /* Nothing to do. */ } + +template +template +typename MatType::elem_type BIPOPCMAES::Optimize( + SeparableFunctionType& function, + MatType& iterateIn, + CallbackTypes&&... callbacks) +{ + StoreBestCoordinates sbc; + size_t totalFunctionEvaluations = 0; + size_t largePopulationBudget = 0; + size_t smallPopulationBudget = 0; + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> dis(0.0, 1.0); + + // First single run with default population size + MatType iterate = iterateIn; + cmaes.Optimize(function, iterate, sbc, callbacks...); + + size_t defaultLambda = cmaes.PopulationSize(); + size_t currentLargeLambda = defaultLambda; + + for (size_t i = 0; i < maxRestarts; ++i) + { + if (largePopulationBudget <= smallPopulationBudget || i == 0 || i == maxRestarts - 1) + { + // Large population regime + currentLargeLambda *= 2; + cmaes.PopulationSize() = currentLargeLambda; + cmaes.StepSize() = 2.0; + + iterate = iterateIn; + cmaes.Optimize(function, iterate, sbc, callbacks...); + + size_t evaluations = cmaes.FunctionEvaluations(); + totalFunctionEvaluations += evaluations; + largePopulationBudget += evaluations; + } + else + { + // Small population regime + double u = dis(gen); + size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * currentLargeLambda / defaultLambda, u * u)); + cmaes.PopulationSize() = smallLambda; + cmaes.StepSize() = 2 * std::pow(10, -2*dis(gen)); + + iterate = iterateIn; + cmaes.Optimize(function, iterate, sbc, callbacks...); + + size_t evaluations = cmaes.FunctionEvaluations(); + totalFunctionEvaluations += evaluations; + smallPopulationBudget += evaluations; + } + + // Check if the total number of evaluations has exceeded the limit + if (totalFunctionEvaluations >= 1e9) { + break; + } + } + + // Store the best coordinates + iterateIn = sbc.BestCoordinates(); + // Return the best objective + return sbc.BestObjective(); +} + +} // namespace ens + +#endif diff --git a/include/ensmallen_bits/cmaes/cmaes.hpp b/include/ensmallen_bits/cmaes/cmaes.hpp index 0ae323490..7bd4140c3 100644 --- a/include/ensmallen_bits/cmaes/cmaes.hpp +++ b/include/ensmallen_bits/cmaes/cmaes.hpp @@ -172,6 +172,15 @@ class CMAES double& StepSize() { return stepSize; } + //! Get the total number of function evaluations. + size_t FunctionEvaluations() const + { return functionEvaluations; } + + //! Type of Selection Policy. + typedef SelectionPolicyType selectionPolicyType; + //! Type of Transformation Policy. + typedef TransformationPolicyType transformationPolicyType; + private: //! Population size. size_t lambda; @@ -195,6 +204,9 @@ class CMAES //! The step size. double stepSize; + + //! Counter for the number of function evaluations. + size_t functionEvaluations = 0; }; /** diff --git a/include/ensmallen_bits/cmaes/cmaes_impl.hpp b/include/ensmallen_bits/cmaes/cmaes_impl.hpp index 73a5c7f02..4d2c18e3d 100644 --- a/include/ensmallen_bits/cmaes/cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/cmaes_impl.hpp @@ -151,6 +151,7 @@ typename MatType::elem_type CMAES::max(); @@ -235,6 +236,8 @@ typename MatType::elem_type CMAES> +class IPOPCMAES +{ + public: + /** + * Construct the IPOP CMA-ES optimizer with the given CMAES object, + * population factor, and maximum number of restarts. The defaults + * here are not necessarily good for the given problem, so it is + * suggested that the values used be tailored to the task at hand. The + * maximum number of iterations refers to the maximum number of points that + * are processed (i.e., one iteration equals one point; one iteration does not + * equal one pass over the dataset). + * + * @param CMAES The CMAES object. + * @param populationFactor The factor by which population increases + * after each restart. + * @param maxRestarts Maximum number of restarts. + */ + IPOPCMAES(const CMAESType& CMAES = CMAESType(), + const double populationFactor = 2, + const size_t maxRestarts = 9); + + /** + * Construct the IPOP CMA-ES optimizer with the given function and parameters. + * The defaults here are not necessarily good for the given problem, so it + * is suggested that the values used be tailored to the task at hand. The + * maximum number of iterations refers to the maximum number of points that + * are processed (i.e., one iteration equals one point; one iteration does + * not equal one pass over the dataset). + * + * @param lambda The initial population size (0 use the default size). + * @param transformationPolicy Instantiated transformation policy used to + * map the coordinates to the desired domain. + * @param batchSize Batch size to use for the objective calculation. + * @param maxIterations Maximum number of iterations allowed(0 means no + limit). + * @param tolerance Maximum absolute tolerance to terminate algorithm. + * @param selectionPolicy Instantiated selection policy used to calculate the + * objective. + * @param stepSize Starting sigma/step size (will be modified). + * @param populationFactor The factor by which population increases + * after each restart. + * @param maxRestarts Maximum number of restarts. + */ +IPOPCMAES(const size_t lambda = 0, + const typename CMAESType::transformationPolicyType& + transformationPolicy = typename CMAESType::transformationPolicyType(), + const size_t batchSize = 32, + const size_t maxIterations = 1000, + const double tolerance = 1e-5, + const typename CMAESType::selectionPolicyType& + selectionPolicy = typename CMAESType::selectionPolicyType(), + double stepSize = 0, + const double populationFactor = 2, + const size_t maxRestarts = 9); + + /** + * Optimize the given function using IPOP CMA-ES. The given starting point will be + * modified to store the finishing point of the algorithm, and the final + * objective value is returned. + * + * @tparam SeparableFunctionType Type of the function to be optimized. + * @tparam MatType Type of matrix to optimize. + * @tparam CallbackTypes Types of callback functions. + * @param function Function to optimize. + * @param iterate Starting point (will be modified). + * @param callbacks Callback functions. + * @return Objective value of the final point. + */ + template + typename MatType::elem_type Optimize(SeparableFunctionType& function, + MatType& iterate, + CallbackTypes&&... callbacks); + + //! Get the population factor. + double PopulationFactor() const { return populationFactor; } + //! Modify the population factor. + double& PopulationFactor() { return populationFactor; } + + //! Get the maximum number of restarts. + size_t MaxRestarts() const { return maxRestarts; } + //! Modify the maximum number of restarts. + size_t& MaxRestarts() { return maxRestarts; } + + //! Get the CMAES object. + const CMAESType& CMAES() const { return cmaes; } + //! Modify the CMAES object. + CMAESType& CMAES() { return cmaes; } + + private: + //! Population factor. + double populationFactor; + + //! Maximum number of restarts. + size_t maxRestarts; + + //! The CMAES object used for optimization. + CMAESType cmaes; +}; + +} // namespace ens + +// Include implementation. +#include "ipop_cmaes_impl.hpp" + +#endif \ No newline at end of file diff --git a/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp new file mode 100644 index 000000000..7ecddc92a --- /dev/null +++ b/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp @@ -0,0 +1,85 @@ +/** + * @file ipop_cmaes_impl.hpp + * @author Marcus Edel + * @author Suvarsha Chennareddy + * @author Benjami Parellada + * + * Implementation of the IPOP Covariance Matrix Adaptation Evolution Strategy + * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution + * Strategy With Increasing Population Size". + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef ENSMALLEN_CMAES_IPOP_CMAES_IMPL_HPP +#define ENSMALLEN_CMAES_IPOP_CMAES_IMPL_HPP + +#include "ipop_cmaes.hpp" +#include + +namespace ens { + +template +IPOPCMAES::IPOPCMAES(const CMAESType& CMAES, + const double populationFactor, + const size_t maxRestarts) : + cmaes(CMAES), + populationFactor(populationFactor), + maxRestarts(maxRestarts) +{ /* Nothing to do. */ } + +template +IPOPCMAES::IPOPCMAES(const size_t lambda, + const typename CMAESType::transformationPolicyType& transformationPolicy, + const size_t batchSize, + const size_t maxIterations, + const double tolerance, + const typename CMAESType::selectionPolicyType& selectionPolicy, + double stepSize, + const double populationFactor, + const size_t maxRestarts) : + cmaes(lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), + populationFactor(populationFactor), + maxRestarts(maxRestarts) +{ /* Nothing to do. */ } + +template +template +typename MatType::elem_type IPOPCMAES::Optimize( + SeparableFunctionType& function, + MatType& iterateIn, + CallbackTypes&&... callbacks) +{ + StoreBestCoordinates sbc; + size_t totalFunctionEvaluations = 0; + for (size_t i = 0; i < maxRestarts; ++i) + { + // Use the starting point. + MatType iterate = iterateIn; + + // Optimize using the CMAES object. + cmaes.Optimize(function, iterate, sbc, callbacks...); + + // Retrieve and accumulate the number of function evaluations used by CMAES. + totalFunctionEvaluations += cmaes.FunctionEvaluations(); + + // Check if the total number of evaluations has exceeded the limit + if (totalFunctionEvaluations >= 1e9) { + break; + } + + // Increase the population size by the population factor for next restart. + cmaes.PopulationSize() *= populationFactor; + } + + // Store the best coordinates. + iterateIn = sbc.BestCoordinates(); + // Return the best objective. + return sbc.BestObjective(); +} + +} // namespace ens + +#endif diff --git a/tests/bipop_cmaes_test.cpp b/tests/bipop_cmaes_test.cpp new file mode 100644 index 000000000..77b761719 --- /dev/null +++ b/tests/bipop_cmaes_test.cpp @@ -0,0 +1,49 @@ +/** + * @file bipop_cmaes_test.cpp + * @author Benjami Parellada + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ + +#include +#include "catch.hpp" +#include "test_function_tools.hpp" + +using namespace ens; +using namespace ens::test; + +/** + * Run BIPOP CMA-ES with the full selection policy on Rastrigin function and + * make sure the results are acceptable. + */ +TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") +{ + const size_t numFunctions = 2; + BoundaryBoxConstraint<> b(-5.12, 5.12); + CMAES> cmaes(10, b, numFunctions, 0, 1e-5); + cmaes.StepSize() = 3.72; + BIPOPCMAES>> bipopcmaes(cmaes, 10); + + RastriginFunction f(numFunctions); + arma::mat initialPoint = f.template GetInitialPoint(); + arma::mat expectedResult = f.template GetFinalPoint(); + + MultipleTrialOptimizerTest(f, bipopcmaes, initialPoint, expectedResult, + 0.01, f.GetFinalObjective(), 0.1, 5); +} + +/** + * Run BIPOP CMA-ES with the full selection policy on Rosenbrock function and + * make sure the results are acceptable. + */ +TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[BIPOPCMAESTest]") +{ + BoundaryBoxConstraint<> b(0, 2); + BIPOPCMAES>> bipopcmaes(0, b, 16, 0, 1e-3); + bipopcmaes.CMAES().StepSize() = 0.25; + + FunctionTest(bipopcmaes, 0.1, 0.1); +} diff --git a/tests/ipop_cmaes_test.cpp b/tests/ipop_cmaes_test.cpp new file mode 100644 index 000000000..e9e06a060 --- /dev/null +++ b/tests/ipop_cmaes_test.cpp @@ -0,0 +1,56 @@ +/** + * @file ipop_cmaes_test.cpp + * @author Suvarsha Chennareddy + * @author Benjami Parellada + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ + +#include +#include "catch.hpp" +#include "test_function_tools.hpp" + +using namespace ens; +using namespace ens::test; + +/** + * Run IPOP CMA-ES with the full selection policy on Rastrigin function and + * make sure the results are acceptable. + */ +TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") +{ + const size_t numFunctions = 2; + + BoundaryBoxConstraint<> b(-5.12, 5.12); + CMAES> cmaes(10, b, numFunctions, 0, 1e-5); + cmaes.StepSize() = 3.72; + + IPOPCMAES>> + ipopcmaes(cmaes, 2, 10); + + RastriginFunction f(numFunctions); + arma::mat initialPoint = f.template GetInitialPoint(); + arma::mat expectedResult = f.template GetFinalPoint(); + + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, + 0.01, f.GetFinalObjective(), 0.1, 5); +} + +/** + * Run IPOP CMA-ES with the full selection policy on Rosenbrock function and + * make sure the results are acceptable. + */ +TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") +{ + BoundaryBoxConstraint<> b(0, 2); + + IPOPCMAES>> + ipopcmaes(0, b, 16, 0, 1e-3); + ipopcmaes.CMAES().StepSize() = 0.25; + ipopcmaes.PopulationFactor() = 1.5; + + FunctionTest(ipopcmaes, 0.1, 0.1); +} \ No newline at end of file From 6bb6af403949bf945a0e69853a1409d79321a666 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sun, 7 Jul 2024 19:52:00 -0700 Subject: [PATCH 02/54] Update include/ensmallen_bits/cmaes/bipop_cmaes.hpp Co-authored-by: Marcus Edel --- include/ensmallen_bits/cmaes/bipop_cmaes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp index 7c46dee54..f8b7788e5 100644 --- a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp @@ -66,7 +66,7 @@ class BIPOPCMAES * @param maxRestarts Maximum number of restarts. */ BIPOPCMAES(const CMAESType& CMAES = CMAESType(), - const size_t maxRestarts = 9); + const size_t maxRestarts = 9); /** * Construct the BIPOP CMA-ES optimizer with the given function and parameters. From 4d880bb53be0345482f17d7642e2b2e52dc8bd92 Mon Sep 17 00:00:00 2001 From: beny Date: Mon, 8 Jul 2024 13:24:10 -0700 Subject: [PATCH 03/54] add ipop and bipop documentation --- doc/optimizers.md | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/doc/optimizers.md b/doc/optimizers.md index bb8a25073..378566f78 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -778,6 +778,69 @@ optimizer2.Optimize(f, coordinates); * [SGD in Wikipedia](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) * [SGD](#standard-sgd) +## BIPOPCMAES + +*An optimizer for [separable functions](#separable-functions).* + +BIPOP CMA-ES (Bi-Population CMA-ES) extends the idea of IPOP CMA-ES by using +two intertwined restart strategies: one with an increasing population size and +another maintaining a smaller, variable population size. This strategy allows +BIPOP CMA-ES to adaptively balance exploration and exploitation across the +fitness landscape, and can outperform IPOP. The larger population restarts aim +to explore broadly, improving global search capabilities, while the smaller +populations intensify the search in promising regions. + +#### Constructors + + * `BIPOPCMAES<`_`CMAESType`_`>()` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`CMAES`_`)` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`CMAES, maxRestarts`_`)` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy`_`)` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` + * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts`_`)` + +The _`CMAESType`_ template parameter is the CMA-ES type used for the optimization. +Currently, either CMAES or ActiveCMAES can be used. + +#### Attributes + +| **type** | **name** | **description** | **default** | +|----------|----------|-----------------|-------------| +| `CMAESType` | **`cmaes`** | The CMAES object used for optimization. | `CMAESType()` | +| `size_t` | **`maxRestarts`** | Maximum number of restarts. | `9` | + +Attributes of the optimizer may also be changed via the member methods +`CMAES()`, `MaxRestarts()`. + +#### Examples: + +
+Click to collapse/expand example code. + + +```c++ +RosenbrockFunction f; +arma::mat coordinates = f.GetInitialPoint(); + +// IPOP Active CMA-ES +BoundaryBoxConstraint<> b(-1, 1); +CMAES cmaes(0, b, 32, 200, 1e-4); +BIPOPCMAES optimizer(cmaes, 5); +Optimizer.Optimize(f, coordinates); +``` + +
+ +#### See also: + + * [CMAES](#cmaes) + * [ActiveCMAES](#activecmaes) + * [IPOP-CMAES](#ipopcmaes) + * [Benchmarking a BI-Population CMA-ES on the BBOB-2009 Function Testbed](https://dl.acm.org/doi/pdf/10.1145/1570256.1570333) + * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) + ## Coordinate Descent (CD) *An optimizer for [partially differentiable functions](#partially-differentiable-functions).* @@ -1484,6 +1547,73 @@ optimizer.Optimize(f, coordinates); * [HOGWILD!: A Lock-Free Approach to Parallelizing Stochastic Gradient Descent](https://arxiv.org/abs/1106.5730) * [Sparse differentiable separable functions](#sparse-differentiable-separable-functions) +## IPOPCMAES + +*An optimizer for [separable functions](#separable-functions).* + +IPOP CMA-ES (Increasing Population Size CMA-ES) is an extension of the +Covariance Matrix Adaptation Evolution Strategy (CMA-ES). It introduces a +restart mechanism that progressively increases the population size. This +approach is beneficial for optimizing multi-modal functions, +characterized by numerous local optima. The restart mechanism is designed to +improve the adaptability of CMA-ES by improving the likelihood of escaping +local optima, thus increasing the chances of discovering the global optimum. + +#### Constructors + + * `IPOPCMAES<`_`CMAESType`_`>()` + * `IPOPCMAES<`_`CMAESType`_`>(`_`CMAES`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`CMAES, populationFactor`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`CMAES, populationFactor, maxRestarts`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, populationFactor`_`)` + * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, populationFactor, maxRestarts`_`)` + +The _`CMAESType`_ template parameter is the CMA-ES type used for the optimization. +Currently, either CMAES or ActiveCMAES can be used. + +#### Attributes + +| **type** | **name** | **description** | **default** | +|----------|----------|-----------------|-------------| +| `CMAESType` | **`cmaes`** | The CMAES object used for optimization. | `CMAESType()` | +| `double` | **`populationFactor`** | The factor by which population increases after each restart. | `2` | +| `size_t` | **`maxRestarts`** | Maximum number of restarts. | `9` | + +Attributes of the optimizer may also be changed via the member methods +`CMAES()`, `MaxRestarts()`, `PopulationFactor()`. + +#### Examples: + +
+Click to collapse/expand example code. + + +```c++ +RosenbrockFunction f; +arma::mat coordinates = f.GetInitialPoint(); + +// IPOP Active CMA-ES +BoundaryBoxConstraint<> b(-1, 1); +CMAES cmaes(0, b, 32, 200, 1e-4); +IPOPCMAES optimizer(cmaes, 2, 5); +Optimizer.Optimize(f, coordinates); +``` + +
+ +#### See also: + + * [CMAES](#cmaes) + * [ActiveCMAES](#activecmaes) + * [BIPOPCMAES](#bipopcmaes) + * [A Restart CMA Evolution Strategy With Increasing Population Size](http://www.cmap.polytechnique.fr/~nikolaus.hansen/cec2005ipopcmaes.pdf) + * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) + + ## IQN *An optimizer for [differentiable separable functions](#differentiable-separable-functions).* From 8a257b5067889e59119601a87a5e707418596170 Mon Sep 17 00:00:00 2001 From: beny Date: Sun, 28 Jul 2024 21:00:49 -0700 Subject: [PATCH 04/54] update docs --- doc/optimizers.md | 5 +++++ include/ensmallen_bits/cmaes/bipop_cmaes.hpp | 2 +- include/ensmallen_bits/cmaes/ipop_cmaes.hpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 378566f78..4269c0c1f 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -86,7 +86,9 @@ approxOptimizer.Optimize(f, coordinates); #### See also: + * [BIPOPCMAES](#bipopcmaes) * [CMAES](#cmaes) + * [IPOPCMAES](#ipopcmaes) * [Improving Evolution Strategies through Active Covariance Matrix Adaptation](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.4239&rep=rep1&type=pdfn) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) @@ -1001,6 +1003,9 @@ approxOptimizer.Optimize(f, coordinates); #### See also: + * [ActiveCMAES](#activecmaes) + * [BIPOPCMAES](#bipopcmaes) + * [IPOPCMAES](#ipopcmaes) * [Completely Derandomized Self-Adaptation in Evolution Strategies](http://www.cmap.polytechnique.fr/~nikolaus.hansen/cmaartic.pdf) * [CMA-ES in Wikipedia](https://en.wikipedia.org/wiki/CMA-ES) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp index f8b7788e5..9dc407d3e 100644 --- a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp @@ -144,4 +144,4 @@ BIPOPCMAES(const size_t lambda = 0, // Include implementation. #include "bipop_cmaes_impl.hpp" -#endif \ No newline at end of file +#endif diff --git a/include/ensmallen_bits/cmaes/ipop_cmaes.hpp b/include/ensmallen_bits/cmaes/ipop_cmaes.hpp index 7affd5150..bc20ccf24 100644 --- a/include/ensmallen_bits/cmaes/ipop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/ipop_cmaes.hpp @@ -156,4 +156,4 @@ IPOPCMAES(const size_t lambda = 0, // Include implementation. #include "ipop_cmaes_impl.hpp" -#endif \ No newline at end of file +#endif From 942bc371001cf45fc19377e5cb07a8fa4363243e Mon Sep 17 00:00:00 2001 From: beny Date: Sun, 28 Jul 2024 23:49:39 -0700 Subject: [PATCH 05/54] Updates ipop bipop --- include/ensmallen_bits/cmaes/bipop_cmaes.hpp | 26 ++- .../ensmallen_bits/cmaes/bipop_cmaes_impl.hpp | 151 +++++++++++------- include/ensmallen_bits/cmaes/ipop_cmaes.hpp | 16 +- .../ensmallen_bits/cmaes/ipop_cmaes_impl.hpp | 56 ++++--- 4 files changed, 165 insertions(+), 84 deletions(-) diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp index 9dc407d3e..49398c5fb 100644 --- a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp @@ -66,7 +66,9 @@ class BIPOPCMAES * @param maxRestarts Maximum number of restarts. */ BIPOPCMAES(const CMAESType& CMAES = CMAESType(), - const size_t maxRestarts = 9); + const size_t maxRestarts = 9, + const size_t maxFunctionEvaluations = 1e9, + const size_t populationFactor = 2); /** * Construct the BIPOP CMA-ES optimizer with the given function and parameters. @@ -89,6 +91,8 @@ class BIPOPCMAES * @param populationFactor The factor by which population increases * after each restart. * @param maxRestarts Maximum number of restarts. + * @param maxFunctionEvaluations Maximum number of function evaluations for all resets. + * */ BIPOPCMAES(const size_t lambda = 0, const typename CMAESType::transformationPolicyType& @@ -99,7 +103,9 @@ BIPOPCMAES(const size_t lambda = 0, const typename CMAESType::selectionPolicyType& selectionPolicy = typename CMAESType::selectionPolicyType(), double stepSize = 0, - const size_t maxRestarts = 9); + const size_t maxRestarts = 9, + const size_t maxFunctionEvaluations = 1e9, + const size_t populationFactor = 2); /** * Optimize the given function using BIPOP CMA-ES. The given starting point will be @@ -131,10 +137,26 @@ BIPOPCMAES(const size_t lambda = 0, //! Modify the CMAES object. CMAESType& CMAES() { return cmaes; } + //! Get the population factor. + double PopulationFactor() const { return populationFactor; } + //! Modify the population factor. + double& PopulationFactor() { return populationFactor; } + + //! Get the maximum number of function evaluations. + size_t MaxFunctionEvaluations() const { return maxFunctionEvaluations; } + //! Modify the maximum number of function evaluations. + size_t& MaxFunctionEvaluations() { return maxFunctionEvaluations; } + private: //! Maximum number of restarts. size_t maxRestarts; + //! Maximum number of function evaluations. + size_t maxFunctionEvaluations; + + //! Population factor + double populationFactor; + //! The CMAES object used for optimization. CMAESType cmaes; }; diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp index 35cbca623..30ba644ef 100644 --- a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp @@ -23,9 +23,13 @@ namespace ens { template BIPOPCMAES::BIPOPCMAES(const CMAESType& CMAES, - const size_t maxRestarts) : + const size_t maxRestarts, + const size_t maxFunctionEvaluations, + const size_t populationFactor) : cmaes(CMAES), - maxRestarts(maxRestarts) + maxRestarts(maxRestarts), + maxFunctionEvaluations(maxFunctionEvaluations), + populationFactor(populationFactor) { /* Nothing to do. */ } template @@ -36,9 +40,13 @@ BIPOPCMAES::BIPOPCMAES(const size_t lambda, const double tolerance, const typename CMAESType::selectionPolicyType& selectionPolicy, double stepSize, - const size_t maxRestarts) : + const size_t maxRestarts, + const size_t maxFunctionEvaluations, + const size_t populationFactor) : cmaes(lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), - maxRestarts(maxRestarts) + maxRestarts(maxRestarts), + maxFunctionEvaluations(maxFunctionEvaluations), + populationFactor(populationFactor) { /* Nothing to do. */ } template @@ -48,64 +56,97 @@ typename MatType::elem_type BIPOPCMAES::Optimize( MatType& iterateIn, CallbackTypes&&... callbacks) { - StoreBestCoordinates sbc; - size_t totalFunctionEvaluations = 0; - size_t largePopulationBudget = 0; - size_t smallPopulationBudget = 0; + // Convenience typedefs. + typedef typename MatType::elem_type ElemType; + typedef typename MatTypeTraits::BaseMatType BaseMatType; - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> dis(0.0, 1.0); + StoreBestCoordinates sbc; + size_t totalFunctionEvaluations = 0; + size_t largePopulationBudget = 0; + size_t smallPopulationBudget = 0; - // First single run with default population size - MatType iterate = iterateIn; - cmaes.Optimize(function, iterate, sbc, callbacks...); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> dis(0.0, 1.0); - size_t defaultLambda = cmaes.PopulationSize(); - size_t currentLargeLambda = defaultLambda; + // First single run with default population size + MatType iterate = iterateIn; + ElemType overallObjective = cmaes.Optimize(function, iterate, sbc, callbacks...); + ElemType objective; + size_t evaluations; - for (size_t i = 0; i < maxRestarts; ++i) + size_t defaultLambda = cmaes.PopulationSize(); + size_t currentLargeLambda = defaultLambda; + + double stepSizeDefault = cmaes.StepSize(); + + // Print out the default population size + Info << "Default population size: " << defaultLambda << std::endl; + + size_t restart = 0; + + while (restart < maxRestarts) + { + if (largePopulationBudget <= smallPopulationBudget || restart == 0 || restart == maxRestarts - 1) + { + // Large population regime + + currentLargeLambda *= populationFactor; + cmaes = CMAESType(currentLargeLambda, cmaes.TransformationPolicy(), cmaes.BatchSize(), + cmaes.MaxIterations(), cmaes.Tolerance(), cmaes.SelectionPolicy(), stepSizeDefault); + + std::cout << "BIPOP-CMA-ES: restart " << restart << ", large population size (lambda): " + << cmaes.PopulationSize() << std::endl; + + iterate = iterateIn; + objective = cmaes.Optimize(function, iterate, sbc, callbacks...); + + evaluations = cmaes.FunctionEvaluations(); + largePopulationBudget += evaluations; + ++restart; + } + else { - if (largePopulationBudget <= smallPopulationBudget || i == 0 || i == maxRestarts - 1) - { - // Large population regime - currentLargeLambda *= 2; - cmaes.PopulationSize() = currentLargeLambda; - cmaes.StepSize() = 2.0; - - iterate = iterateIn; - cmaes.Optimize(function, iterate, sbc, callbacks...); - - size_t evaluations = cmaes.FunctionEvaluations(); - totalFunctionEvaluations += evaluations; - largePopulationBudget += evaluations; - } - else - { - // Small population regime - double u = dis(gen); - size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * currentLargeLambda / defaultLambda, u * u)); - cmaes.PopulationSize() = smallLambda; - cmaes.StepSize() = 2 * std::pow(10, -2*dis(gen)); - - iterate = iterateIn; - cmaes.Optimize(function, iterate, sbc, callbacks...); - - size_t evaluations = cmaes.FunctionEvaluations(); - totalFunctionEvaluations += evaluations; - smallPopulationBudget += evaluations; - } - - // Check if the total number of evaluations has exceeded the limit - if (totalFunctionEvaluations >= 1e9) { - break; - } + // Small population regime + double u = dis(gen); + size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * currentLargeLambda / defaultLambda, u * u)); + double stepSizeSmall = 2 * std::pow(10, -2*dis(gen)); + cmaes = CMAESType(smallLambda, cmaes.TransformationPolicy(), cmaes.BatchSize(), + cmaes.MaxIterations(), cmaes.Tolerance(), cmaes.SelectionPolicy(), stepSizeSmall); + + std::cout << "BIPOP-CMA-ES: restart " << restart << ", small population size (lambda): " + << cmaes.PopulationSize() << std::endl; + + iterate = iterateIn; + objective = cmaes.Optimize(function, iterate, sbc, callbacks...); + + evaluations = cmaes.FunctionEvaluations(); + smallPopulationBudget += evaluations; + } + + if (objective < overallObjective) + { + overallObjective = objective; + Info << "BIPOP-CMA-ES: New best objective: " << overallObjective << std::endl; + } + + totalFunctionEvaluations += evaluations; + // Check if the total number of evaluations has exceeded the limit + if (totalFunctionEvaluations >= maxFunctionEvaluations) { + Warn << "BIPOP-CMA-ES: Maximum function overall evaluations reached. " + << "terminating optimization." << std::endl; + + //iterate = transformationPolicy.Transform(iterate); + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = sbc.BestCoordinates(); + return sbc.BestObjective(); } + } - // Store the best coordinates - iterateIn = sbc.BestCoordinates(); - // Return the best objective - return sbc.BestObjective(); + //iterate = transformationPolicy.Transform(iterate); + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = sbc.BestCoordinates(); + return sbc.BestObjective(); } } // namespace ens diff --git a/include/ensmallen_bits/cmaes/ipop_cmaes.hpp b/include/ensmallen_bits/cmaes/ipop_cmaes.hpp index bc20ccf24..6f26f7cf4 100644 --- a/include/ensmallen_bits/cmaes/ipop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/ipop_cmaes.hpp @@ -69,7 +69,8 @@ class IPOPCMAES */ IPOPCMAES(const CMAESType& CMAES = CMAESType(), const double populationFactor = 2, - const size_t maxRestarts = 9); + const size_t maxRestarts = 9, + const size_t maxFunctionEvaluations = 1e9); /** * Construct the IPOP CMA-ES optimizer with the given function and parameters. @@ -103,7 +104,8 @@ IPOPCMAES(const size_t lambda = 0, selectionPolicy = typename CMAESType::selectionPolicyType(), double stepSize = 0, const double populationFactor = 2, - const size_t maxRestarts = 9); + const size_t maxRestarts = 9, + const size_t maxFunctionEvaluations = 1e9); /** * Optimize the given function using IPOP CMA-ES. The given starting point will be @@ -135,6 +137,11 @@ IPOPCMAES(const size_t lambda = 0, //! Modify the maximum number of restarts. size_t& MaxRestarts() { return maxRestarts; } + //! Get the maximum number of function evaluations. + size_t MaxFunctionEvaluations() const { return maxFunctionEvaluations; } + //! Modify the maximum number of function evaluations. + size_t& MaxFunctionEvaluations() { return maxFunctionEvaluations; } + //! Get the CMAES object. const CMAESType& CMAES() const { return cmaes; } //! Modify the CMAES object. @@ -147,6 +154,9 @@ IPOPCMAES(const size_t lambda = 0, //! Maximum number of restarts. size_t maxRestarts; + //! Maximum number of function evaluations. + size_t maxFunctionEvaluations; + //! The CMAES object used for optimization. CMAESType cmaes; }; @@ -156,4 +166,4 @@ IPOPCMAES(const size_t lambda = 0, // Include implementation. #include "ipop_cmaes_impl.hpp" -#endif +#endif \ No newline at end of file diff --git a/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp index 7ecddc92a..ff5f9b16a 100644 --- a/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp @@ -24,10 +24,12 @@ namespace ens { template IPOPCMAES::IPOPCMAES(const CMAESType& CMAES, const double populationFactor, - const size_t maxRestarts) : + const size_t maxRestarts, + const size_t maxFunctionEvaluations) : cmaes(CMAES), populationFactor(populationFactor), - maxRestarts(maxRestarts) + maxRestarts(maxRestarts), + maxFunctionEvaluations(maxFunctionEvaluations) { /* Nothing to do. */ } template @@ -39,10 +41,12 @@ IPOPCMAES::IPOPCMAES(const size_t lambda, const typename CMAESType::selectionPolicyType& selectionPolicy, double stepSize, const double populationFactor, - const size_t maxRestarts) : + const size_t maxRestarts, + const size_t maxFunctionEvaluations) : cmaes(lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), populationFactor(populationFactor), - maxRestarts(maxRestarts) + maxRestarts(maxRestarts), + maxFunctionEvaluations(maxFunctionEvaluations) { /* Nothing to do. */ } template @@ -52,32 +56,36 @@ typename MatType::elem_type IPOPCMAES::Optimize( MatType& iterateIn, CallbackTypes&&... callbacks) { - StoreBestCoordinates sbc; - size_t totalFunctionEvaluations = 0; - for (size_t i = 0; i < maxRestarts; ++i) - { - // Use the starting point. - MatType iterate = iterateIn; + StoreBestCoordinates sbc; + size_t totalFunctionEvaluations = 0; + MatType iterate = iterateIn; + for (size_t restart = 0; restart < maxRestarts; ++restart) + { + // Use the starting point. + iterate = iterateIn; - // Optimize using the CMAES object. - cmaes.Optimize(function, iterate, sbc, callbacks...); + // Optimize using the CMAES object. + cmaes.Optimize(function, iterate, sbc, callbacks...); - // Retrieve and accumulate the number of function evaluations used by CMAES. - totalFunctionEvaluations += cmaes.FunctionEvaluations(); + // Retrieve and accumulate the number of function evaluations used by CMAES. + totalFunctionEvaluations += cmaes.FunctionEvaluations(); - // Check if the total number of evaluations has exceeded the limit - if (totalFunctionEvaluations >= 1e9) { - break; - } + // Check if the total number of evaluations has exceeded the limit + if (totalFunctionEvaluations >= maxFunctionEvaluations) { + Warn << "BIPOP-CMA-ES: Maximum function overall evaluations reached. " + << "terminating optimization." << std::endl; - // Increase the population size by the population factor for next restart. - cmaes.PopulationSize() *= populationFactor; + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = sbc.BestCoordinates(); + return sbc.BestObjective(); } + // Increase the population size by the population factor for next restart. + cmaes.PopulationSize() *= populationFactor; + } - // Store the best coordinates. - iterateIn = sbc.BestCoordinates(); - // Return the best objective. - return sbc.BestObjective(); + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = sbc.BestCoordinates(); + return sbc.BestObjective(); } } // namespace ens From 762fab94c597eefc9cfb1e0b08b99fb30496d5eb Mon Sep 17 00:00:00 2001 From: beny Date: Sun, 28 Jul 2024 23:53:48 -0700 Subject: [PATCH 06/54] bipop update --- include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp index 30ba644ef..e5fff1b88 100644 --- a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp @@ -95,7 +95,7 @@ typename MatType::elem_type BIPOPCMAES::Optimize( cmaes = CMAESType(currentLargeLambda, cmaes.TransformationPolicy(), cmaes.BatchSize(), cmaes.MaxIterations(), cmaes.Tolerance(), cmaes.SelectionPolicy(), stepSizeDefault); - std::cout << "BIPOP-CMA-ES: restart " << restart << ", large population size (lambda): " + Info << "BIPOP-CMA-ES: restart " << restart << ", large population size (lambda): " << cmaes.PopulationSize() << std::endl; iterate = iterateIn; @@ -114,7 +114,7 @@ typename MatType::elem_type BIPOPCMAES::Optimize( cmaes = CMAESType(smallLambda, cmaes.TransformationPolicy(), cmaes.BatchSize(), cmaes.MaxIterations(), cmaes.Tolerance(), cmaes.SelectionPolicy(), stepSizeSmall); - std::cout << "BIPOP-CMA-ES: restart " << restart << ", small population size (lambda): " + Info << "BIPOP-CMA-ES: restart " << restart << ", small population size (lambda): " << cmaes.PopulationSize() << std::endl; iterate = iterateIn; From 2508bb145a0381a0a52478755a70fed9b00c2fa4 Mon Sep 17 00:00:00 2001 From: beny Date: Tue, 13 Aug 2024 07:24:19 +0200 Subject: [PATCH 07/54] Refactor IPOP and BIPOP to one --- include/ensmallen_bits/cmaes/pop_cmaes.hpp | 171 ++++++++++++++++++ .../ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 162 +++++++++++++++++ tests/CMakeLists.txt | 2 + tests/pop_cmaes_test.cpp | 103 +++++++++++ 4 files changed, 438 insertions(+) create mode 100644 include/ensmallen_bits/cmaes/pop_cmaes.hpp create mode 100644 include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp create mode 100644 tests/pop_cmaes_test.cpp diff --git a/include/ensmallen_bits/cmaes/pop_cmaes.hpp b/include/ensmallen_bits/cmaes/pop_cmaes.hpp new file mode 100644 index 000000000..27d85df62 --- /dev/null +++ b/include/ensmallen_bits/cmaes/pop_cmaes.hpp @@ -0,0 +1,171 @@ +/** + * @file ipop_cmaes_impl.hpp + * @author Marcus Edel + * @author Benjami Parellada + * + * Definition of the IPOP Covariance Matrix Adaptation Evolution Strategy + * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution + * Strategy With Increasing Population Size" and BIPOP Covariance Matrix + * Adaptation Evolution Strategy as proposed by N. Hansen in "Benchmarking + * a BI-population CMA-ES on the BBOB-2009 function testbed". + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef ENSMALLEN_CMAES_POP_CMAES_HPP +#define ENSMALLEN_CMAES_POP_CMAES_HPP + +#include "cmaes.hpp" + +namespace ens { + +/** + * Population-based CMA-ES (POP-CMA-ES) that can operate as either IPOP-CMA-ES + * or BIPOP-CMA-ES based on a flag. + * + * IPOP CMA-ES is a variant of the stochastic search algorithm + * CMA-ES - Covariance Matrix Adaptation Evolution Strategy. + * IPOP CMA-ES, also known as CMAES with increasing population size, + * incorporates a restart strategy that involves gradually increasing + * the population size. This approach is specifically designed to + * enhance the performance of CMA-ES on multi-modal functions. + * + * For more information, please refer to: + * + * @code + * @INPROCEEDINGS{1554902, + * author={Auger, A. and Hansen, N.}, + * booktitle={2005 IEEE Congress on Evolutionary Computation}, + * title={A restart CMA evolution strategy with increasing population size}, + * year={2005}, + * volume={2}, + * number={}, + * pages={1769-1776 Vol. 2}, + * doi={10.1109/CEC.2005.1554902}} + * @endcode + * + * IPOP CMA-ES can optimize separable functions. For more details, see the + * documentation on function types included with this distribution or on the + * ensmallen website. + * + * BI-Population CMA-ES is a variant of the stochastic search algorithm + * CMA-ES - Covariance Matrix Adaptation Evolution Strategy. + * It implements a dual restart strategy with varying population sizes: one + * increasing and one with smaller, varied sizes. This BI-population approach + * is designed to optimize performance on multi-modal function testbeds by + * leveraging different exploration and exploitation dynamics. + * + * For more information, please refer to: + * + * @code + * @inproceedings{hansen2009benchmarking, + * title={Benchmarking a BI-population CMA-ES on the BBOB-2009 function testbed}, + * author={Hansen, Nikolaus}, + * booktitle={Proceedings of the 11th annual conference companion on genetic and evolutionary computation conference: late breaking papers}, + * pages={2389--2396}, + * year={2009}} + * @endcode + * + * BI-Population CMA-ES can efficiently handle separable, multimodal, and weak + * structure functions across various dimensions, as demonstrated in the + * comprehensive results of the BBOB-2009 function testbed. The optimizer + * utilizes an interlaced multistart strategy to balance between broad + * exploration and intensive exploitation, adjusting population sizes and + * step-sizes dynamically. + */ +template> +class POPCMAES : public CMAES +{ + public: + /** + * Construct the POP-CMA-ES optimizer with the given parameters. + * Other than the same CMA-ES parameters, it also adds the maximum number of + * restarts, the increase in population factor, the maximum number of + * evaluations, as well as a flag indicating to use BIPOP or not. + * The suggested values are not necessarily good for the given problem, so it + * is suggested that the values used be tailored to the task at hand. The + * maximum number of iterations refers to the maximum number of points that + * are processed (i.e., one iteration equals one point; one iteration does not + * equal one pass over the dataset). + * + * @param lambda The initial population size (0 use the default size). + * @param transformationPolicy Instantiated transformation policy used to + * map the coordinates to the desired domain. + * @param batchSize Batch size to use for the objective calculation. + * @param maxIterations Maximum number of iterations allowed. + * @param tolerance Maximum absolute tolerance to terminate algorithm. + * @param selectionPolicy Instantiated selection policy used to calculate the + * objective. + * @param stepSize Starting sigma/step size (will be modified). + * @param populationFactor The factor by which population increases + * after each restart. + * @param maxRestarts Maximum number of restarts. + * @param maxFunctionEvaluations Maximum number of function evaluations. + * @param useBIPOP Flag that controls if the optimizer will run BIPOP or IPOP. + */ + POPCMAES(const size_t lambda = 0, + const TransformationPolicyType& transformationPolicy = + TransformationPolicyType(), + const size_t batchSize = 32, + const size_t maxIterations = 1000, + const double tolerance = 1e-5, + const SelectionPolicyType& selectionPolicy = SelectionPolicyType(), + double stepSize = 0, + const double populationFactor = 2, + const size_t maxRestarts = 9, + const size_t maxFunctionEvaluations = 1e9, + const bool useBIPOP = true); + + /** + * Set POP-CMA-ES specific parameters. + */ + template + typename MatType::elem_type Optimize(SeparableFunctionType& function, + MatType& iterate, + CallbackTypes&&... callbacks); + + //! Get the population factor. + double PopulationFactor() const { return populationFactor; } + //! Modify the population factor. + double& PopulationFactor() { return populationFactor; } + + //! Get the maximum number of restarts. + size_t MaxRestarts() const { return maxRestarts; } + //! Modify the maximum number of restarts. + size_t& MaxRestarts() { return maxRestarts; } + + //! Get the maximum number of function evaluations. + size_t MaxFunctionEvaluations() const { return maxFunctionEvaluations; } + //! Modify the maximum number of function evaluations. + size_t& MaxFunctionEvaluations() { return maxFunctionEvaluations; } + + //! Get the BIPOP mode flag. + bool UseBIPOP() const { return useBIPOP; } + //! Modify the BIPOP mode flag. + bool& UseBIPOP() { return useBIPOP; } + + private: + //! Population factor + double populationFactor; + + //! Maximum number of restarts. + size_t maxRestarts; + + //! Maximum number of function evaluations. + size_t maxFunctionEvaluations; + + //! Flag to switch between IPOP and BIPOP modes. + bool useBIPOP; +}; + +} // namespace ens + +// Include implementation. +#include "pop_cmaes_impl.hpp" + +#endif \ No newline at end of file diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp new file mode 100644 index 000000000..a44200800 --- /dev/null +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -0,0 +1,162 @@ +/** + * @file ipop_cmaes_impl.hpp + * @author Marcus Edel + * @author Benjami Parellada + * + * Implementation of the IPOP Covariance Matrix Adaptation Evolution Strategy + * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution + * Strategy With Increasing Population Size" and BIPOP Covariance Matrix + * Adaptation Evolution Strategy as proposed by N. Hansen in "Benchmarking + * a BI-population CMA-ES on the BBOB-2009 function testbed". + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef ENSMALLEN_CMAES_POP_CMAES_IMPL_HPP +#define ENSMALLEN_CMAES_POP_CMAES_IMPL_HPP + +#include "pop_cmaes.hpp" +#include +#include + +namespace ens { + +template +POPCMAES::POPCMAES( + const size_t lambda, + const TransformationPolicyType& transformationPolicy, + const size_t batchSize, + const size_t maxIterations, + const double tolerance, + const SelectionPolicyType& selectionPolicy, + double stepSize, + const double populationFactor, + const size_t maxRestarts, + const size_t maxFunctionEvaluations, + const bool useBIPOP) : + CMAES( + lambda, transformationPolicy, batchSize, maxIterations, + tolerance, selectionPolicy, stepSize), + populationFactor(populationFactor), + maxRestarts(maxRestarts), + maxFunctionEvaluations(maxFunctionEvaluations), + useBIPOP(useBIPOP) +{ /* Nothing to do. */ } + +template +template +typename MatType::elem_type POPCMAES::Optimize( + SeparableFunctionType& function, + MatType& iterateIn, + CallbackTypes&&... callbacks) +{ + // Convenience typedefs. + typedef typename MatType::elem_type ElemType; + + StoreBestCoordinates sbc; + StoreBestCoordinates overallSBC; + size_t totalFunctionEvaluations = 0; + size_t largePopulationBudget = 0; + size_t smallPopulationBudget = 0; + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> dis(0.0, 1.0); + + // First single run with default population size + MatType iterate = iterateIn; + ElemType overallObjective = CMAES::Optimize(function, iterate, sbc, + callbacks...); + ElemType objective; + size_t evaluations; + + size_t defaultLambda = this->PopulationSize(); + size_t currentLargeLambda = defaultLambda; + + double stepSizeDefault = this->StepSize(); + + // Print out the default population size + Info << "Default population size: " << defaultLambda << std::endl; + + size_t restart = 0; + + while (restart < maxRestarts) + { + if (!useBIPOP || largePopulationBudget <= smallPopulationBudget || restart == 0 || + restart == maxRestarts - 1) + { + // Large population regime (IPOP or BIPOP) + currentLargeLambda *= populationFactor; + this->PopulationSize() = currentLargeLambda; + this->StepSize() = stepSizeDefault; + + Info << "POP-CMA-ES: restart " << restart << ", large population size" << + " (lambda): " << this->PopulationSize() << std::endl; + + iterate = iterateIn; + + // Optimize using the CMAES object. + objective = CMAES::Optimize(function, iterate, sbc, + callbacks...); + + evaluations = this->FunctionEvaluations(); + largePopulationBudget += evaluations; + } + else if (useBIPOP) + { + // Small population regime (BIPOP only) + double u = dis(gen); + size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * + currentLargeLambda / defaultLambda, u * u)); + double stepSizeSmall = 2 * std::pow(10, -2*dis(gen)); + + this->PopulationSize() = smallLambda; + this->StepSize() = stepSizeSmall; + + Info << "BIPOP-CMA-ES: restart " << restart << ", small population" << + " size (lambda): " << this->PopulationSize() << std::endl; + + iterate = iterateIn; + + // Optimize using the CMAES object. + objective = CMAES::Optimize(function, iterate, sbc, + callbacks...); + + evaluations = this->FunctionEvaluations(); + smallPopulationBudget += evaluations; + } + + if (objective < overallObjective) + { + overallObjective = objective; + overallSBC = sbc; + Info << "POP-CMA-ES: New best objective: " << overallObjective << std::endl; + } + + totalFunctionEvaluations += evaluations; + // Check if the total number of evaluations has exceeded the limit + if (totalFunctionEvaluations >= maxFunctionEvaluations) { + Warn << "POP-CMA-ES: Maximum function overall evaluations reached. " + << "terminating optimization." << std::endl; + + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = overallSBC.BestCoordinates(); + return overallSBC.BestObjective(); + } + + ++restart; + } + + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = overallSBC.BestCoordinates(); + return overallSBC.BestObjective(); +} + +} // namespace ens + +#endif \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index df5938844..e3e6d5c77 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,7 @@ set(ENSMALLEN_TESTS_SOURCES adam_test.cpp aug_lagrangian_test.cpp bigbatch_sgd_test.cpp + bipop_cmaes_test.cpp callbacks_test.cpp cd_test.cpp cmaes_test.cpp @@ -34,6 +35,7 @@ set(ENSMALLEN_TESTS_SOURCES nesterov_momentum_sgd_test.cpp nsga2_test.cpp parallel_sgd_test.cpp + pop_cmaes_test.cpp proximal_test.cpp pso_test.cpp quasi_hyperbolic_momentum_sgd_test.cpp diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp new file mode 100644 index 000000000..b97fcfddd --- /dev/null +++ b/tests/pop_cmaes_test.cpp @@ -0,0 +1,103 @@ +#include +#include "catch.hpp" +#include "test_function_tools.hpp" +#include + +using namespace ens; +using namespace ens::test; + +TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") +{ + RastriginFunction f(2); + BoundaryBoxConstraint<> b(-10, 10); + + POPCMAES> ipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 3.72, // stepSize + 2.0, // populationFactor + 1, // maxRestarts + 1e4, // maxFunctionEvaluations + false // useBIPOP (false for IPOP) + ); + + + arma::mat initialPoint = f.GetInitialPoint(); + arma::mat expectedResult = f.GetFinalPoint(); + + // Test IPOP-CMA-ES with the Sphere function. + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); +} + +TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") +{ + RastriginFunction f(2); + BoundaryBoxConstraint<> b(-10, 10); + + POPCMAES> ipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 3.72, // stepSize + 2.0, // populationFactor + 1, // maxRestarts + 1e4, // maxFunctionEvaluations + true // useBIPOP (false for IPOP) + ); + + arma::mat initialPoint = f.GetInitialPoint(); + arma::mat expectedResult = f.GetFinalPoint(); + + // Test IPOP-CMA-ES with the Sphere function. + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); +} + + +TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") +{ + BoundaryBoxConstraint<> b(0, 2); + + POPCMAES> ipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 0.25, // stepSize + 1.5, // populationFactor + 1, // maxRestarts + 1e4, // maxFunctionEvaluations + false // useBIPOP (false for IPOP) + ); + + FunctionTest(ipopcmaes, 0.1, 0.1); +} + +TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") +{ + BoundaryBoxConstraint<> b(0, 2); + + POPCMAES> ipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 0.25, // stepSize + 1.5, // populationFactor + 1, // maxRestarts + 1e4, // maxFunctionEvaluations + true // useBIPOP (false for IPOP) + ); + + FunctionTest(ipopcmaes, 0.1, 0.1); +} \ No newline at end of file From aba89da4a36960df1cc74113728c654a4bfff33f Mon Sep 17 00:00:00 2001 From: beny Date: Tue, 13 Aug 2024 07:28:33 +0200 Subject: [PATCH 08/54] add POP in ensmallen.hpp --- include/ensmallen.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ensmallen.hpp b/include/ensmallen.hpp index 7d39da684..668fa1356 100644 --- a/include/ensmallen.hpp +++ b/include/ensmallen.hpp @@ -103,6 +103,7 @@ #include "ensmallen_bits/bigbatch_sgd/bigbatch_sgd.hpp" #include "ensmallen_bits/cmaes/cmaes.hpp" #include "ensmallen_bits/cmaes/active_cmaes.hpp" +#include "ensmallen_bits/cmaes/pop_cmaes.hpp" #include "ensmallen_bits/cmaes/ipop_cmaes.hpp" #include "ensmallen_bits/cmaes/bipop_cmaes.hpp" #include "ensmallen_bits/cd/cd.hpp" From 1103561c731524fdc0710f9a506c20f7f40ece35 Mon Sep 17 00:00:00 2001 From: beny Date: Tue, 13 Aug 2024 07:49:33 +0200 Subject: [PATCH 09/54] correct typo --- tests/pop_cmaes_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp index b97fcfddd..cb526dfce 100644 --- a/tests/pop_cmaes_test.cpp +++ b/tests/pop_cmaes_test.cpp @@ -29,7 +29,6 @@ TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") arma::mat initialPoint = f.GetInitialPoint(); arma::mat expectedResult = f.GetFinalPoint(); - // Test IPOP-CMA-ES with the Sphere function. MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); } @@ -55,7 +54,6 @@ TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") arma::mat initialPoint = f.GetInitialPoint(); arma::mat expectedResult = f.GetFinalPoint(); - // Test IPOP-CMA-ES with the Sphere function. MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); } From 33160772e98284ae27041e972bbe5039629fe48c Mon Sep 17 00:00:00 2001 From: beny Date: Sat, 17 Aug 2024 04:09:44 +0200 Subject: [PATCH 10/54] Documentation and useBIPOP parameter template --- doc/optimizers.md | 97 ++++++++++--------- include/ensmallen.hpp | 2 - include/ensmallen_bits/cmaes/pop_cmaes.hpp | 26 ++--- .../ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 28 +++--- tests/pop_cmaes_test.cpp | 32 +++--- 5 files changed, 95 insertions(+), 90 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 4269c0c1f..0dd992f1e 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -86,9 +86,9 @@ approxOptimizer.Optimize(f, coordinates); #### See also: - * [BIPOPCMAES](#bipopcmaes) + * [BIPOP_CMAES](#bipopcmaes) * [CMAES](#cmaes) - * [IPOPCMAES](#ipopcmaes) + * [IPOP_CMAES](#ipopcmaes) * [Improving Evolution Strategies through Active Covariance Matrix Adaptation](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.4239&rep=rep1&type=pdfn) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) @@ -780,7 +780,7 @@ optimizer2.Optimize(f, coordinates); * [SGD in Wikipedia](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) * [SGD](#standard-sgd) -## BIPOPCMAES +## BIPOP_CMAES *An optimizer for [separable functions](#separable-functions).* @@ -792,29 +792,33 @@ fitness landscape, and can outperform IPOP. The larger population restarts aim to explore broadly, improving global search capabilities, while the smaller populations intensify the search in promising regions. -#### Constructors - - * `BIPOPCMAES<`_`CMAESType`_`>()` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`CMAES`_`)` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`CMAES, maxRestarts`_`)` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy`_`)` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` - * `BIPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts`_`)` +### Constructors -The _`CMAESType`_ template parameter is the CMA-ES type used for the optimization. -Currently, either CMAES or ActiveCMAES can be used. +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>()` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor, maxFunctionEvaluations`_`)` -#### Attributes +### Attributes | **type** | **name** | **description** | **default** | |----------|----------|-----------------|-------------| -| `CMAESType` | **`cmaes`** | The CMAES object used for optimization. | `CMAESType()` | +| `size_t` | **`lambda`** | The population size (0 uses a default size). | `0` | +| `TransformationPolicyType` | **`transformationPolicy`** | Instantiated transformation policy used to map the coordinates to the desired domain. | `TransformationPolicyType()` | +| `size_t` | **`batchSize`** | Batch size to use for the objective calculation. | `32` | +| `size_t` | **`maxIterations`** | Maximum number of iterations. | `1000` | +| `double` | **`tolerance`** | Maximum absolute tolerance to terminate the algorithm. | `1e-5` | +| `SelectionPolicyType` | **`selectionPolicy`** | Instantiated selection policy used to calculate the objective. | `SelectionPolicyType()` | +| `double` | **`stepSize`** | Initial step size. | `0` | | `size_t` | **`maxRestarts`** | Maximum number of restarts. | `9` | +| `double` | **`populationFactor`** | The factor by which the population increases after each restart. | `2.0` | +| `size_t` | **`maxFunctionEvaluations`** | Maximum number of function evaluations. | `1e9` | -Attributes of the optimizer may also be changed via the member methods -`CMAES()`, `MaxRestarts()`. +The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters are used to control how the selection of points and the transformation of the decision variables are handled during the optimization process. For more information, check the [CMAES](#cmaes) class. The `lambda`, `transformationPolicy`, `batchSize`, `maxIterations`, `tolerance`, `selectionPolicy`, and `stepSize` are all parameters that affect the underlying CMAES process. #### Examples: @@ -828,8 +832,7 @@ arma::mat coordinates = f.GetInitialPoint(); // IPOP Active CMA-ES BoundaryBoxConstraint<> b(-1, 1); -CMAES cmaes(0, b, 32, 200, 1e-4); -BIPOPCMAES optimizer(cmaes, 5); +BIPOP_CMAES optimizer(0, b, 32, 200, 1e-4, 5, 2, 9, 1e4); Optimizer.Optimize(f, coordinates); ``` @@ -839,7 +842,7 @@ Optimizer.Optimize(f, coordinates); * [CMAES](#cmaes) * [ActiveCMAES](#activecmaes) - * [IPOP-CMAES](#ipopcmaes) + * [IPOP_CMAES](#ipopcmaes) * [Benchmarking a BI-Population CMA-ES on the BBOB-2009 Function Testbed](https://dl.acm.org/doi/pdf/10.1145/1570256.1570333) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) @@ -1004,8 +1007,8 @@ approxOptimizer.Optimize(f, coordinates); #### See also: * [ActiveCMAES](#activecmaes) - * [BIPOPCMAES](#bipopcmaes) - * [IPOPCMAES](#ipopcmaes) + * [BIPOP_CMAES](#bipopcmaes) + * [IPOP_CMAES](#ipopcmaes) * [Completely Derandomized Self-Adaptation in Evolution Strategies](http://www.cmap.polytechnique.fr/~nikolaus.hansen/cmaartic.pdf) * [CMA-ES in Wikipedia](https://en.wikipedia.org/wiki/CMA-ES) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) @@ -1552,7 +1555,7 @@ optimizer.Optimize(f, coordinates); * [HOGWILD!: A Lock-Free Approach to Parallelizing Stochastic Gradient Descent](https://arxiv.org/abs/1106.5730) * [Sparse differentiable separable functions](#sparse-differentiable-separable-functions) -## IPOPCMAES +## IPOP_CMAES *An optimizer for [separable functions](#separable-functions).* @@ -1564,32 +1567,33 @@ characterized by numerous local optima. The restart mechanism is designed to improve the adaptability of CMA-ES by improving the likelihood of escaping local optima, thus increasing the chances of discovering the global optimum. -#### Constructors - - * `IPOPCMAES<`_`CMAESType`_`>()` - * `IPOPCMAES<`_`CMAESType`_`>(`_`CMAES`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`CMAES, populationFactor`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`CMAES, populationFactor, maxRestarts`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, populationFactor`_`)` - * `IPOPCMAES<`_`CMAESType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, populationFactor, maxRestarts`_`)` +### Constructors -The _`CMAESType`_ template parameter is the CMA-ES type used for the optimization. -Currently, either CMAES or ActiveCMAES can be used. +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>()` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor, maxFunctionEvaluations`_`)` -#### Attributes +### Attributes | **type** | **name** | **description** | **default** | |----------|----------|-----------------|-------------| -| `CMAESType` | **`cmaes`** | The CMAES object used for optimization. | `CMAESType()` | -| `double` | **`populationFactor`** | The factor by which population increases after each restart. | `2` | +| `size_t` | **`lambda`** | The population size (0 uses a default size). | `0` | +| `TransformationPolicyType` | **`transformationPolicy`** | Instantiated transformation policy used to map the coordinates to the desired domain. | `TransformationPolicyType()` | +| `size_t` | **`batchSize`** | Batch size to use for the objective calculation. | `32` | +| `size_t` | **`maxIterations`** | Maximum number of iterations. | `1000` | +| `double` | **`tolerance`** | Maximum absolute tolerance to terminate the algorithm. | `1e-5` | +| `SelectionPolicyType` | **`selectionPolicy`** | Instantiated selection policy used to calculate the objective. | `SelectionPolicyType()` | +| `double` | **`stepSize`** | Initial step size. | `0` | | `size_t` | **`maxRestarts`** | Maximum number of restarts. | `9` | +| `double` | **`populationFactor`** | The factor by which the population increases after each restart. | `2.0` | +| `size_t` | **`maxFunctionEvaluations`** | Maximum number of function evaluations. | `1e9` | -Attributes of the optimizer may also be changed via the member methods -`CMAES()`, `MaxRestarts()`, `PopulationFactor()`. +The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters are used to control how the selection of points and the transformation of the decision variables are handled during the optimization process. For more information, check the [CMAES](#cmaes) class. The `lambda`, `transformationPolicy`, `batchSize`, `maxIterations`, `tolerance`, `selectionPolicy`, and `stepSize` are all parameters that affect the underlying CMAES process. #### Examples: @@ -1603,8 +1607,7 @@ arma::mat coordinates = f.GetInitialPoint(); // IPOP Active CMA-ES BoundaryBoxConstraint<> b(-1, 1); -CMAES cmaes(0, b, 32, 200, 1e-4); -IPOPCMAES optimizer(cmaes, 2, 5); +IPOP_CMAES optimizer(0, b, 32, 200, 1e-4, 5, 2, 9, 1e4); Optimizer.Optimize(f, coordinates); ``` @@ -1614,7 +1617,7 @@ Optimizer.Optimize(f, coordinates); * [CMAES](#cmaes) * [ActiveCMAES](#activecmaes) - * [BIPOPCMAES](#bipopcmaes) + * [BIPOP_CMAES](#bipopcmaes) * [A Restart CMA Evolution Strategy With Increasing Population Size](http://www.cmap.polytechnique.fr/~nikolaus.hansen/cec2005ipopcmaes.pdf) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) diff --git a/include/ensmallen.hpp b/include/ensmallen.hpp index 668fa1356..3839a115a 100644 --- a/include/ensmallen.hpp +++ b/include/ensmallen.hpp @@ -104,8 +104,6 @@ #include "ensmallen_bits/cmaes/cmaes.hpp" #include "ensmallen_bits/cmaes/active_cmaes.hpp" #include "ensmallen_bits/cmaes/pop_cmaes.hpp" -#include "ensmallen_bits/cmaes/ipop_cmaes.hpp" -#include "ensmallen_bits/cmaes/bipop_cmaes.hpp" #include "ensmallen_bits/cd/cd.hpp" #include "ensmallen_bits/cne/cne.hpp" #include "ensmallen_bits/de/de.hpp" diff --git a/include/ensmallen_bits/cmaes/pop_cmaes.hpp b/include/ensmallen_bits/cmaes/pop_cmaes.hpp index 27d85df62..5ee1aca29 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes.hpp @@ -76,8 +76,9 @@ namespace ens { * step-sizes dynamically. */ template> -class POPCMAES : public CMAES + typename TransformationPolicyType = EmptyTransformation<>, + bool UseBIPOPFlag = true> +class POP_CMAES : public CMAES { public: /** @@ -104,9 +105,8 @@ class POPCMAES : public CMAES * after each restart. * @param maxRestarts Maximum number of restarts. * @param maxFunctionEvaluations Maximum number of function evaluations. - * @param useBIPOP Flag that controls if the optimizer will run BIPOP or IPOP. */ - POPCMAES(const size_t lambda = 0, + POP_CMAES(const size_t lambda = 0, const TransformationPolicyType& transformationPolicy = TransformationPolicyType(), const size_t batchSize = 32, @@ -116,8 +116,7 @@ class POPCMAES : public CMAES double stepSize = 0, const double populationFactor = 2, const size_t maxRestarts = 9, - const size_t maxFunctionEvaluations = 1e9, - const bool useBIPOP = true); + const size_t maxFunctionEvaluations = 1e9); /** * Set POP-CMA-ES specific parameters. @@ -145,9 +144,7 @@ class POPCMAES : public CMAES size_t& MaxFunctionEvaluations() { return maxFunctionEvaluations; } //! Get the BIPOP mode flag. - bool UseBIPOP() const { return useBIPOP; } - //! Modify the BIPOP mode flag. - bool& UseBIPOP() { return useBIPOP; } + static constexpr bool UseBIPOP() { return UseBIPOPFlag; } private: //! Population factor @@ -159,10 +156,17 @@ class POPCMAES : public CMAES //! Maximum number of function evaluations. size_t maxFunctionEvaluations; - //! Flag to switch between IPOP and BIPOP modes. - bool useBIPOP; }; +// Define IPOP_CMAES and BIPOP_CMAES using the POP_CMAES template +template> +using IPOP_CMAES = POP_CMAES; + +template> +using BIPOP_CMAES = POP_CMAES; + } // namespace ens // Include implementation. diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index a44200800..bdedb16b4 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -23,8 +23,10 @@ namespace ens { -template -POPCMAES::POPCMAES( +template +POP_CMAES::POP_CMAES( const size_t lambda, const TransformationPolicyType& transformationPolicy, const size_t batchSize, @@ -34,20 +36,21 @@ POPCMAES::POPCMAES( double stepSize, const double populationFactor, const size_t maxRestarts, - const size_t maxFunctionEvaluations, - const bool useBIPOP) : + const size_t maxFunctionEvaluations) : CMAES( lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), populationFactor(populationFactor), maxRestarts(maxRestarts), - maxFunctionEvaluations(maxFunctionEvaluations), - useBIPOP(useBIPOP) + maxFunctionEvaluations(maxFunctionEvaluations) { /* Nothing to do. */ } -template +template template -typename MatType::elem_type POPCMAES::Optimize( +typename MatType::elem_type POP_CMAES::Optimize( SeparableFunctionType& function, MatType& iterateIn, CallbackTypes&&... callbacks) @@ -85,8 +88,8 @@ typename MatType::elem_type POPCMAESFunctionEvaluations(); largePopulationBudget += evaluations; } - else if (useBIPOP) + else if (UseBIPOPFlag) { // Small population regime (BIPOP only) double u = dis(gen); @@ -135,7 +138,8 @@ typename MatType::elem_type POPCMAES b(-10, 10); - POPCMAES> ipopcmaes( + IPOP_CMAES> ipopcmaes( 15, // lambda b, // transformationPolicy 32, // batchSize @@ -20,9 +20,8 @@ TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") FullSelection(), // selectionPolicy 3.72, // stepSize 2.0, // populationFactor - 1, // maxRestarts - 1e4, // maxFunctionEvaluations - false // useBIPOP (false for IPOP) + 5, // maxRestarts + 1e4 // maxFunctionEvaluations ); @@ -37,7 +36,7 @@ TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") RastriginFunction f(2); BoundaryBoxConstraint<> b(-10, 10); - POPCMAES> ipopcmaes( + IPOP_CMAES> ipopcmaes( 15, // lambda b, // transformationPolicy 32, // batchSize @@ -46,9 +45,8 @@ TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") FullSelection(), // selectionPolicy 3.72, // stepSize 2.0, // populationFactor - 1, // maxRestarts - 1e4, // maxFunctionEvaluations - true // useBIPOP (false for IPOP) + 5, // maxRestarts + 1e4 // maxFunctionEvaluations ); arma::mat initialPoint = f.GetInitialPoint(); @@ -62,7 +60,7 @@ TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") { BoundaryBoxConstraint<> b(0, 2); - POPCMAES> ipopcmaes( + BIPOP_CMAES> bipopcmaes( 15, // lambda b, // transformationPolicy 32, // batchSize @@ -71,19 +69,18 @@ TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") FullSelection(), // selectionPolicy 0.25, // stepSize 1.5, // populationFactor - 1, // maxRestarts - 1e4, // maxFunctionEvaluations - false // useBIPOP (false for IPOP) + 5, // maxRestarts + 1e4 // maxFunctionEvaluations ); - FunctionTest(ipopcmaes, 0.1, 0.1); + FunctionTest(bipopcmaes, 0.1, 0.1); } TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") { BoundaryBoxConstraint<> b(0, 2); - POPCMAES> ipopcmaes( + BIPOP_CMAES> bipopcmaes( 15, // lambda b, // transformationPolicy 32, // batchSize @@ -92,10 +89,9 @@ TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") FullSelection(), // selectionPolicy 0.25, // stepSize 1.5, // populationFactor - 1, // maxRestarts - 1e4, // maxFunctionEvaluations - true // useBIPOP (false for IPOP) + 5, // maxRestarts + 1e4 // maxFunctionEvaluations ); - FunctionTest(ipopcmaes, 0.1, 0.1); + FunctionTest(bipopcmaes, 0.1, 0.1); } \ No newline at end of file From 66d9f190044fd53a6b35866ec5d10ab0f3b930a1 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:13:03 +0200 Subject: [PATCH 11/54] Delete include/ensmallen_bits/cmaes/bipop_cmaes.hpp --- include/ensmallen_bits/cmaes/bipop_cmaes.hpp | 169 ------------------- 1 file changed, 169 deletions(-) delete mode 100644 include/ensmallen_bits/cmaes/bipop_cmaes.hpp diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes.hpp deleted file mode 100644 index 49398c5fb..000000000 --- a/include/ensmallen_bits/cmaes/bipop_cmaes.hpp +++ /dev/null @@ -1,169 +0,0 @@ -/** - * @file bipop_cmaes.hpp - * @author Marcus Edel - * @author Benjami Parellada - * - * Definition of the BIPOP Covariance Matrix Adaptation Evolution Strategy - * as proposed by N. Hansen in "Benchmarking a BI-population CMA-ES on the - * BBOB-2009 function testbed". - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef ENSMALLEN_CMAES_BIPOP_CMAES_HPP -#define ENSMALLEN_CMAES_BIPOP_CMAES_HPP - -#include "cmaes.hpp" - -namespace ens { - -/** - * BI-Population CMA-ES is a variant of the stochastic search algorithm - * CMA-ES - Covariance Matrix Adaptation Evolution Strategy. - * It implements a dual restart strategy with varying population sizes: one - * increasing and one with smaller, varied sizes. This BI-population approach - * is designed to optimize performance on multi-modal function testbeds by - * leveraging different exploration and exploitation dynamics. - * - * For more information, please refer to: - * - * @code - * @inproceedings{hansen2009benchmarking, - * title={Benchmarking a BI-population CMA-ES on the BBOB-2009 function testbed}, - * author={Hansen, Nikolaus}, - * booktitle={Proceedings of the 11th annual conference companion on genetic and evolutionary computation conference: late breaking papers}, - * pages={2389--2396}, - * year={2009}} - * @endcode - * - * BI-Population CMA-ES can efficiently handle separable, multimodal, and weak - * structure functions across various dimensions, as demonstrated in the - * comprehensive results of the BBOB-2009 function testbed. The optimizer - * utilizes an interlaced multistart strategy to balance between broad - * exploration and intensive exploitation, adjusting population sizes and - * step-sizes dynamically. - * - * @tparam CMAESType The type of CMA-ES used for optimization. Options include standard CMAES and variants like ActiveCMAES. - */ -template> -class BIPOPCMAES -{ - public: - /** - * Construct the BIPOP CMA-ES optimizer with the given CMAES object, - * and maximum number of restarts. The defaults - * here are not necessarily good for the given problem, so it is - * suggested that the values used be tailored to the task at hand. The - * maximum number of iterations refers to the maximum number of points that - * are processed (i.e., one iteration equals one point; one iteration does not - * equal one pass over the dataset). - * - * @param CMAES The CMAES object. - * @param populationFactor The factor by which population increases - * after each restart. - * @param maxRestarts Maximum number of restarts. - */ - BIPOPCMAES(const CMAESType& CMAES = CMAESType(), - const size_t maxRestarts = 9, - const size_t maxFunctionEvaluations = 1e9, - const size_t populationFactor = 2); - - /** - * Construct the BIPOP CMA-ES optimizer with the given function and parameters. - * The defaults here are not necessarily good for the given problem, so it - * is suggested that the values used be tailored to the task at hand. The - * maximum number of iterations refers to the maximum number of points that - * are processed (i.e., one iteration equals one point; one iteration does - * not equal one pass over the dataset). - * - * @param lambda The initial population size (0 use the default size). - * @param transformationPolicy Instantiated transformation policy used to - * map the coordinates to the desired domain. - * @param batchSize Batch size to use for the objective calculation. - * @param maxIterations Maximum number of iterations allowed(0 means no - limit). - * @param tolerance Maximum absolute tolerance to terminate algorithm. - * @param selectionPolicy Instantiated selection policy used to calculate the - * objective. - * @param stepSize Starting sigma/step size (will be modified). - * @param populationFactor The factor by which population increases - * after each restart. - * @param maxRestarts Maximum number of restarts. - * @param maxFunctionEvaluations Maximum number of function evaluations for all resets. - * - */ -BIPOPCMAES(const size_t lambda = 0, - const typename CMAESType::transformationPolicyType& - transformationPolicy = typename CMAESType::transformationPolicyType(), - const size_t batchSize = 32, - const size_t maxIterations = 1000, - const double tolerance = 1e-5, - const typename CMAESType::selectionPolicyType& - selectionPolicy = typename CMAESType::selectionPolicyType(), - double stepSize = 0, - const size_t maxRestarts = 9, - const size_t maxFunctionEvaluations = 1e9, - const size_t populationFactor = 2); - - /** - * Optimize the given function using BIPOP CMA-ES. The given starting point will be - * modified to store the finishing point of the algorithm, and the final - * objective value is returned. - * - * @tparam SeparableFunctionType Type of the function to be optimized. - * @tparam MatType Type of matrix to optimize. - * @tparam CallbackTypes Types of callback functions. - * @param function Function to optimize. - * @param iterate Starting point (will be modified). - * @param callbacks Callback functions. - * @return Objective value of the final point. - */ - template - typename MatType::elem_type Optimize(SeparableFunctionType& function, - MatType& iterate, - CallbackTypes&&... callbacks); - - //! Get the maximum number of restarts. - size_t MaxRestarts() const { return maxRestarts; } - //! Modify the maximum number of restarts. - size_t& MaxRestarts() { return maxRestarts; } - - //! Get the CMAES object. - const CMAESType& CMAES() const { return cmaes; } - //! Modify the CMAES object. - CMAESType& CMAES() { return cmaes; } - - //! Get the population factor. - double PopulationFactor() const { return populationFactor; } - //! Modify the population factor. - double& PopulationFactor() { return populationFactor; } - - //! Get the maximum number of function evaluations. - size_t MaxFunctionEvaluations() const { return maxFunctionEvaluations; } - //! Modify the maximum number of function evaluations. - size_t& MaxFunctionEvaluations() { return maxFunctionEvaluations; } - - private: - //! Maximum number of restarts. - size_t maxRestarts; - - //! Maximum number of function evaluations. - size_t maxFunctionEvaluations; - - //! Population factor - double populationFactor; - - //! The CMAES object used for optimization. - CMAESType cmaes; -}; - -} // namespace ens - -// Include implementation. -#include "bipop_cmaes_impl.hpp" - -#endif From 6d58cfd91d47cba67a7d8f5b4e23de82674fd2a6 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:13:43 +0200 Subject: [PATCH 12/54] Delete include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp --- .../ensmallen_bits/cmaes/bipop_cmaes_impl.hpp | 154 ------------------ 1 file changed, 154 deletions(-) delete mode 100644 include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp diff --git a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp deleted file mode 100644 index e5fff1b88..000000000 --- a/include/ensmallen_bits/cmaes/bipop_cmaes_impl.hpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * @file bipop_cmaes_impl.hpp - * @author Benjami Parellada - * - * Implementation of the BIPOP Covariance Matrix Adaptation Evolution Strategy - * as proposed by N. Hansen in "Benchmarking a BI-population CMA-ES on the - * BBOB-2009 function testbed". - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef ENSMALLEN_CMAES_BIPOP_CMAES_IMPL_HPP -#define ENSMALLEN_CMAES_BIPOP_CMAES_IMPL_HPP - -#include "bipop_cmaes.hpp" -#include -#include - -namespace ens { - -template -BIPOPCMAES::BIPOPCMAES(const CMAESType& CMAES, - const size_t maxRestarts, - const size_t maxFunctionEvaluations, - const size_t populationFactor) : - cmaes(CMAES), - maxRestarts(maxRestarts), - maxFunctionEvaluations(maxFunctionEvaluations), - populationFactor(populationFactor) -{ /* Nothing to do. */ } - -template -BIPOPCMAES::BIPOPCMAES(const size_t lambda, - const typename CMAESType::transformationPolicyType& transformationPolicy, - const size_t batchSize, - const size_t maxIterations, - const double tolerance, - const typename CMAESType::selectionPolicyType& selectionPolicy, - double stepSize, - const size_t maxRestarts, - const size_t maxFunctionEvaluations, - const size_t populationFactor) : - cmaes(lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), - maxRestarts(maxRestarts), - maxFunctionEvaluations(maxFunctionEvaluations), - populationFactor(populationFactor) -{ /* Nothing to do. */ } - -template -template -typename MatType::elem_type BIPOPCMAES::Optimize( - SeparableFunctionType& function, - MatType& iterateIn, - CallbackTypes&&... callbacks) -{ - // Convenience typedefs. - typedef typename MatType::elem_type ElemType; - typedef typename MatTypeTraits::BaseMatType BaseMatType; - - StoreBestCoordinates sbc; - size_t totalFunctionEvaluations = 0; - size_t largePopulationBudget = 0; - size_t smallPopulationBudget = 0; - - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> dis(0.0, 1.0); - - // First single run with default population size - MatType iterate = iterateIn; - ElemType overallObjective = cmaes.Optimize(function, iterate, sbc, callbacks...); - ElemType objective; - size_t evaluations; - - size_t defaultLambda = cmaes.PopulationSize(); - size_t currentLargeLambda = defaultLambda; - - double stepSizeDefault = cmaes.StepSize(); - - // Print out the default population size - Info << "Default population size: " << defaultLambda << std::endl; - - size_t restart = 0; - - while (restart < maxRestarts) - { - if (largePopulationBudget <= smallPopulationBudget || restart == 0 || restart == maxRestarts - 1) - { - // Large population regime - - currentLargeLambda *= populationFactor; - cmaes = CMAESType(currentLargeLambda, cmaes.TransformationPolicy(), cmaes.BatchSize(), - cmaes.MaxIterations(), cmaes.Tolerance(), cmaes.SelectionPolicy(), stepSizeDefault); - - Info << "BIPOP-CMA-ES: restart " << restart << ", large population size (lambda): " - << cmaes.PopulationSize() << std::endl; - - iterate = iterateIn; - objective = cmaes.Optimize(function, iterate, sbc, callbacks...); - - evaluations = cmaes.FunctionEvaluations(); - largePopulationBudget += evaluations; - ++restart; - } - else - { - // Small population regime - double u = dis(gen); - size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * currentLargeLambda / defaultLambda, u * u)); - double stepSizeSmall = 2 * std::pow(10, -2*dis(gen)); - cmaes = CMAESType(smallLambda, cmaes.TransformationPolicy(), cmaes.BatchSize(), - cmaes.MaxIterations(), cmaes.Tolerance(), cmaes.SelectionPolicy(), stepSizeSmall); - - Info << "BIPOP-CMA-ES: restart " << restart << ", small population size (lambda): " - << cmaes.PopulationSize() << std::endl; - - iterate = iterateIn; - objective = cmaes.Optimize(function, iterate, sbc, callbacks...); - - evaluations = cmaes.FunctionEvaluations(); - smallPopulationBudget += evaluations; - } - - if (objective < overallObjective) - { - overallObjective = objective; - Info << "BIPOP-CMA-ES: New best objective: " << overallObjective << std::endl; - } - - totalFunctionEvaluations += evaluations; - // Check if the total number of evaluations has exceeded the limit - if (totalFunctionEvaluations >= maxFunctionEvaluations) { - Warn << "BIPOP-CMA-ES: Maximum function overall evaluations reached. " - << "terminating optimization." << std::endl; - - //iterate = transformationPolicy.Transform(iterate); - Callback::EndOptimization(*this, function, iterate, callbacks...); - iterateIn = sbc.BestCoordinates(); - return sbc.BestObjective(); - } - } - - //iterate = transformationPolicy.Transform(iterate); - Callback::EndOptimization(*this, function, iterate, callbacks...); - iterateIn = sbc.BestCoordinates(); - return sbc.BestObjective(); -} - -} // namespace ens - -#endif From 2c14b7de3a68bb8c77069e76d5057d7009620c78 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:14:10 +0200 Subject: [PATCH 13/54] Delete include/ensmallen_bits/cmaes/ipop_cmaes.hpp --- include/ensmallen_bits/cmaes/ipop_cmaes.hpp | 169 -------------------- 1 file changed, 169 deletions(-) delete mode 100644 include/ensmallen_bits/cmaes/ipop_cmaes.hpp diff --git a/include/ensmallen_bits/cmaes/ipop_cmaes.hpp b/include/ensmallen_bits/cmaes/ipop_cmaes.hpp deleted file mode 100644 index 6f26f7cf4..000000000 --- a/include/ensmallen_bits/cmaes/ipop_cmaes.hpp +++ /dev/null @@ -1,169 +0,0 @@ -/** - * @file ipop_cmaes.hpp - * @author Marcus Edel - * @author Suvarsha Chennareddy - * @author Benjami Parellada - * - * Definition of the IPOP Covariance Matrix Adaptation Evolution Strategy - * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution - * Strategy With Increasing Population Size". - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef ENSMALLEN_CMAES_IPOP_CMAES_HPP -#define ENSMALLEN_CMAES_IPOP_CMAES_HPP - -#include "cmaes.hpp" - -namespace ens { - -/** - * IPOP CMA-ES is a variant of the stochastic search algorithm - * CMA-ES - Covariance Matrix Adaptation Evolution Strategy. - * IPOP CMA-ES, also known as CMAES with increasing population size, - * incorporates a restart strategy that involves gradually increasing - * the population size. This approach is specifically designed to - * enhance the performance of CMA-ES on multi-modal functions. - * - * For more information, please refer to: - * - * @code - * @INPROCEEDINGS{1554902, - * author={Auger, A. and Hansen, N.}, - * booktitle={2005 IEEE Congress on Evolutionary Computation}, - * title={A restart CMA evolution strategy with increasing population size}, - * year={2005}, - * volume={2}, - * number={}, - * pages={1769-1776 Vol. 2}, - * doi={10.1109/CEC.2005.1554902}} - * @endcode - * - * IPOP CMA-ES can optimize separable functions. For more details, see the - * documentation on function types included with this distribution or on the - * ensmallen website. - * - * @tparam CMAESType The CMA-ES type used for the optimization. Currently, - * either CMAES or ActiveCMAES can be used. - */ -template> -class IPOPCMAES -{ - public: - /** - * Construct the IPOP CMA-ES optimizer with the given CMAES object, - * population factor, and maximum number of restarts. The defaults - * here are not necessarily good for the given problem, so it is - * suggested that the values used be tailored to the task at hand. The - * maximum number of iterations refers to the maximum number of points that - * are processed (i.e., one iteration equals one point; one iteration does not - * equal one pass over the dataset). - * - * @param CMAES The CMAES object. - * @param populationFactor The factor by which population increases - * after each restart. - * @param maxRestarts Maximum number of restarts. - */ - IPOPCMAES(const CMAESType& CMAES = CMAESType(), - const double populationFactor = 2, - const size_t maxRestarts = 9, - const size_t maxFunctionEvaluations = 1e9); - - /** - * Construct the IPOP CMA-ES optimizer with the given function and parameters. - * The defaults here are not necessarily good for the given problem, so it - * is suggested that the values used be tailored to the task at hand. The - * maximum number of iterations refers to the maximum number of points that - * are processed (i.e., one iteration equals one point; one iteration does - * not equal one pass over the dataset). - * - * @param lambda The initial population size (0 use the default size). - * @param transformationPolicy Instantiated transformation policy used to - * map the coordinates to the desired domain. - * @param batchSize Batch size to use for the objective calculation. - * @param maxIterations Maximum number of iterations allowed(0 means no - limit). - * @param tolerance Maximum absolute tolerance to terminate algorithm. - * @param selectionPolicy Instantiated selection policy used to calculate the - * objective. - * @param stepSize Starting sigma/step size (will be modified). - * @param populationFactor The factor by which population increases - * after each restart. - * @param maxRestarts Maximum number of restarts. - */ -IPOPCMAES(const size_t lambda = 0, - const typename CMAESType::transformationPolicyType& - transformationPolicy = typename CMAESType::transformationPolicyType(), - const size_t batchSize = 32, - const size_t maxIterations = 1000, - const double tolerance = 1e-5, - const typename CMAESType::selectionPolicyType& - selectionPolicy = typename CMAESType::selectionPolicyType(), - double stepSize = 0, - const double populationFactor = 2, - const size_t maxRestarts = 9, - const size_t maxFunctionEvaluations = 1e9); - - /** - * Optimize the given function using IPOP CMA-ES. The given starting point will be - * modified to store the finishing point of the algorithm, and the final - * objective value is returned. - * - * @tparam SeparableFunctionType Type of the function to be optimized. - * @tparam MatType Type of matrix to optimize. - * @tparam CallbackTypes Types of callback functions. - * @param function Function to optimize. - * @param iterate Starting point (will be modified). - * @param callbacks Callback functions. - * @return Objective value of the final point. - */ - template - typename MatType::elem_type Optimize(SeparableFunctionType& function, - MatType& iterate, - CallbackTypes&&... callbacks); - - //! Get the population factor. - double PopulationFactor() const { return populationFactor; } - //! Modify the population factor. - double& PopulationFactor() { return populationFactor; } - - //! Get the maximum number of restarts. - size_t MaxRestarts() const { return maxRestarts; } - //! Modify the maximum number of restarts. - size_t& MaxRestarts() { return maxRestarts; } - - //! Get the maximum number of function evaluations. - size_t MaxFunctionEvaluations() const { return maxFunctionEvaluations; } - //! Modify the maximum number of function evaluations. - size_t& MaxFunctionEvaluations() { return maxFunctionEvaluations; } - - //! Get the CMAES object. - const CMAESType& CMAES() const { return cmaes; } - //! Modify the CMAES object. - CMAESType& CMAES() { return cmaes; } - - private: - //! Population factor. - double populationFactor; - - //! Maximum number of restarts. - size_t maxRestarts; - - //! Maximum number of function evaluations. - size_t maxFunctionEvaluations; - - //! The CMAES object used for optimization. - CMAESType cmaes; -}; - -} // namespace ens - -// Include implementation. -#include "ipop_cmaes_impl.hpp" - -#endif \ No newline at end of file From 541c6be986099b0b1431ab4653f741f82a1a1c9b Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:14:38 +0200 Subject: [PATCH 14/54] Delete include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp --- .../ensmallen_bits/cmaes/ipop_cmaes_impl.hpp | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp diff --git a/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp deleted file mode 100644 index ff5f9b16a..000000000 --- a/include/ensmallen_bits/cmaes/ipop_cmaes_impl.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/** - * @file ipop_cmaes_impl.hpp - * @author Marcus Edel - * @author Suvarsha Chennareddy - * @author Benjami Parellada - * - * Implementation of the IPOP Covariance Matrix Adaptation Evolution Strategy - * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution - * Strategy With Increasing Population Size". - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef ENSMALLEN_CMAES_IPOP_CMAES_IMPL_HPP -#define ENSMALLEN_CMAES_IPOP_CMAES_IMPL_HPP - -#include "ipop_cmaes.hpp" -#include - -namespace ens { - -template -IPOPCMAES::IPOPCMAES(const CMAESType& CMAES, - const double populationFactor, - const size_t maxRestarts, - const size_t maxFunctionEvaluations) : - cmaes(CMAES), - populationFactor(populationFactor), - maxRestarts(maxRestarts), - maxFunctionEvaluations(maxFunctionEvaluations) -{ /* Nothing to do. */ } - -template -IPOPCMAES::IPOPCMAES(const size_t lambda, - const typename CMAESType::transformationPolicyType& transformationPolicy, - const size_t batchSize, - const size_t maxIterations, - const double tolerance, - const typename CMAESType::selectionPolicyType& selectionPolicy, - double stepSize, - const double populationFactor, - const size_t maxRestarts, - const size_t maxFunctionEvaluations) : - cmaes(lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize), - populationFactor(populationFactor), - maxRestarts(maxRestarts), - maxFunctionEvaluations(maxFunctionEvaluations) -{ /* Nothing to do. */ } - -template -template -typename MatType::elem_type IPOPCMAES::Optimize( - SeparableFunctionType& function, - MatType& iterateIn, - CallbackTypes&&... callbacks) -{ - StoreBestCoordinates sbc; - size_t totalFunctionEvaluations = 0; - MatType iterate = iterateIn; - for (size_t restart = 0; restart < maxRestarts; ++restart) - { - // Use the starting point. - iterate = iterateIn; - - // Optimize using the CMAES object. - cmaes.Optimize(function, iterate, sbc, callbacks...); - - // Retrieve and accumulate the number of function evaluations used by CMAES. - totalFunctionEvaluations += cmaes.FunctionEvaluations(); - - // Check if the total number of evaluations has exceeded the limit - if (totalFunctionEvaluations >= maxFunctionEvaluations) { - Warn << "BIPOP-CMA-ES: Maximum function overall evaluations reached. " - << "terminating optimization." << std::endl; - - Callback::EndOptimization(*this, function, iterate, callbacks...); - iterateIn = sbc.BestCoordinates(); - return sbc.BestObjective(); - } - // Increase the population size by the population factor for next restart. - cmaes.PopulationSize() *= populationFactor; - } - - Callback::EndOptimization(*this, function, iterate, callbacks...); - iterateIn = sbc.BestCoordinates(); - return sbc.BestObjective(); -} - -} // namespace ens - -#endif From 1d2dd1ed039290fb3e8352346b38f47f2e2c9121 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:15:15 +0200 Subject: [PATCH 15/54] Delete tests/bipop_cmaes_test.cpp --- tests/bipop_cmaes_test.cpp | 49 -------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 tests/bipop_cmaes_test.cpp diff --git a/tests/bipop_cmaes_test.cpp b/tests/bipop_cmaes_test.cpp deleted file mode 100644 index 77b761719..000000000 --- a/tests/bipop_cmaes_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file bipop_cmaes_test.cpp - * @author Benjami Parellada - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#include -#include "catch.hpp" -#include "test_function_tools.hpp" - -using namespace ens; -using namespace ens::test; - -/** - * Run BIPOP CMA-ES with the full selection policy on Rastrigin function and - * make sure the results are acceptable. - */ -TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") -{ - const size_t numFunctions = 2; - BoundaryBoxConstraint<> b(-5.12, 5.12); - CMAES> cmaes(10, b, numFunctions, 0, 1e-5); - cmaes.StepSize() = 3.72; - BIPOPCMAES>> bipopcmaes(cmaes, 10); - - RastriginFunction f(numFunctions); - arma::mat initialPoint = f.template GetInitialPoint(); - arma::mat expectedResult = f.template GetFinalPoint(); - - MultipleTrialOptimizerTest(f, bipopcmaes, initialPoint, expectedResult, - 0.01, f.GetFinalObjective(), 0.1, 5); -} - -/** - * Run BIPOP CMA-ES with the full selection policy on Rosenbrock function and - * make sure the results are acceptable. - */ -TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[BIPOPCMAESTest]") -{ - BoundaryBoxConstraint<> b(0, 2); - BIPOPCMAES>> bipopcmaes(0, b, 16, 0, 1e-3); - bipopcmaes.CMAES().StepSize() = 0.25; - - FunctionTest(bipopcmaes, 0.1, 0.1); -} From 4622470d8a9ea876844ba1a6f1c3fc7ecfea5fc1 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:15:51 +0200 Subject: [PATCH 16/54] Delete tests/ipop_cmaes_test.cpp --- tests/ipop_cmaes_test.cpp | 56 --------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 tests/ipop_cmaes_test.cpp diff --git a/tests/ipop_cmaes_test.cpp b/tests/ipop_cmaes_test.cpp deleted file mode 100644 index e9e06a060..000000000 --- a/tests/ipop_cmaes_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file ipop_cmaes_test.cpp - * @author Suvarsha Chennareddy - * @author Benjami Parellada - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#include -#include "catch.hpp" -#include "test_function_tools.hpp" - -using namespace ens; -using namespace ens::test; - -/** - * Run IPOP CMA-ES with the full selection policy on Rastrigin function and - * make sure the results are acceptable. - */ -TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") -{ - const size_t numFunctions = 2; - - BoundaryBoxConstraint<> b(-5.12, 5.12); - CMAES> cmaes(10, b, numFunctions, 0, 1e-5); - cmaes.StepSize() = 3.72; - - IPOPCMAES>> - ipopcmaes(cmaes, 2, 10); - - RastriginFunction f(numFunctions); - arma::mat initialPoint = f.template GetInitialPoint(); - arma::mat expectedResult = f.template GetFinalPoint(); - - MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, - 0.01, f.GetFinalObjective(), 0.1, 5); -} - -/** - * Run IPOP CMA-ES with the full selection policy on Rosenbrock function and - * make sure the results are acceptable. - */ -TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") -{ - BoundaryBoxConstraint<> b(0, 2); - - IPOPCMAES>> - ipopcmaes(0, b, 16, 0, 1e-3); - ipopcmaes.CMAES().StepSize() = 0.25; - ipopcmaes.PopulationFactor() = 1.5; - - FunctionTest(ipopcmaes, 0.1, 0.1); -} \ No newline at end of file From 6d369f3b2d01003dc653bcfdc6f27bd4b3c2ee93 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 04:16:44 +0200 Subject: [PATCH 17/54] Update CMakeLists.txt --- tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e3e6d5c77..c0e0a7d0a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,6 @@ set(ENSMALLEN_TESTS_SOURCES adam_test.cpp aug_lagrangian_test.cpp bigbatch_sgd_test.cpp - bipop_cmaes_test.cpp callbacks_test.cpp cd_test.cpp cmaes_test.cpp From 3dfe37327e232af3156ae46a588511fbbed8e491 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 07:17:01 +0200 Subject: [PATCH 18/54] add more tests for pop-cma-es --- tests/pop_cmaes_test.cpp | 50 ++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp index a970f5e08..7d2bd9c7f 100644 --- a/tests/pop_cmaes_test.cpp +++ b/tests/pop_cmaes_test.cpp @@ -6,7 +6,11 @@ using namespace ens; using namespace ens::test; -TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") +/** + * Run IPOP-CMA-ES on the Rastrigin function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("IPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") { RastriginFunction f(2); BoundaryBoxConstraint<> b(-10, 10); @@ -24,14 +28,17 @@ TEST_CASE("IPOPCMAESRastriginFunctionTest", "[IPOPCMAESTest]") 1e4 // maxFunctionEvaluations ); - arma::mat initialPoint = f.GetInitialPoint(); arma::mat expectedResult = f.GetFinalPoint(); MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); } -TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") +/** + * Run BIPOP-CMA-ES on the Rastrigin function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") { RastriginFunction f(2); BoundaryBoxConstraint<> b(-10, 10); @@ -55,8 +62,11 @@ TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[BIPOPCMAESTest]") MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); } - -TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") +/** + * Run IPOP-CMA-ES on the Rosenbrock function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") { BoundaryBoxConstraint<> b(0, 2); @@ -76,7 +86,11 @@ TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") FunctionTest(bipopcmaes, 0.1, 0.1); } -TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") +/** + * Run BIPOP-CMA-ES on the Rosenbrock function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") { BoundaryBoxConstraint<> b(0, 2); @@ -94,4 +108,26 @@ TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[IPOPCMAESTest]") ); FunctionTest(bipopcmaes, 0.1, 0.1); -} \ No newline at end of file +} + +/** + * Run IPOP-CMA-ES with the full selection policy on logistic regression and + * make sure the results are acceptable. + */ +TEST_CASE("IPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") +{ + BoundaryBoxConstraint<> b(-10, 10); + IPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); + LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); +} + +/** + * Run BIPOP-CMA-ES with the random selection policy on logistic regression and + * make sure the results are acceptable. + */ +TEST_CASE("BIPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") +{ + BoundaryBoxConstraint<> b(-10, 10); + BIPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); + LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); +} From 16b0be12dde945e287ae8e498f635e4030d5090c Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 07:18:23 +0200 Subject: [PATCH 19/54] fixed bug in pop-cma-es --- tests/pop_cmaes_test.cpp | 290 ++++++++++++++++++++++----------------- 1 file changed, 163 insertions(+), 127 deletions(-) diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp index 7d2bd9c7f..025b163fd 100644 --- a/tests/pop_cmaes_test.cpp +++ b/tests/pop_cmaes_test.cpp @@ -1,133 +1,169 @@ -#include -#include "catch.hpp" -#include "test_function_tools.hpp" -#include - -using namespace ens; -using namespace ens::test; - /** - * Run IPOP-CMA-ES on the Rastrigin function and check whether the optimizer - * converges to the expected solution within tolerance limits. + * @file ipop_cmaes_impl.hpp + * @author Marcus Edel + * @author Benjami Parellada + * + * Implementation of the IPOP Covariance Matrix Adaptation Evolution Strategy + * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution + * Strategy With Increasing Population Size" and BIPOP Covariance Matrix + * Adaptation Evolution Strategy as proposed by N. Hansen in "Benchmarking + * a BI-population CMA-ES on the BBOB-2009 function testbed". + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ -TEST_CASE("IPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") +#ifndef ENSMALLEN_CMAES_POP_CMAES_IMPL_HPP +#define ENSMALLEN_CMAES_POP_CMAES_IMPL_HPP + +#include "pop_cmaes.hpp" +#include +#include + +namespace ens { + +template +POP_CMAES::POP_CMAES( + const size_t lambda, + const TransformationPolicyType& transformationPolicy, + const size_t batchSize, + const size_t maxIterations, + const double tolerance, + const SelectionPolicyType& selectionPolicy, + double stepSize, + const double populationFactor, + const size_t maxRestarts, + const size_t maxFunctionEvaluations) : + CMAES( + lambda, transformationPolicy, batchSize, maxIterations, + tolerance, selectionPolicy, stepSize), + populationFactor(populationFactor), + maxRestarts(maxRestarts), + maxFunctionEvaluations(maxFunctionEvaluations) +{ /* Nothing to do. */ } + +template +template +typename MatType::elem_type POP_CMAES::Optimize( + SeparableFunctionType& function, + MatType& iterateIn, + CallbackTypes&&... callbacks) { - RastriginFunction f(2); - BoundaryBoxConstraint<> b(-10, 10); - - IPOP_CMAES> ipopcmaes( - 15, // lambda - b, // transformationPolicy - 32, // batchSize - 1000, // maxIterations - 1e-8, // tolerance - FullSelection(), // selectionPolicy - 3.72, // stepSize - 2.0, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations - ); - - arma::mat initialPoint = f.GetInitialPoint(); - arma::mat expectedResult = f.GetFinalPoint(); - - MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); + // Convenience typedefs. + typedef typename MatType::elem_type ElemType; + + StoreBestCoordinates sbc; + StoreBestCoordinates overallSBC; + size_t totalFunctionEvaluations = 0; + size_t largePopulationBudget = 0; + size_t smallPopulationBudget = 0; + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> dis(0.0, 1.0); + + // First single run with default population size + MatType iterate = iterateIn; + ElemType overallObjective = CMAES::Optimize(function, iterate, sbc, + callbacks...); + + overallSBC = sbc; + ElemType objective; + size_t evaluations; + + size_t defaultLambda = this->PopulationSize(); + size_t currentLargeLambda = defaultLambda; + + double stepSizeDefault = this->StepSize(); + + Info << "POP-CMA-ES: default population size (lambda): " << defaultLambda + << ", default step size (sigma): " << stepSizeDefault << std::endl; + + size_t restart = 0; + + while (restart < maxRestarts) + { + if (!UseBIPOPFlag || largePopulationBudget <= smallPopulationBudget || + restart == 0 || restart == maxRestarts - 1) + { + // Large population regime (IPOP or BIPOP) + currentLargeLambda *= populationFactor; + this->PopulationSize() = currentLargeLambda; + this->StepSize() = stepSizeDefault; + + Info << "POP-CMA-ES: restart " << restart << ", large population size" << + " (lambda): " << this->PopulationSize() << std::endl; + + iterate = iterateIn; + + // Optimize using the CMAES object. + objective = CMAES::Optimize(function, iterate, sbc, + callbacks...); + + evaluations = this->FunctionEvaluations(); + largePopulationBudget += evaluations; + } + else if (UseBIPOPFlag) + { + // Small population regime (BIPOP only) + double u = dis(gen); + size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * + currentLargeLambda / defaultLambda, u * u)); + double stepSizeSmall = 2 * std::pow(10, -2*dis(gen)); + + this->PopulationSize() = smallLambda; + this->StepSize() = stepSizeSmall; + + Info << "POP-CMA-ES: restart " << restart << ", small population size" + << " (lambda): " << this->PopulationSize() << ", small step size" + << " (sigma): " << this->StepSize() << std::endl; + + iterate = iterateIn; + + // Optimize using the CMAES object. + objective = CMAES::Optimize(function, iterate, sbc, + callbacks...); + + evaluations = this->FunctionEvaluations(); + smallPopulationBudget += evaluations; + } + + if (objective < overallObjective) + { + overallObjective = objective; + overallSBC = sbc; + Info << "POP-CMA-ES: New best objective: " << overallObjective << + std::endl; + } + + totalFunctionEvaluations += evaluations; + // Check if the total number of evaluations has exceeded the limit + if (totalFunctionEvaluations >= maxFunctionEvaluations) { + Warn << "POP-CMA-ES: Maximum function overall evaluations reached. " + << "terminating optimization." << std::endl; + + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = overallSBC.BestCoordinates(); + return overallSBC.BestObjective(); + } + + ++restart; + } + + Callback::EndOptimization(*this, function, iterate, callbacks...); + iterateIn = overallSBC.BestCoordinates(); + return overallSBC.BestObjective(); } -/** - * Run BIPOP-CMA-ES on the Rastrigin function and check whether the optimizer - * converges to the expected solution within tolerance limits. - */ -TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") -{ - RastriginFunction f(2); - BoundaryBoxConstraint<> b(-10, 10); - - IPOP_CMAES> ipopcmaes( - 15, // lambda - b, // transformationPolicy - 32, // batchSize - 1000, // maxIterations - 1e-8, // tolerance - FullSelection(), // selectionPolicy - 3.72, // stepSize - 2.0, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations - ); - - arma::mat initialPoint = f.GetInitialPoint(); - arma::mat expectedResult = f.GetFinalPoint(); - - MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); -} +} // namespace ens -/** - * Run IPOP-CMA-ES on the Rosenbrock function and check whether the optimizer - * converges to the expected solution within tolerance limits. - */ -TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") -{ - BoundaryBoxConstraint<> b(0, 2); - - BIPOP_CMAES> bipopcmaes( - 15, // lambda - b, // transformationPolicy - 32, // batchSize - 1000, // maxIterations - 1e-8, // tolerance - FullSelection(), // selectionPolicy - 0.25, // stepSize - 1.5, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations - ); - - FunctionTest(bipopcmaes, 0.1, 0.1); -} - -/** - * Run BIPOP-CMA-ES on the Rosenbrock function and check whether the optimizer - * converges to the expected solution within tolerance limits. - */ -TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") -{ - BoundaryBoxConstraint<> b(0, 2); - - BIPOP_CMAES> bipopcmaes( - 15, // lambda - b, // transformationPolicy - 32, // batchSize - 1000, // maxIterations - 1e-8, // tolerance - FullSelection(), // selectionPolicy - 0.25, // stepSize - 1.5, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations - ); - - FunctionTest(bipopcmaes, 0.1, 0.1); -} - -/** - * Run IPOP-CMA-ES with the full selection policy on logistic regression and - * make sure the results are acceptable. - */ -TEST_CASE("IPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") -{ - BoundaryBoxConstraint<> b(-10, 10); - IPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); - LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); -} - -/** - * Run BIPOP-CMA-ES with the random selection policy on logistic regression and - * make sure the results are acceptable. - */ -TEST_CASE("BIPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") -{ - BoundaryBoxConstraint<> b(-10, 10); - BIPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); - LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); -} +#endif From a6fd0ff5479f68343c79bb8292bc46b9493fcaef Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Sat, 17 Aug 2024 07:41:48 +0200 Subject: [PATCH 20/54] Update test for pop-cma-es --- tests/pop_cmaes_test.cpp | 290 +++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 163 deletions(-) diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp index 025b163fd..7d2bd9c7f 100644 --- a/tests/pop_cmaes_test.cpp +++ b/tests/pop_cmaes_test.cpp @@ -1,169 +1,133 @@ +#include +#include "catch.hpp" +#include "test_function_tools.hpp" +#include + +using namespace ens; +using namespace ens::test; + /** - * @file ipop_cmaes_impl.hpp - * @author Marcus Edel - * @author Benjami Parellada - * - * Implementation of the IPOP Covariance Matrix Adaptation Evolution Strategy - * as proposed by A. Auger and N. Hansen in "A Restart CMA Evolution - * Strategy With Increasing Population Size" and BIPOP Covariance Matrix - * Adaptation Evolution Strategy as proposed by N. Hansen in "Benchmarking - * a BI-population CMA-ES on the BBOB-2009 function testbed". - * - * ensmallen is free software; you may redistribute it and/or modify it under - * the terms of the 3-clause BSD license. You should have received a copy of - * the 3-clause BSD license along with ensmallen. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. + * Run IPOP-CMA-ES on the Rastrigin function and check whether the optimizer + * converges to the expected solution within tolerance limits. */ -#ifndef ENSMALLEN_CMAES_POP_CMAES_IMPL_HPP -#define ENSMALLEN_CMAES_POP_CMAES_IMPL_HPP - -#include "pop_cmaes.hpp" -#include -#include - -namespace ens { - -template -POP_CMAES::POP_CMAES( - const size_t lambda, - const TransformationPolicyType& transformationPolicy, - const size_t batchSize, - const size_t maxIterations, - const double tolerance, - const SelectionPolicyType& selectionPolicy, - double stepSize, - const double populationFactor, - const size_t maxRestarts, - const size_t maxFunctionEvaluations) : - CMAES( - lambda, transformationPolicy, batchSize, maxIterations, - tolerance, selectionPolicy, stepSize), - populationFactor(populationFactor), - maxRestarts(maxRestarts), - maxFunctionEvaluations(maxFunctionEvaluations) -{ /* Nothing to do. */ } - -template -template -typename MatType::elem_type POP_CMAES::Optimize( - SeparableFunctionType& function, - MatType& iterateIn, - CallbackTypes&&... callbacks) +TEST_CASE("IPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") { - // Convenience typedefs. - typedef typename MatType::elem_type ElemType; - - StoreBestCoordinates sbc; - StoreBestCoordinates overallSBC; - size_t totalFunctionEvaluations = 0; - size_t largePopulationBudget = 0; - size_t smallPopulationBudget = 0; - - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> dis(0.0, 1.0); - - // First single run with default population size - MatType iterate = iterateIn; - ElemType overallObjective = CMAES::Optimize(function, iterate, sbc, - callbacks...); - - overallSBC = sbc; - ElemType objective; - size_t evaluations; - - size_t defaultLambda = this->PopulationSize(); - size_t currentLargeLambda = defaultLambda; - - double stepSizeDefault = this->StepSize(); - - Info << "POP-CMA-ES: default population size (lambda): " << defaultLambda - << ", default step size (sigma): " << stepSizeDefault << std::endl; - - size_t restart = 0; - - while (restart < maxRestarts) - { - if (!UseBIPOPFlag || largePopulationBudget <= smallPopulationBudget || - restart == 0 || restart == maxRestarts - 1) - { - // Large population regime (IPOP or BIPOP) - currentLargeLambda *= populationFactor; - this->PopulationSize() = currentLargeLambda; - this->StepSize() = stepSizeDefault; - - Info << "POP-CMA-ES: restart " << restart << ", large population size" << - " (lambda): " << this->PopulationSize() << std::endl; - - iterate = iterateIn; - - // Optimize using the CMAES object. - objective = CMAES::Optimize(function, iterate, sbc, - callbacks...); - - evaluations = this->FunctionEvaluations(); - largePopulationBudget += evaluations; - } - else if (UseBIPOPFlag) - { - // Small population regime (BIPOP only) - double u = dis(gen); - size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * - currentLargeLambda / defaultLambda, u * u)); - double stepSizeSmall = 2 * std::pow(10, -2*dis(gen)); - - this->PopulationSize() = smallLambda; - this->StepSize() = stepSizeSmall; - - Info << "POP-CMA-ES: restart " << restart << ", small population size" - << " (lambda): " << this->PopulationSize() << ", small step size" - << " (sigma): " << this->StepSize() << std::endl; - - iterate = iterateIn; - - // Optimize using the CMAES object. - objective = CMAES::Optimize(function, iterate, sbc, - callbacks...); - - evaluations = this->FunctionEvaluations(); - smallPopulationBudget += evaluations; - } - - if (objective < overallObjective) - { - overallObjective = objective; - overallSBC = sbc; - Info << "POP-CMA-ES: New best objective: " << overallObjective << - std::endl; - } - - totalFunctionEvaluations += evaluations; - // Check if the total number of evaluations has exceeded the limit - if (totalFunctionEvaluations >= maxFunctionEvaluations) { - Warn << "POP-CMA-ES: Maximum function overall evaluations reached. " - << "terminating optimization." << std::endl; - - Callback::EndOptimization(*this, function, iterate, callbacks...); - iterateIn = overallSBC.BestCoordinates(); - return overallSBC.BestObjective(); - } - - ++restart; - } - - Callback::EndOptimization(*this, function, iterate, callbacks...); - iterateIn = overallSBC.BestCoordinates(); - return overallSBC.BestObjective(); + RastriginFunction f(2); + BoundaryBoxConstraint<> b(-10, 10); + + IPOP_CMAES> ipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 3.72, // stepSize + 2.0, // populationFactor + 5, // maxRestarts + 1e4 // maxFunctionEvaluations + ); + + arma::mat initialPoint = f.GetInitialPoint(); + arma::mat expectedResult = f.GetFinalPoint(); + + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); } -} // namespace ens +/** + * Run BIPOP-CMA-ES on the Rastrigin function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") +{ + RastriginFunction f(2); + BoundaryBoxConstraint<> b(-10, 10); + + IPOP_CMAES> ipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 3.72, // stepSize + 2.0, // populationFactor + 5, // maxRestarts + 1e4 // maxFunctionEvaluations + ); + + arma::mat initialPoint = f.GetInitialPoint(); + arma::mat expectedResult = f.GetFinalPoint(); + + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); +} -#endif +/** + * Run IPOP-CMA-ES on the Rosenbrock function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") +{ + BoundaryBoxConstraint<> b(0, 2); + + BIPOP_CMAES> bipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 0.25, // stepSize + 1.5, // populationFactor + 5, // maxRestarts + 1e4 // maxFunctionEvaluations + ); + + FunctionTest(bipopcmaes, 0.1, 0.1); +} + +/** + * Run BIPOP-CMA-ES on the Rosenbrock function and check whether the optimizer + * converges to the expected solution within tolerance limits. + */ +TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") +{ + BoundaryBoxConstraint<> b(0, 2); + + BIPOP_CMAES> bipopcmaes( + 15, // lambda + b, // transformationPolicy + 32, // batchSize + 1000, // maxIterations + 1e-8, // tolerance + FullSelection(), // selectionPolicy + 0.25, // stepSize + 1.5, // populationFactor + 5, // maxRestarts + 1e4 // maxFunctionEvaluations + ); + + FunctionTest(bipopcmaes, 0.1, 0.1); +} + +/** + * Run IPOP-CMA-ES with the full selection policy on logistic regression and + * make sure the results are acceptable. + */ +TEST_CASE("IPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") +{ + BoundaryBoxConstraint<> b(-10, 10); + IPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); + LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); +} + +/** + * Run BIPOP-CMA-ES with the random selection policy on logistic regression and + * make sure the results are acceptable. + */ +TEST_CASE("BIPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") +{ + BoundaryBoxConstraint<> b(-10, 10); + BIPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); + LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); +} From 8f5ce2239b64d523d44efe50b7404650b7630ade Mon Sep 17 00:00:00 2001 From: beny Date: Mon, 19 Aug 2024 22:10:06 -0700 Subject: [PATCH 21/54] init overallSBC to sbc --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index bdedb16b4..eb77efadd 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -73,6 +73,8 @@ typename MatType::elem_type POP_CMAES::Optimize(function, iterate, sbc, callbacks...); + + overallSBC = sbc; ElemType objective; size_t evaluations; From 723b62338f98bddbc48409a7a10b998aa3b33353 Mon Sep 17 00:00:00 2001 From: beny-dl <38348820+beny-dl@users.noreply.github.com> Date: Tue, 20 Aug 2024 09:15:17 -0700 Subject: [PATCH 22/54] Update include/ensmallen_bits/cmaes/pop_cmaes.hpp Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes.hpp b/include/ensmallen_bits/cmaes/pop_cmaes.hpp index 5ee1aca29..729116c3d 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes.hpp @@ -107,16 +107,16 @@ class POP_CMAES : public CMAES * @param maxFunctionEvaluations Maximum number of function evaluations. */ POP_CMAES(const size_t lambda = 0, - const TransformationPolicyType& transformationPolicy = - TransformationPolicyType(), - const size_t batchSize = 32, - const size_t maxIterations = 1000, - const double tolerance = 1e-5, - const SelectionPolicyType& selectionPolicy = SelectionPolicyType(), - double stepSize = 0, - const double populationFactor = 2, - const size_t maxRestarts = 9, - const size_t maxFunctionEvaluations = 1e9); + const TransformationPolicyType& transformationPolicy = + TransformationPolicyType(), + const size_t batchSize = 32, + const size_t maxIterations = 1000, + const double tolerance = 1e-5, + const SelectionPolicyType& selectionPolicy = SelectionPolicyType(), + double stepSize = 0, + const double populationFactor = 2, + const size_t maxRestarts = 9, + const size_t maxFunctionEvaluations = 1e9); /** * Set POP-CMA-ES specific parameters. From 4abc15d68d5cc886f8cdd5c720105e6251d5e3de Mon Sep 17 00:00:00 2001 From: beny Date: Tue, 20 Aug 2024 09:33:19 -0700 Subject: [PATCH 23/54] update doc and tests --- doc/function_types.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/function_types.md b/doc/function_types.md index 418ac3501..d04abb2fa 100644 --- a/doc/function_types.md +++ b/doc/function_types.md @@ -358,7 +358,10 @@ Each of the implemented methods is allowed to have additional cv-modifiers The following optimizers can be used with arbitrary separable functions: + - [ActiveCMAES](#activecmaes) + - [BIPOP_CMAES](#bipopcmaes) - [CMAES](#cmaes) + - [IPOP_CMAES](#ipopcmaes) Each of these optimizers has an `Optimize()` function that is called as `Optimize(f, x)` where `f` is the function to be optimized and `x` holds the From 2e3f7db7b8cc2a45b1fce7a51ad4fd98c58e7bfc Mon Sep 17 00:00:00 2001 From: beny Date: Tue, 20 Aug 2024 11:45:53 -0700 Subject: [PATCH 24/54] update tests --- tests/pop_cmaes_test.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp index 7d2bd9c7f..79167f55b 100644 --- a/tests/pop_cmaes_test.cpp +++ b/tests/pop_cmaes_test.cpp @@ -19,19 +19,19 @@ TEST_CASE("IPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") 15, // lambda b, // transformationPolicy 32, // batchSize - 1000, // maxIterations + 10000, // maxIterations 1e-8, // tolerance FullSelection(), // selectionPolicy 3.72, // stepSize 2.0, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations + 7, // maxRestarts + 1e6 // maxFunctionEvaluations ); arma::mat initialPoint = f.GetInitialPoint(); arma::mat expectedResult = f.GetFinalPoint(); - MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.5, f.GetFinalObjective(), 0.5, 5); } /** @@ -47,19 +47,19 @@ TEST_CASE("BIPOPCMAESRastriginFunctionTest", "[POPCMAESTest]") 15, // lambda b, // transformationPolicy 32, // batchSize - 1000, // maxIterations + 10000, // maxIterations 1e-8, // tolerance FullSelection(), // selectionPolicy 3.72, // stepSize 2.0, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations + 7, // maxRestarts + 1e6 // maxFunctionEvaluations ); arma::mat initialPoint = f.GetInitialPoint(); arma::mat expectedResult = f.GetFinalPoint(); - MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.01, f.GetFinalObjective(), 0.1, 5); + MultipleTrialOptimizerTest(f, ipopcmaes, initialPoint, expectedResult, 0.5, f.GetFinalObjective(), 0.5, 5); } /** @@ -74,16 +74,16 @@ TEST_CASE("IPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") 15, // lambda b, // transformationPolicy 32, // batchSize - 1000, // maxIterations + 10000, // maxIterations 1e-8, // tolerance FullSelection(), // selectionPolicy 0.25, // stepSize 1.5, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations + 7, // maxRestarts + 1e6 // maxFunctionEvaluations ); - FunctionTest(bipopcmaes, 0.1, 0.1); + FunctionTest(bipopcmaes, 0.5, 0.5); } /** @@ -98,16 +98,16 @@ TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") 15, // lambda b, // transformationPolicy 32, // batchSize - 1000, // maxIterations + 10000, // maxIterations 1e-8, // tolerance FullSelection(), // selectionPolicy 0.25, // stepSize 1.5, // populationFactor - 5, // maxRestarts - 1e4 // maxFunctionEvaluations + 7, // maxRestarts + 1e6 // maxFunctionEvaluations ); - FunctionTest(bipopcmaes, 0.1, 0.1); + FunctionTest(bipopcmaes, 0.5, 0.5); } /** @@ -117,7 +117,7 @@ TEST_CASE("BIPOPCMAESRosenbrockFunctionTest", "[POPCMAESTest]") TEST_CASE("IPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") { BoundaryBoxConstraint<> b(-10, 10); - IPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); + IPOP_CMAES> cmaes(0, b, 32, 1000, 1e-3, FullSelection(), 0.6, 2.0, 7, 1e7); LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); } @@ -128,6 +128,6 @@ TEST_CASE("IPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") TEST_CASE("BIPOPCMAESLogisticRegressionTest", "[POPCMAESTest]") { BoundaryBoxConstraint<> b(-10, 10); - BIPOP_CMAES> cmaes(0, b, 32, 500, 1e-3, FullSelection(), 0.6, 2.0, 5, 1e7); + BIPOP_CMAES> cmaes(0, b, 32, 1000, 1e-3, FullSelection(), 0.6, 2.0, 7, 1e7); LogisticRegressionFunctionTest(cmaes, 0.003, 0.006, 5); } From 6b674f33e5867368b45ed871b56a0a06f5237205 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:22:33 +0100 Subject: [PATCH 25/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 116c65801..9159e99a1 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -871,7 +871,7 @@ optimizer2.Optimize(f, coordinates); * [SGD in Wikipedia](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) * [SGD](#standard-sgd) -## BIPOP_CMAES +## BIPOP CMA-ES *An optimizer for [separable functions](#separable-functions).* From b876f45206635a39023fdf5ba1954b97ed162d74 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:22:55 +0100 Subject: [PATCH 26/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 9159e99a1..56a2f856d 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -875,7 +875,7 @@ optimizer2.Optimize(f, coordinates); *An optimizer for [separable functions](#separable-functions).* -BIPOP CMA-ES (Bi-Population CMA-ES) extends the idea of IPOP CMA-ES by using +BIPOP CMA-ES (Bi-Population CMA-ES) extends the idea of [IPOP CMA-ES](#ipop-cma-es) by using two intertwined restart strategies: one with an increasing population size and another maintaining a smaller, variable population size. This strategy allows BIPOP CMA-ES to adaptively balance exploration and exploitation across the From 0b5ecbdd3beedc785c970fe7bf1e4df907345fcb Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:23:22 +0100 Subject: [PATCH 27/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 56a2f856d..532af1400 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -921,7 +921,7 @@ The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters RosenbrockFunction f; arma::mat coordinates = f.GetInitialPoint(); -// IPOP Active CMA-ES +// BIPOP CMA-ES BoundaryBoxConstraint<> b(-1, 1); BIPOP_CMAES optimizer(0, b, 32, 200, 1e-4, 5, 2, 9, 1e4); Optimizer.Optimize(f, coordinates); From 0980684b1ff1d3f7d2f629e9a476c24a149dc421 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:23:52 +0100 Subject: [PATCH 28/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 532af1400..56c7baf3c 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1646,7 +1646,7 @@ optimizer.Optimize(f, coordinates); * [HOGWILD!: A Lock-Free Approach to Parallelizing Stochastic Gradient Descent](https://arxiv.org/abs/1106.5730) * [Sparse differentiable separable functions](#sparse-differentiable-separable-functions) -## IPOP_CMAES +## IPOP CMA-ES *An optimizer for [separable functions](#separable-functions).* From a985816998134430c7019ae9abca6c443b615340 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:24:13 +0100 Subject: [PATCH 29/54] Update doc/function_types.md per suggestion Co-authored-by: Ryan Curtin --- doc/function_types.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/function_types.md b/doc/function_types.md index f4e5cdcad..fb95ca41b 100644 --- a/doc/function_types.md +++ b/doc/function_types.md @@ -358,10 +358,10 @@ Each of the implemented methods is allowed to have additional cv-modifiers The following optimizers can be used with arbitrary separable functions: - - [ActiveCMAES](#activecmaes) - - [BIPOP_CMAES](#bipopcmaes) - - [CMAES](#cmaes) - - [IPOP_CMAES](#ipopcmaes) + - [Active CMA-ES](#active-cma-es) + - [BIPOP CMA-ES](#bipop-cma-es) + - [CMA-ES](#cma-es) + - [IPOP CMA-ES](#ipop-cma-es) Each of these optimizers has an `Optimize()` function that is called as `Optimize(f, x)` where `f` is the function to be optimized and `x` holds the From 6e674f9e6723d4a3c4d33576b9c6f41814994c2f Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:24:40 +0100 Subject: [PATCH 30/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 56c7baf3c..d5bf08eaf 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -86,9 +86,9 @@ approxOptimizer.Optimize(f, coordinates); #### See also: - * [BIPOP_CMAES](#bipopcmaes) - * [CMAES](#cmaes) - * [IPOP_CMAES](#ipopcmaes) + * [BIPOP CMA-ES](#bipop-cma-es) + * [CMA-ES](#cma-es) + * [IPOP CMA-ES](#ipop-cma-es) * [Improving Evolution Strategies through Active Covariance Matrix Adaptation](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.4239&rep=rep1&type=pdfn) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) From 71fc31016e723c66174aae9ae456e6366a724d96 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:25:09 +0100 Subject: [PATCH 31/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index d5bf08eaf..0b4dddbd8 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -887,11 +887,7 @@ populations intensify the search in promising regions. * `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>()` * `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy`_`)` -* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` -* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` -* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` -* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts`_`)` -* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor`_`)` +* `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance`_`)` * `BIPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor, maxFunctionEvaluations`_`)` ### Attributes From 1a222d30ef533c88eceb43b2c04c840762d414dd Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:25:48 +0100 Subject: [PATCH 32/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 0b4dddbd8..16fca31c8 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -905,7 +905,17 @@ populations intensify the search in promising regions. | `double` | **`populationFactor`** | The factor by which the population increases after each restart. | `2.0` | | `size_t` | **`maxFunctionEvaluations`** | Maximum number of function evaluations. | `1e9` | -The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters are used to control how the selection of points and the transformation of the decision variables are handled during the optimization process. For more information, check the [CMAES](#cmaes) class. The `lambda`, `transformationPolicy`, `batchSize`, `maxIterations`, `tolerance`, `selectionPolicy`, and `stepSize` are all parameters that affect the underlying CMAES process. +The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters +are used to control how the selection of points and the transformation of the +decision variables are handled during the optimization process. For more +information, check the [`CMAES`](#cma-es) class. The `lambda`, +`transformationPolicy`, `batchSize`, `maxIterations`, `tolerance`, +`selectionPolicy`, and `stepSize` are all parameters that affect the underlying +CMA-ES process. + +For convenience, the following type can be used: + + * **`BIPOP_CMAES<>`** (equivalent to `BIPOP_CMAES>`): uses all separable functions to compute objective #### Examples: From b07b339a6c1a0e8b21f153939d02403cac65b695 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:26:11 +0100 Subject: [PATCH 33/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 16fca31c8..8e0612bdc 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -937,9 +937,9 @@ Optimizer.Optimize(f, coordinates); #### See also: - * [CMAES](#cmaes) - * [ActiveCMAES](#activecmaes) - * [IPOP_CMAES](#ipopcmaes) + * [CMA-ES](#cma-es) + * [Active CMA-ES](#active-cma-es) + * [IPOP CMA-ES](#ipop-cma-es) * [Benchmarking a BI-Population CMA-ES on the BBOB-2009 Function Testbed](https://dl.acm.org/doi/pdf/10.1145/1570256.1570333) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) From f377c794d73851e195832230b46623a20bf8753b Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:26:32 +0100 Subject: [PATCH 34/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 8e0612bdc..936b74f42 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1103,9 +1103,9 @@ approxOptimizer.Optimize(f, coordinates); #### See also: - * [ActiveCMAES](#activecmaes) - * [BIPOP_CMAES](#bipopcmaes) - * [IPOP_CMAES](#ipopcmaes) + * [Active CMAES](#active-cma-es) + * [BIPOP CMA-ES](#bipop-cma-es) + * [IPOP CMA-ES](#ipop-cma-es) * [Completely Derandomized Self-Adaptation in Evolution Strategies](http://www.cmap.polytechnique.fr/~nikolaus.hansen/cmaartic.pdf) * [CMA-ES in Wikipedia](https://en.wikipedia.org/wiki/CMA-ES) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) From d271cda3545889e16faeb9163f2d316d5fcad7f6 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:26:59 +0100 Subject: [PATCH 35/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 936b74f42..dec7c2bda 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1668,11 +1668,7 @@ local optima, thus increasing the chances of discovering the global optimum. * `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>()` * `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy`_`)` -* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize`_`)` -* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)` -* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)` -* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts`_`)` -* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor`_`)` +* `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance`_`)` * `IPOP_CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize, maxRestarts, populationFactor, maxFunctionEvaluations`_`)` ### Attributes From befd7d577454aaec63bd1b9f1d6809fc971d7a57 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:27:27 +0100 Subject: [PATCH 36/54] Update include/ensmallen_bits/cmaes/pop_cmaes.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes.hpp b/include/ensmallen_bits/cmaes/pop_cmaes.hpp index 729116c3d..761430523 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes.hpp @@ -114,8 +114,8 @@ class POP_CMAES : public CMAES const double tolerance = 1e-5, const SelectionPolicyType& selectionPolicy = SelectionPolicyType(), double stepSize = 0, - const double populationFactor = 2, const size_t maxRestarts = 9, + const double populationFactor = 2, const size_t maxFunctionEvaluations = 1e9); /** From b98991b0ba8fec3854914486eb27527d4acf99e3 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:27:51 +0100 Subject: [PATCH 37/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index eb77efadd..b0e7f833b 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -34,8 +34,8 @@ POP_CMAES( lambda, transformationPolicy, batchSize, maxIterations, From 33b545258ea76dc393e9c7fccae79088823cd3c4 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:28:13 +0100 Subject: [PATCH 38/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index dec7c2bda..cb2303bf1 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1686,7 +1686,17 @@ local optima, thus increasing the chances of discovering the global optimum. | `double` | **`populationFactor`** | The factor by which the population increases after each restart. | `2.0` | | `size_t` | **`maxFunctionEvaluations`** | Maximum number of function evaluations. | `1e9` | -The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters are used to control how the selection of points and the transformation of the decision variables are handled during the optimization process. For more information, check the [CMAES](#cmaes) class. The `lambda`, `transformationPolicy`, `batchSize`, `maxIterations`, `tolerance`, `selectionPolicy`, and `stepSize` are all parameters that affect the underlying CMAES process. +The _`SelectionPolicyType`_ and _`TransformationPolicyType`_ template parameters +are used to control how the selection of points and the transformation of the +decision variables are handled during the optimization process. For more +information, check the [`CMAES`](#cma-es) class. The `lambda`, +`transformationPolicy`, `batchSize`, `maxIterations`, `tolerance`, +`selectionPolicy`, and `stepSize` are all parameters that affect the underlying +CMA-ES process. + +For convenience, the following type can be used: + + * **`IPOP_CMAES<>`** (equivalent to `IPOP_CMAES>`): uses all separable functions to compute objective #### Examples: From 42e01eeb332c490fd4e263c88c96eec652c9d152 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:28:35 +0100 Subject: [PATCH 39/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index cb2303bf1..6aea1ed92 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1708,7 +1708,7 @@ For convenience, the following type can be used: RosenbrockFunction f; arma::mat coordinates = f.GetInitialPoint(); -// IPOP Active CMA-ES +// IPOP CMA-ES BoundaryBoxConstraint<> b(-1, 1); IPOP_CMAES optimizer(0, b, 32, 200, 1e-4, 5, 2, 9, 1e4); Optimizer.Optimize(f, coordinates); From 765af8559b56536ce0ff365d0775bdba86704d2f Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:28:54 +0100 Subject: [PATCH 40/54] Update doc/optimizers.md per suggestion Co-authored-by: Ryan Curtin --- doc/optimizers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/optimizers.md b/doc/optimizers.md index 6aea1ed92..70aedb7db 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1718,9 +1718,9 @@ Optimizer.Optimize(f, coordinates); #### See also: - * [CMAES](#cmaes) - * [ActiveCMAES](#activecmaes) - * [BIPOP_CMAES](#bipopcmaes) + * [CMA-ES](#cmaes) + * [Active CMA-ES](#active-cma-es) + * [BIPOP CMA-ES](#bipop-cma-es) * [A Restart CMA Evolution Strategy With Increasing Population Size](http://www.cmap.polytechnique.fr/~nikolaus.hansen/cec2005ipopcmaes.pdf) * [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy) From 27ec68d07c09cbc5b674648d1e3cf0b83dee22b4 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:29:16 +0100 Subject: [PATCH 41/54] Update include/ensmallen_bits/cmaes/cmaes.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/cmaes.hpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/ensmallen_bits/cmaes/cmaes.hpp b/include/ensmallen_bits/cmaes/cmaes.hpp index 7bd4140c3..7b48c6ec5 100644 --- a/include/ensmallen_bits/cmaes/cmaes.hpp +++ b/include/ensmallen_bits/cmaes/cmaes.hpp @@ -176,11 +176,6 @@ class CMAES size_t FunctionEvaluations() const { return functionEvaluations; } - //! Type of Selection Policy. - typedef SelectionPolicyType selectionPolicyType; - //! Type of Transformation Policy. - typedef TransformationPolicyType transformationPolicyType; - private: //! Population size. size_t lambda; From b8671a41c4308adba9177b2095d8e5f089491566 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:29:38 +0100 Subject: [PATCH 42/54] Update include/ensmallen_bits/cmaes/cmaes.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/cmaes.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/ensmallen_bits/cmaes/cmaes.hpp b/include/ensmallen_bits/cmaes/cmaes.hpp index 7b48c6ec5..6fed17a98 100644 --- a/include/ensmallen_bits/cmaes/cmaes.hpp +++ b/include/ensmallen_bits/cmaes/cmaes.hpp @@ -173,8 +173,7 @@ class CMAES { return stepSize; } //! Get the total number of function evaluations. - size_t FunctionEvaluations() const - { return functionEvaluations; } + size_t FunctionEvaluations() const { return functionEvaluations; } private: //! Population size. From 5a69d3d0bac6d875cda11c08ac32a88a9bad769e Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:30:14 +0100 Subject: [PATCH 43/54] Update tests/pop_cmaes_test.cpp per suggestion Co-authored-by: Ryan Curtin --- tests/pop_cmaes_test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/pop_cmaes_test.cpp b/tests/pop_cmaes_test.cpp index 79167f55b..46e1d427f 100644 --- a/tests/pop_cmaes_test.cpp +++ b/tests/pop_cmaes_test.cpp @@ -1,3 +1,14 @@ +/** + * @file pop_cmaes_test.cpp + * @author Benjami Parellada + * + * Tests for the POP_CMAES class, including IPOP CMA-ES and BIPOP CMA-ES. + * + * ensmallen is free software; you may redistribute it and/or modify it under + * the terms of the 3-clause BSD license. You should have received a copy of + * the 3-clause BSD license along with ensmallen. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ #include #include "catch.hpp" #include "test_function_tools.hpp" From 32443c731f12ef6a8aeab8af38bea1139633200b Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:30:36 +0100 Subject: [PATCH 44/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index b0e7f833b..ac3a16cc3 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -19,7 +19,6 @@ #include "pop_cmaes.hpp" #include -#include namespace ens { From 0b735a7f2725b46b7ee3ad8728165e56f72f8ac9 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:31:05 +0100 Subject: [PATCH 45/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index ac3a16cc3..f21d34895 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -63,10 +63,6 @@ typename MatType::elem_type POP_CMAES dis(0.0, 1.0); - // First single run with default population size MatType iterate = iterateIn; ElemType overallObjective = CMAES Date: Thu, 28 Nov 2024 06:31:40 +0100 Subject: [PATCH 46/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index f21d34895..8cf494e78 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -109,10 +109,10 @@ typename MatType::elem_type POP_CMAES(); size_t smallLambda = static_cast(defaultLambda * std::pow(0.5 * currentLargeLambda / defaultLambda, u * u)); - double stepSizeSmall = 2 * std::pow(10, -2*dis(gen)); + double stepSizeSmall = 2 * std::pow(10, -2 * arma::randu()); this->PopulationSize() = smallLambda; this->StepSize() = stepSizeSmall; From cc393087d328b0f17dcf351cc9e082cdf0c0a8dc Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:32:04 +0100 Subject: [PATCH 47/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index 8cf494e78..9a3d10cfb 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -118,7 +118,7 @@ typename MatType::elem_type POP_CMAESStepSize() = stepSizeSmall; Info << "BIPOP-CMA-ES: restart " << restart << ", small population" << - " size (lambda): " << this->PopulationSize() << std::endl; + " size (lambda): " << this->PopulationSize() << "." << std::endl; iterate = iterateIn; From 7b95aa03b182eb81e63e812a350ee8573b18abc9 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:32:23 +0100 Subject: [PATCH 48/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index 9a3d10cfb..7f245b2cf 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -135,8 +135,8 @@ typename MatType::elem_type POP_CMAES Date: Thu, 28 Nov 2024 06:32:41 +0100 Subject: [PATCH 49/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index 7f245b2cf..db48968c3 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -94,7 +94,7 @@ typename MatType::elem_type POP_CMAESStepSize() = stepSizeDefault; Info << "POP-CMA-ES: restart " << restart << ", large population size" << - " (lambda): " << this->PopulationSize() << std::endl; + " (lambda): " << this->PopulationSize() << "." << std::endl; iterate = iterateIn; From 8749c95875704fa3ab7c925af0ec8d4c3d0e82f8 Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:33:00 +0100 Subject: [PATCH 50/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index db48968c3..547503634 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -79,7 +79,7 @@ typename MatType::elem_type POP_CMAESStepSize(); // Print out the default population size - Info << "Default population size: " << defaultLambda << std::endl; + Info << "Default population size: " << defaultLambda << "." << std::endl; size_t restart = 0; From 2456a4b87fb95d579c923b6198164c92fe07e60c Mon Sep 17 00:00:00 2001 From: conradsnicta Date: Thu, 28 Nov 2024 06:33:17 +0100 Subject: [PATCH 51/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index 547503634..76ee95712 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -146,7 +146,7 @@ typename MatType::elem_type POP_CMAES Date: Thu, 28 Nov 2024 06:33:30 +0100 Subject: [PATCH 52/54] Update include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp per suggestion Co-authored-by: Ryan Curtin --- include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp index 76ee95712..38b801126 100644 --- a/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp +++ b/include/ensmallen_bits/cmaes/pop_cmaes_impl.hpp @@ -154,7 +154,7 @@ typename MatType::elem_type POP_CMAES Date: Thu, 28 Nov 2024 10:44:25 +0100 Subject: [PATCH 53/54] Update HISTORY.md --- HISTORY.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 0742d6e4c..7ce367b4b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,7 +7,11 @@ ([#404](https://github.com/mlpack/ensmallen/pull/404)). * For Armadillo 14.2.0 switch to `.index_min()` and `.index_max()` - ([#409](https://github.com/mlpack/ensmallen/pull/409). + ([#409](https://github.com/mlpack/ensmallen/pull/409)). + + * Added IPOP and BIPOP restart mechanisms for CMA-ES. + ([#403](https://github.com/mlpack/ensmallen/pull/403)). + ### ensmallen 2.21.1: "Bent Antenna" ###### 2024-02-15 From 57da5ebcdc1a8413de53b4c5c22ae9a8ff694610 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Thu, 28 Nov 2024 09:59:10 -0500 Subject: [PATCH 54/54] Change CMAES to CMA-ES in other places too. --- doc/function_types.md | 4 ++-- doc/optimizers.md | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/function_types.md b/doc/function_types.md index fb95ca41b..3da52a000 100644 --- a/doc/function_types.md +++ b/doc/function_types.md @@ -456,7 +456,7 @@ int main() // parameters, so the shape is 10x1. arma::mat params(10, 1, arma::fill::randn); - // Use the CMAES optimizer with default parameters to minimize the + // Use the CMA-ES optimizer with default parameters to minimize the // LinearRegressionFunction. // The ens::CMAES type can be replaced with any suitable ensmallen optimizer // that can handle arbitrary separable functions. @@ -464,7 +464,7 @@ int main() LinearRegressionFunction lrf(data, responses); cmaes.Optimize(lrf, params); - std::cout << "The optimized linear regression model found by CMAES has the " + std::cout << "The optimized linear regression model found by CMA-ES has the " << "parameters " << params.t(); } ``` diff --git a/doc/optimizers.md b/doc/optimizers.md index 70aedb7db..2691eb751 100644 --- a/doc/optimizers.md +++ b/doc/optimizers.md @@ -1,4 +1,4 @@ -## ActiveCMAES +## Active CMA-ES *An optimizer for [separable functions](#separable-functions).* @@ -72,12 +72,12 @@ the coordinates respectively. RosenbrockFunction f; arma::mat coordinates = f.GetInitialPoint(); -// ActiveCMAES with the FullSelection and BoundaryBoxConstraint policies. +// Active CMA-ES with the FullSelection and BoundaryBoxConstraint policies. BoundaryBoxConstraint b(-1, 1); ActiveCMAES optimizer(0, b, 32, 200, 1e-4); optimizer.Optimize(f, coordinates); -// ActiveCMAES with the RandomSelection and BoundaryBoxConstraint policies. +// Active CMA-ES with the RandomSelection and BoundaryBoxConstraint policies. ApproxActiveCMAES> cmaes(0, b, 32, 200, 1e-4); approxOptimizer.Optimize(f, coordinates); ``` @@ -1019,7 +1019,7 @@ cyclicscd.Optimize(f, coordinates); * [Stochastic Methods for L1-Regularized Loss Minimization](https://www.jmlr.org/papers/volume12/shalev-shwartz11a/shalev-shwartz11a.pdf) * [Partially differentiable functions](#partially-differentiable-functions) -## CMAES +## CMA-ES *An optimizer for [separable functions](#separable-functions).* @@ -1089,12 +1089,12 @@ the coordinates respectively. RosenbrockFunction f; arma::mat coordinates = f.GetInitialPoint(); -// CMAES with the FullSelection and BoundaryBoxConstraint policies. +// CMA-ES with the FullSelection and BoundaryBoxConstraint policies. BoundaryBoxConstraint b(-1, 1); CMAES optimizer(0, b, 32, 200, 1e-4); optimizer.Optimize(f, coordinates); -// CMAES with the RandomSelection and BoundaryBoxConstraint policies. +// CMA-ES with the RandomSelection and BoundaryBoxConstraint policies. ApproxCMAES> cmaes(0, b, 32, 200, 1e-4); approxOptimizer.Optimize(f, coordinates); ```