From 33a2b63201d4a30e8236144b89f68abae1161288 Mon Sep 17 00:00:00 2001 From: "james.balamuta@gmail.com" Date: Sat, 30 Nov 2024 01:03:37 -0600 Subject: [PATCH] Add local patch of changes sent upstream --- ChangeLog | 9 +++ NEWS.md | 2 + .../ensmallen_bits/agemoea/agemoea.hpp | 22 +++---- .../problems/dtlz/dtlz2_function.hpp | 53 +++++++++-------- .../problems/dtlz/dtlz4_function.hpp | 49 ++++++++-------- .../problems/dtlz/dtlz5_function.hpp | 57 +++++++++---------- .../problems/dtlz/dtlz6_function.hpp | 51 ++++++++--------- .../problems/dtlz/dtlz7_function.hpp | 43 +++++++------- .../problems/maf/maf5_function.hpp | 55 +++++++++--------- .../problems/maf/maf6_function.hpp | 51 ++++++++--------- 10 files changed, 195 insertions(+), 197 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0ee557..5e58ac5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2024-11-29 James Balamuta + * inst/include/ensmallen_bits/agemoea/agemoea.hpp: removed unused private field variable + * inst/include/problems/dtlz/dtlz2_function.hpp: removed unused variable. + * inst/include/problems/dtlz/dtlz4_function.hpp: ditto + * inst/include/problems/dtlz/dtlz5_function.hpp: ditto + * inst/include/problems/dtlz/dtlz6_function.hpp: ditto + * inst/include/problems/dtlz/dtlz7_function.hpp: ditto + * inst/include/problems/maf/maf5_function.hpp: ditto + * inst/include/problems/maf/maf6_function.hpp: ditto + * DESCRIPTION (Version): Release 2.22.0 * NEWS.md: Update for Ensmallen release 2.22.0 * inst/include/ensmallen_bits: Upgraded to Ensmallen 2.22.0 diff --git a/NEWS.md b/NEWS.md index fb34334..279373f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ ([#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)). +- Addressed uninitialized variable and private field warnings + ([#65](https://github.com/coatless-rpkg/rcppensmallen/pull/65)) # RcppEnsmallen 0.2.21.1.1 diff --git a/inst/include/ensmallen_bits/agemoea/agemoea.hpp b/inst/include/ensmallen_bits/agemoea/agemoea.hpp index f7c5c2f..0748678 100644 --- a/inst/include/ensmallen_bits/agemoea/agemoea.hpp +++ b/inst/include/ensmallen_bits/agemoea/agemoea.hpp @@ -347,7 +347,7 @@ class AGEMOEA size_t idxQ, const std::vector& ranks, const std::vector& survivalScore); - + /** * Normalizes the front given the extreme points in the current front. * @@ -363,7 +363,7 @@ class AGEMOEA arma::Col& normalization, const std::vector& front, const arma::Row& extreme); - + /** * Get the geometry information p of Lp norm (p > 0). * @@ -377,7 +377,7 @@ class AGEMOEA std::vector >& calculatedObjectives, const std::vector& front, const arma::Row& extreme); - + /** * Finds the pairwise Lp distance between all the points in the front. * @@ -395,7 +395,7 @@ class AGEMOEA /** * Finding the indexes of the extreme points in the front. - * + * * @param indexes vector containing the slected indexes. * @param calculatedObjectives The current population objectives. * @param front The front of the current generation. @@ -405,11 +405,11 @@ class AGEMOEA arma::Row& indexes, std::vector >& calculatedObjectives, const std::vector& front); - + /** * Finding the distance of each point in the front from the line formed * by pointA and pointB. - * + * * @param distance The vector containing the distances of the points in the fron from the line. * @param calculatedObjectives Reference to the current population evaluated Objectives. * @param front The front of the current generation(indices of population). @@ -423,10 +423,10 @@ class AGEMOEA const std::vector& front, const arma::Col& pointA, const arma::Col& pointB); - + /** * Find the Diversity score corresponding the solution S using the selected set. - * + * * @param selected The current selected set. * @param pairwiseDistance The current pairwise distance for the whole front. * @param S The relative index of S being considered within the front. @@ -452,12 +452,6 @@ class AGEMOEA //! Probability that crossover will occur. double crossoverProb; - //! Probability that mutation will occur. - double mutationProb; - - //! Strength of the mutation. - double mutationStrength; - //! The crowding degree of the mutation. Higher value produces a mutant //! resembling its parent. double distributionIndex; diff --git a/inst/include/ensmallen_bits/problems/dtlz/dtlz2_function.hpp b/inst/include/ensmallen_bits/problems/dtlz/dtlz2_function.hpp index d73de19..aa56a14 100644 --- a/inst/include/ensmallen_bits/problems/dtlz/dtlz2_function.hpp +++ b/inst/include/ensmallen_bits/problems/dtlz/dtlz2_function.hpp @@ -23,8 +23,8 @@ namespace test { * \f[ * x_M = [x_i, n - M + 1 <= i <= n] * g(x) = \Sigma{i = n - M + 1}^n (x_i - 0.5)^2 - * - * f_1(x) = 0.5 * cos(x_1 * pi * 0.5) * cos(x_2 * pi * 0.5) * ... cos(x_2 * pi * 0.5) * (1 + g(x_M)) + * + * f_1(x) = 0.5 * cos(x_1 * pi * 0.5) * cos(x_2 * pi * 0.5) * ... cos(x_2 * pi * 0.5) * (1 + g(x_M)) * f_2(x) = 0.5 * cos(x_1 * pi * 0.5) * cos(x_2 * pi * 0.5) * ... sin(x_M-1 * pi * 0.5) * (1 + g(x_M)) * . * . @@ -35,9 +35,9 @@ namespace test { * 0 <= x_i <= 1 for i = 1,...,n. * * This should be optimized to x_i = 0.5 (for all x_i in x_M), at: - * + * * For more information, please refer to: - * + * * @code * @incollection{deb2005scalable, * title={Scalable test problems for evolutionary multiobjective optimization}, @@ -62,7 +62,7 @@ namespace test { size_t numParetoPoints; public: - + /** * Object Constructor. * Initializes the individual objective functions. @@ -82,10 +82,10 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, 1, arma::fill::zeros); - } - + } + // Get the private variables. - + // Get the number of objectives. size_t GetNumObjectives () { return this -> numObjectives; } @@ -110,20 +110,19 @@ namespace test { */ arma::Row g(const MatType& coords) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + for(size_t i = numObjectives - 1; i < numVariables; i++) { - innerSum += arma::pow((coords.row(i) - 0.5), 2); - } - + innerSum += arma::pow((coords.row(i) - 0.5), 2); + } + return innerSum; - } + } /** * Evaluate the objectives with the given coordinate. @@ -141,21 +140,21 @@ namespace test { arma::Row value = 0.5 * (1.0 + G); for(size_t i = 0; i < numObjectives - 1; i++) { - objectives.row(i) = value % + objectives.row(i) = value % arma::sin(coords.row(i) * arma::datum::pi * 0.5); - value = value % arma::cos(coords.row(i) * arma::datum::pi * 0.5); + value = value % arma::cos(coords.row(i) * arma::datum::pi * 0.5); } objectives.row(numObjectives - 1) = value; - return objectives; + return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct DTLZ2Objective { DTLZ2Objective(size_t stop, DTLZ2& dtlz): stop(stop), dtlz(dtlz) - {/* Nothing to do here. */} - + {/* Nothing to do here. */} + /** * Evaluate one objective with the given coordinate. * @@ -182,8 +181,8 @@ namespace test { } value = value * (1.0 + dtlz.g(coords)[0]); - return value; - } + return value; + } DTLZ2& dtlz; size_t stop; @@ -193,12 +192,12 @@ namespace test { std::tuple GetObjectives() { return std::make_tuple(objectiveF1, objectiveF2, objectiveF3); - } + } //! Get the Reference Front. //! Front. The implementation has been taken from pymoo. arma::mat GetReferenceFront() - { + { Uniform refGenerator; arma::mat refDirs = refGenerator.Generate(3, this -> numParetoPoints, 0); arma::colvec x = arma::normalise(refDirs, 2, 1); @@ -214,4 +213,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif diff --git a/inst/include/ensmallen_bits/problems/dtlz/dtlz4_function.hpp b/inst/include/ensmallen_bits/problems/dtlz/dtlz4_function.hpp index cc06cb6..b01fd30 100644 --- a/inst/include/ensmallen_bits/problems/dtlz/dtlz4_function.hpp +++ b/inst/include/ensmallen_bits/problems/dtlz/dtlz4_function.hpp @@ -23,8 +23,8 @@ namespace test { * \f[ * x_M = [x_i, n - M + 1 <= i <= n] * g(x) = \Sigma{i = n - M + 1}^n (x_i - 0.5)^2 - * - * f_1(x) = 0.5 * cos(x_1^alpha * pi * 0.5) * cos(x_2^alpha * pi * 0.5) * ... cos(x_2^alpha * pi * 0.5) * (1 + g(x_M)) + * + * f_1(x) = 0.5 * cos(x_1^alpha * pi * 0.5) * cos(x_2^alpha * pi * 0.5) * ... cos(x_2^alpha * pi * 0.5) * (1 + g(x_M)) * f_2(x) = 0.5 * cos(x_1^alpha * pi * 0.5) * cos(x_2^alpha * pi * 0.5) * ... sin(x_M-1^alpha * pi * 0.5) * (1 + g(x_M)) * . * . @@ -35,9 +35,9 @@ namespace test { * 0 <= x_i <= 1 for i = 1,...,n. * * This should be optimized to x_i = 0.5 (for all x_i in x_M), at: - * + * * For more information, please refer to: - * + * * @code * @incollection{deb2005scalable, * title={Scalable test problems for evolutionary multiobjective optimization}, @@ -85,8 +85,8 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, 1, arma::fill::zeros); - } - + } + // Get the private variables. // Get the number of objectives. @@ -113,20 +113,19 @@ namespace test { */ arma::Row g(const MatType& coords) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + for(size_t i = numObjectives - 1; i < numVariables; i++) { - innerSum += arma::pow((coords.row(i) - 0.5), 2); - } - + innerSum += arma::pow((coords.row(i) - 0.5), 2); + } + return innerSum; - } + } /** * Evaluate the objectives with the given coordinate. @@ -144,21 +143,21 @@ namespace test { arma::Row value = 0.5 * (1.0 + G); for(size_t i = 0; i < numObjectives - 1; i++) { - objectives.row(i) = value % + objectives.row(i) = value % arma::sin(arma::pow(coords.row(i), alpha) * arma::datum::pi * 0.5); - value = value % arma::cos(arma::pow(coords.row(i), alpha) * arma::datum::pi * 0.5); + value = value % arma::cos(arma::pow(coords.row(i), alpha) * arma::datum::pi * 0.5); } objectives.row(numObjectives - 1) = value; - return objectives; + return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct DTLZ4Objective { DTLZ4Objective(size_t stop, DTLZ4& dtlz): stop(stop), dtlz(dtlz) - {/* Nothing to do here.*/} - + {/* Nothing to do here.*/} + /** * Evaluate one objective with the given coordinate. * @@ -185,8 +184,8 @@ namespace test { } value = value * (1 + dtlz.g(coords)[0]); - return value; - } + return value; + } DTLZ4& dtlz; size_t stop; @@ -196,12 +195,12 @@ namespace test { std::tuple GetObjectives() { return std::make_tuple(objectiveF1, objectiveF2, objectiveF3); - } + } //! Get the Reference Front. //! Front. The implementation has been taken from pymoo. arma::mat GetReferenceFront() - { + { Uniform refGenerator; arma::mat refDirs = refGenerator.Generate(3, this -> numParetoPoints, 0); arma::colvec x = arma::normalise(refDirs, 2, 1); @@ -217,4 +216,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif diff --git a/inst/include/ensmallen_bits/problems/dtlz/dtlz5_function.hpp b/inst/include/ensmallen_bits/problems/dtlz/dtlz5_function.hpp index c27926b..6c7de5c 100644 --- a/inst/include/ensmallen_bits/problems/dtlz/dtlz5_function.hpp +++ b/inst/include/ensmallen_bits/problems/dtlz/dtlz5_function.hpp @@ -21,8 +21,8 @@ namespace test { * \f[ * theta_M = [theta_i, n - M + 1 <= i <= n] * g(x) = \Sigma{i = n - M + 1}^n (x_i - 0.5)^2 - * - * f_1(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... cos(theta_M-1 * pi * 0.5) * (1 + g(theta_M)) + * + * f_1(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... cos(theta_M-1 * pi * 0.5) * (1 + g(theta_M)) * f_2(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... sin(theta_M-1 * pi * 0.5) * (1 + g(theta_M)) * . * . @@ -31,13 +31,13 @@ namespace test { * * Bounds of the variable space is: * 0 <= x_i <= 1 for i = 1,...,n. - * + * * Where theta_i = 0.5 * (1 + 2 * g(X_M) * x_i) / (1 + g(X_M)) - * + * * This should be optimized to x_i = 0.5 (for all x_i in X_M), at: - * + * * For more information, please refer to: - * + * * @code * @incollection{deb2005scalable, * title={Scalable test problems for evolutionary multiobjective optimization}, @@ -82,14 +82,14 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, 1, arma::fill::zeros); - } - + } + // Get the private variables. - + // Get the number of objectives. size_t GetNumObjectives() { return this -> numObjectives; } - + // Get the number of variables. size_t GetNumVariables() { return this -> numVariables; } @@ -110,20 +110,19 @@ namespace test { */ arma::Row g(const MatType& coords) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + for(size_t i = numObjectives - 1; i < numVariables; i++) { - innerSum += arma::pow((coords.row(i) - 0.5), 2); - } - + innerSum += arma::pow((coords.row(i) - 0.5), 2); + } + return innerSum; - } + } /** * Evaluate the objectives with the given coordinate. @@ -137,27 +136,27 @@ namespace test { typedef typename MatType::elem_type ElemType; arma::Mat objectives(numObjectives, size(coords)[1]); - arma::Row G = g(coords); + arma::Row G = g(coords); arma::Row value = 0.5 * (1.0 + G); arma::Row theta; for(size_t i = 0; i < numObjectives - 1; i++) { theta = 0.5 * (1.0 + 2.0 * coords.row(i) % G) / (1.0 + G); - objectives.row(i) = value % + objectives.row(i) = value % arma::sin(theta * arma::datum::pi * 0.5); - value = value % arma::cos(theta * arma::datum::pi * 0.5); + value = value % arma::cos(theta * arma::datum::pi * 0.5); } objectives.row(numObjectives - 1) = value; return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct DTLZ5Objective { DTLZ5Objective(size_t stop, DTLZ5& dtlz): stop(stop), dtlz(dtlz) - {/* Nothing to do here. */} - + {/* Nothing to do here. */} + /** * Evaluate one objective with the given coordinate. * @@ -173,7 +172,7 @@ namespace test { ElemType G = dtlz.g(coords)[0]; for(size_t i = 0; i < stop; i++) { - theta = 0.5 * (1.0 + 2.0 * coords[i] * G) / (1.0 + G); + theta = 0.5 * (1.0 + 2.0 * coords[i] * G) / (1.0 + G); value = value * std::cos(theta * arma::datum::pi * 0.5); } theta = 0.5 * (1.0 + 2.0 * coords[stop] * G) / (1.0 + G); @@ -187,8 +186,8 @@ namespace test { } value = value * (1.0 + G); - return value; - } + return value; + } DTLZ5& dtlz; size_t stop; @@ -198,7 +197,7 @@ namespace test { std::tuple GetObjectives () { return std::make_tuple(objectiveF1, objectiveF2, objectiveF3); - } + } DTLZ5Objective objectiveF1; DTLZ5Objective objectiveF2; @@ -207,4 +206,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif diff --git a/inst/include/ensmallen_bits/problems/dtlz/dtlz6_function.hpp b/inst/include/ensmallen_bits/problems/dtlz/dtlz6_function.hpp index 812db47..c9e4f11 100644 --- a/inst/include/ensmallen_bits/problems/dtlz/dtlz6_function.hpp +++ b/inst/include/ensmallen_bits/problems/dtlz/dtlz6_function.hpp @@ -21,8 +21,8 @@ namespace test { * \f[ * theta_M = [theta_i, n - M + 1 <= i <= n] * g(x) = \Sigma{i = n - M + 1}^n (x_i)^0.1 - * - * f_1(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... cos(theta_2 * pi * 0.5) * (1 + g(theta_M)) + * + * f_1(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... cos(theta_2 * pi * 0.5) * (1 + g(theta_M)) * f_2(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... sin(theta_M-1 * pi * 0.5) * (1 + g(theta_M)) * . * . @@ -31,13 +31,13 @@ namespace test { * * Bounds of the variable space is: * 0 <= x_i <= 1 for i = 1,...,n. - * + * * Where theta_i = 0.5 * (1 + 2 * g(X_M) * x_i) / (1 + g(X_M)) - * + * * This should be optimized to x_i = 0.5 (for all x_i in X_M), at: - * + * * For more information, please refer to: - * + * * @code * @incollection{deb2005scalable, * title={Scalable test problems for evolutionary multiobjective optimization}, @@ -82,8 +82,8 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, 1, arma::fill::zeros); - } - + } + // Get the private variables. // Get number of obectives. @@ -110,20 +110,19 @@ namespace test { */ arma::Row g(const MatType& coords) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + for(size_t i = numObjectives - 1; i < numVariables; i++) { - innerSum += arma::pow(coords.row(i), 0.1); + innerSum += arma::pow(coords.row(i), 0.1); } - + return innerSum; - } + } /** * Evaluate the objectives with the given coordinate. @@ -137,27 +136,27 @@ namespace test { typedef typename MatType::elem_type ElemType; arma::Mat objectives(numObjectives, size(coords)[1]); - arma::Row G = g(coords); + arma::Row G = g(coords); arma::Row value = 0.5 * (1.0 + G); arma::Row theta; for(size_t i = 0; i < numObjectives - 1; i++) { theta = 0.5 * (1.0 + 2.0 * coords.row(i) % G) / (1.0 + G); - objectives.row(i) = value % + objectives.row(i) = value % arma::sin(theta * arma::datum::pi * 0.5); - value = value % arma::cos(theta * arma::datum::pi * 0.5); + value = value % arma::cos(theta * arma::datum::pi * 0.5); } objectives.row(numObjectives - 1) = value; return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct DTLZ6Objective { DTLZ6Objective(size_t stop, DTLZ6& dtlz): stop(stop), dtlz(dtlz) - {/* Nothing to do here. */} - + {/* Nothing to do here. */} + /** * Evaluate one objective with the given coordinate. * @@ -173,7 +172,7 @@ namespace test { ElemType G = dtlz.g(coords)[0]; for(size_t i = 0; i < stop; i++) { - theta = 0.5 * (1.0 + 2.0 * coords[i] * G) / (1.0 + G); + theta = 0.5 * (1.0 + 2.0 * coords[i] * G) / (1.0 + G); value = value * std::cos(theta * arma::datum::pi * 0.5); } theta = 0.5 * (1.0 + 2.0 * coords[stop] * G) / (1.0 + G); @@ -187,8 +186,8 @@ namespace test { } value = value * (1.0 + G); - return value; - } + return value; + } DTLZ6& dtlz; size_t stop; @@ -198,7 +197,7 @@ namespace test { std::tuple GetObjectives () { return std::make_tuple(objectiveF1, objectiveF2, objectiveF3); - } + } DTLZ6Objective objectiveF1; DTLZ6Objective objectiveF2; @@ -207,4 +206,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif diff --git a/inst/include/ensmallen_bits/problems/dtlz/dtlz7_function.hpp b/inst/include/ensmallen_bits/problems/dtlz/dtlz7_function.hpp index 4365318..fc2959e 100644 --- a/inst/include/ensmallen_bits/problems/dtlz/dtlz7_function.hpp +++ b/inst/include/ensmallen_bits/problems/dtlz/dtlz7_function.hpp @@ -20,8 +20,8 @@ namespace test { * The DTLZ7 function, defined by: * \f[ * x_M = [x_i, n - M + 1 <= i <= n] - * g(x) = 1 + (9 / |X_M|) * (\Sigma{i = n - M + 1}^n x_i) - * + * g(x) = 1 + (9 / |X_M|) * (\Sigma{i = n - M + 1}^n x_i) + * * f_1(x) = x_1 * f_2(x) = x_2 * . @@ -33,7 +33,7 @@ namespace test { * 0 <= x_i <= 1 for i = 1,...,n. * * This should be optimized to x_i = 0.5 (for all x_i in x_M), at: - * the objective function values lie on the linear hyper-plane: + * the objective function values lie on the linear hyper-plane: * \Sigma { m = 1}^M f_m* =0.5. * * For more information, please refer to: @@ -100,7 +100,7 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, arma::fill::zeros); - } + } /** * Evaluate the G(x) with the given coordinate. @@ -114,11 +114,11 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + innerSum = (9.0 / k) * arma::sum(coords.rows(numObjectives - 1, - numVariables - 1) , 0) + 1.0; + numVariables - 1) , 0) + 1.0; return innerSum; } @@ -131,17 +131,16 @@ namespace test { arma::Row h( const MatType& coords, const arma::Row& G) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::ones); innerSum = innerSum * numObjectives; for(size_t i = 0;i < numObjectives - 1;i++) { - innerSum -= coords.row(i) % (1.0 + - arma::cos(arma::datum::pi * 3 * coords.row(i))) / (1 + G); + innerSum -= coords.row(i) % (1.0 + + arma::cos(arma::datum::pi * 3 * coords.row(i))) / (1 + G); } return innerSum; } @@ -157,21 +156,21 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; - arma::Mat objectives(numObjectives, size(coords)[1]); + arma::Mat objectives(numObjectives, size(coords)[1]); arma::Row G = g(coords); arma::Row H = h(coords, G); objectives.rows(0, numObjectives - 2) = coords.rows(0, numObjectives - 2); objectives.row(numObjectives - 1) = (1 + G) % H; - return objectives; + return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct DTLZ7Objective { DTLZ7Objective(size_t stop, DTLZ7& dtlz): stop(stop), dtlz(dtlz) - {/* Nothing to do here. */} - + {/* Nothing to do here. */} + /** * Evaluate one objective with the given coordinate. * @@ -185,10 +184,10 @@ namespace test { ElemType value = 0.5; if(stop != dtlz.numObjectives - 1) { return coords[stop];} - + value = (1.0 + dtlz.g(coords)[0]) * dtlz.h(coords, dtlz.g(coords))[0]; - return value; - } + return value; + } DTLZ7& dtlz; size_t stop; @@ -198,7 +197,7 @@ namespace test { std::tuple GetObjectives() { return std::make_tuple(objectiveF1, objectiveF2, objectiveF3); - } + } DTLZ7Objective objectiveF1; DTLZ7Objective objectiveF2; @@ -211,4 +210,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif diff --git a/inst/include/ensmallen_bits/problems/maf/maf5_function.hpp b/inst/include/ensmallen_bits/problems/maf/maf5_function.hpp index 65c1b8d..1ac5f1b 100644 --- a/inst/include/ensmallen_bits/problems/maf/maf5_function.hpp +++ b/inst/include/ensmallen_bits/problems/maf/maf5_function.hpp @@ -23,8 +23,8 @@ namespace test { * \f[ * x_M = [x_i, n - M + 1 <= i <= n] * g(x) = \Sigma{i = n - M + 1}^n (x_i - 0.5)^2 - * - * f_1(x) = a^M * cos(x_1^alpha * pi * 0.5) * cos(x_2^alpha * pi * 0.5) * ... cos(x_2^alpha * pi * 0.5) * (1 + g(x_M)) + * + * f_1(x) = a^M * cos(x_1^alpha * pi * 0.5) * cos(x_2^alpha * pi * 0.5) * ... cos(x_2^alpha * pi * 0.5) * (1 + g(x_M)) * f_2(x) = a^M-1 * cos(x_1^alpha * pi * 0.5) * cos(x_2^alpha * pi * 0.5) * ... sin(x_M-1^alpha * pi * 0.5) * (1 + g(x_M)) * . * . @@ -35,9 +35,9 @@ namespace test { * 0 <= x_i <= 1 for i = 1,...,n. * * This should be optimized to x_i = 0.5 (for all x_i in x_M), at: - * + * * For more information, please refer to: - * + * * @code * @article{cheng2017benchmark, * title={A benchmark test suite for evolutionary many-objective optimization}, @@ -87,8 +87,8 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, 1, arma::fill::zeros); - } - + } + // Get the private variables. // Get the number of objectives. @@ -109,7 +109,7 @@ namespace test { /** * Set the scale factor a. - * + * * @param a The scale factor of the objectives. */ void SetA(double a) @@ -117,7 +117,7 @@ namespace test { /** * Set the power of each variable alpha. - * + * * @param alpha The power of each variable. */ void SetAlpha(size_t alpha) @@ -131,20 +131,19 @@ namespace test { */ arma::Row g(const MatType& coords) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + for (size_t i = numObjectives - 1; i < numVariables; i++) { - innerSum += arma::pow((coords.row(i) - 0.5), 2); - } - + innerSum += arma::pow((coords.row(i) - 0.5), 2); + } + return innerSum; - } + } /** * Evaluate the objectives with the given coordinate. @@ -162,22 +161,22 @@ namespace test { arma::Row value = (1.0 + G); for (size_t i = 0; i < numObjectives - 1; i++) { - objectives.row(i) = std::pow(a, i + 1) * arma::pow(value, 4) % - arma::pow(arma::sin(arma::pow(coords.row(i), alpha) * + objectives.row(i) = std::pow(a, i + 1) * arma::pow(value, 4) % + arma::pow(arma::sin(arma::pow(coords.row(i), alpha) * arma::datum::pi * 0.5), 4); - value = value % arma::cos(arma::pow(coords.row(i), alpha) * arma::datum::pi * 0.5); + value = value % arma::cos(arma::pow(coords.row(i), alpha) * arma::datum::pi * 0.5); } objectives.row(numObjectives - 1) = arma::pow(value, 4) * std::pow(a, numObjectives); return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct MAF5Objective { MAF5Objective(size_t stop, MAF5& maf): stop(stop), maf(maf) - {/* Nothing to do here.*/} - + {/* Nothing to do here.*/} + /** * Evaluate one objective with the given coordinate. * @@ -191,21 +190,21 @@ namespace test { ElemType value = 1.0; for (size_t i = 0; i < stop; i++) { - value = value * std::cos(std::pow(coords[i], maf.GetAlpha()) + value = value * std::cos(std::pow(coords[i], maf.GetAlpha()) * arma::datum::pi * 0.5); } if(stop != maf.GetNumObjectives() - 1) { - value = value * std::sin(std::pow(coords[stop], maf.GetAlpha()) + value = value * std::sin(std::pow(coords[stop], maf.GetAlpha()) * arma::datum::pi * 0.5); } value = value * (1 + maf.g(coords)[0]); value = std::pow(value, 4); - value = value * std::pow(maf.GetA(), stop + 1); + value = value * std::pow(maf.GetA(), stop + 1); return value; - } + } MAF5& maf; size_t stop; @@ -215,7 +214,7 @@ namespace test { std::tuple GetObjectives() { return std::make_tuple(objectiveF1, objectiveF2, objectiveF3); - } + } MAF5Objective objectiveF1; MAF5Objective objectiveF2; @@ -224,4 +223,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif diff --git a/inst/include/ensmallen_bits/problems/maf/maf6_function.hpp b/inst/include/ensmallen_bits/problems/maf/maf6_function.hpp index e443e5c..e023906 100644 --- a/inst/include/ensmallen_bits/problems/maf/maf6_function.hpp +++ b/inst/include/ensmallen_bits/problems/maf/maf6_function.hpp @@ -21,8 +21,8 @@ namespace test { * \f[ * theta_M = [theta_i, n - M + 1 <= i <= n] * g(x) = \Sigma{i = n - M + 1}^n (x_i - 0.5)^2 - * - * f_1(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... cos(theta_2 * pi * 0.5) * (1 + g(theta_M)) + * + * f_1(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... cos(theta_2 * pi * 0.5) * (1 + g(theta_M)) * f_2(x) = 0.5 * cos(theta_1 * pi * 0.5) * cos(theta_2 * pi * 0.5) * ... sin(theta_M-1 * pi * 0.5) * (1 + g(theta_M)) * . * . @@ -31,13 +31,13 @@ namespace test { * * Bounds of the variable space is: * 0 <= x_i <= 1 for i = 1,...,n. - * + * * Where theta_i = 0.5 * (1 + 2 * g(X_M) * x_i) / (1 + g(X_M)) - * + * * This should be optimized to x_i = 0.5 (for all x_i in X_M), at: - * + * * For more information, please refer to: - * + * * @code * @article{cheng2017benchmark, * title={A benchmark test suite for evolutionary many-objective optimization}, @@ -85,13 +85,13 @@ namespace test { typedef typename MatType::elem_type ElemType; return arma::Col(numVariables, 1, arma::fill::zeros); } - + // Get the private variables. - + // Get the number of objectives. size_t GetNumObjectives() { return this -> numObjectives; } - + // Get the number of variables. size_t GetNumVariables() { return this -> numVariables; } @@ -116,20 +116,19 @@ namespace test { */ arma::Row g(const MatType& coords) { - size_t k = numVariables - numObjectives + 1; // Convenience typedef. typedef typename MatType::elem_type ElemType; - + arma::Row innerSum(size(coords)[1], arma::fill::zeros); - + for (size_t i = numObjectives - 1; i < numVariables; i++) { - innerSum += arma::pow((coords.row(i) - 0.5), 2); - } - + innerSum += arma::pow((coords.row(i) - 0.5), 2); + } + return innerSum; - } + } /** * Evaluate the objectives with the given coordinate. @@ -143,34 +142,34 @@ namespace test { typedef typename MatType::elem_type ElemType; arma::Mat objectives(numObjectives, size(coords)[1]); - arma::Row G = g(coords); + arma::Row G = g(coords); arma::Row value = (1.0 + 100 * G); arma::Row theta; for (size_t i = 0; i < numObjectives - 1; i++) { if(i < I) - { + { theta = coords.row(i) * arma::datum::pi * 0.5; } else { theta = 0.25 * (1.0 + 2.0 * coords.row(i) % G) / (1.0 + G); } - objectives.row(i) = value % + objectives.row(i) = value % arma::sin(theta); - value = value % arma::cos(theta); + value = value % arma::cos(theta); } objectives.row(numObjectives - 1) = value; return objectives; } - + // Individual Objective function. - // Changes based on stop variable provided. + // Changes based on stop variable provided. struct MAF6Objective { MAF6Objective(size_t stop, MAF6& maf): stop(stop), maf(maf) {/* Nothing to do here. */} - + /** * Evaluate one objective with the given coordinate. * @@ -212,8 +211,8 @@ namespace test { } value = value * (1.0 + 100 * G); - return value; - } + return value; + } MAF6& maf; size_t stop; @@ -232,4 +231,4 @@ namespace test { } //namespace test } //namespace ens -#endif \ No newline at end of file +#endif