diff --git a/include/ensmallen_bits/problems/maf/maf1_function.hpp b/include/ensmallen_bits/problems/maf/maf1_function.hpp index 02b34f27a..0b2f13306 100644 --- a/include/ensmallen_bits/problems/maf/maf1_function.hpp +++ b/include/ensmallen_bits/problems/maf/maf1_function.hpp @@ -58,7 +58,6 @@ namespace test { // A fixed no. of Objectives and Variables(|x| = 7, M = 3). size_t numObjectives {3}; size_t numVariables {12}; - size_t numParetoPoints; public: @@ -68,30 +67,21 @@ namespace test { * * @param numParetoPoint No. of pareto points in the reference front. */ - MAF1 (size_t numParetoPoint = 136) : - numParetoPoints(numParetoPoint), - objectiveF1(0, *this), - objectiveF2(1, *this), - objectiveF3(2, *this) + MAF1() : + objectiveF1(0, *this), + objectiveF2(1, *this), + objectiveF3(2, *this) {/* Nothing to do here */} // Get the private variables. - size_t GetNumObjectives () + size_t GetNumObjectives() { return this -> numObjectives; } - size_t GetNumVariables () + size_t GetNumVariables() { return this -> numVariables; } - /** - * Set the no. of pareto points. - * - * @param numParetoPoint - */ - void SetNumParetoPoint (size_t numParetoPoint) - { this -> numParetoPoints = numParetoPoint; } - // Get the starting point. - arma::Col GetInitialPoint () + arma::Col GetInitialPoint() { // Convenience typedef. typedef typename MatType::elem_type ElemType; @@ -104,14 +94,14 @@ namespace test { * @param coords The function coordinates. * @return arma::Row */ - arma::Row g (const MatType& coords) + arma::Row g(const MatType& coords) { // 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++) + for (size_t i = numObjectives - 1;i < numVariables;i++) { innerSum += arma::pow((coords.row(i) - 0.5), 2); } @@ -125,7 +115,7 @@ namespace test { * @param coords The function coordinates. * @return arma::Mat */ - arma::Mat Evaluate (const MatType& coords) + arma::Mat Evaluate(const MatType& coords) { // Convenience typedef. typedef typename MatType::elem_type ElemType; @@ -133,7 +123,7 @@ namespace test { arma::Mat objectives(numObjectives, size(coords)[1]); arma::Row G = g(coords); arma::Row value(coords.n_cols, arma::fill::ones); - for(size_t i = 0;i < numObjectives - 1;i++) + for (size_t i = 0;i < numObjectives - 1;i++) { objectives.row(i) = (1 - value % (1.0 - coords.row(i))) % (1. + G); value = value % coords.row(i); @@ -146,7 +136,7 @@ namespace test { // Changes based on stop variable provided. struct MAF1Objective { - MAF1Objective (size_t stop, MAF1& maf): stop(stop), maf(maf) + MAF1Objective(size_t stop, MAF1& maf): stop(stop), maf(maf) {/* Nothing to do here. */} /** @@ -155,10 +145,10 @@ namespace test { * @param coords The function coordinates. * @return arma::Col */ - typename MatType::elem_type Evaluate (const MatType& coords) + typename MatType::elem_type Evaluate(const MatType& coords) { // Convenience typedef. - if (stop == 0) + if(stop == 0) { return coords[0] * (1. + maf.g(coords)[0]); } diff --git a/include/ensmallen_bits/problems/maf/maf2_function.hpp b/include/ensmallen_bits/problems/maf/maf2_function.hpp index 1b2947397..697b26bf0 100644 --- a/include/ensmallen_bits/problems/maf/maf2_function.hpp +++ b/include/ensmallen_bits/problems/maf/maf2_function.hpp @@ -70,8 +70,7 @@ namespace test { * * @param numParetoPoint No. of pareto points in the reference front. */ - MAF2(size_t numParetoPoints = 136) : - numParetoPoints(numParetoPoints), + MAF2() : objectiveF1(0, *this), objectiveF2(1, *this), objectiveF3(2, *this) @@ -95,14 +94,6 @@ namespace test { size_t GetNumVariables() { return this -> numVariables; } - /** - * Set the no. of pareto points. - * - * @param numParetoPoint The no. points in the reference front. - */ - void SetNumParetoPoint(size_t numParetoPoint) - { this -> numParetoPoints = numParetoPoint; } - /** * Evaluate the G(x) with the given coordinate. * @@ -116,12 +107,13 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; - arma::Mat innerSum(numObjectives, size(coords)[1], arma::fill::zeros); + arma::Mat innerSum(numObjectives, size(coords)[1], + arma::fill::zeros); for (size_t i = 0; i < numObjectives; i++) { size_t j = numObjectives - 1 + (i * c); - for(; j < numVariables + (i + 1) *c && j < numObjectives; i++) + for(; j < numVariables - 1 + (i + 1) *c && j < numObjectives; j++) { innerSum.row(i) += arma::pow((coords.row(i) - 0.5), 2) * 0.25; } @@ -143,16 +135,17 @@ namespace test { arma::Mat objectives(numObjectives, size(coords)[1]); arma::Mat G = g(coords); - arma::Row value(numObjectives, arma::fill::ones); + arma::Row value(size(coords)[1], arma::fill::ones); arma::Row theta; for (size_t i = 0; i < numObjectives - 1; i++) { - theta = arma::datum::pi * 0.5 * (coords.row(i) / 2 + 0.25); + theta = arma::datum::pi * 0.5 * ((coords.row(i) / 2) + 0.25); objectives.row(i) = value % arma::sin(theta) % (1.0 + G.row(numObjectives - 1 - i)); value = value % arma::cos(theta); } - objectives.row(numObjectives - 1) = value; + objectives.row(numObjectives - 1) = value % + (1.0 + G.row(0)); return objectives; } @@ -178,18 +171,14 @@ namespace test { arma::Col G = maf.g(coords).col(0); for (size_t i = 0; i < stop; i++) { - theta = arma::datum::pi * 0.5 * (coords[i] / 2 + 0.25); + theta = arma::datum::pi * 0.5 * ((coords[i] / 2) + 0.25); value = value * std::cos(theta); } - theta = arma::datum::pi * 0.5 * (coords[stop] / 2 + 0.25); - if (stop != maf.numObjectives - 1) + theta = arma::datum::pi * 0.5 * ((coords[stop] / 2) + 0.25); + if(stop != maf.numObjectives - 1) { value = value * std::sin(theta); } - else - { - value = value * std::cos(theta); - } value = value * (1.0 + G[maf.GetNumObjectives() - 1 - stop]); return value; diff --git a/include/ensmallen_bits/problems/maf/maf3_function.hpp b/include/ensmallen_bits/problems/maf/maf3_function.hpp index 385954041..4ea096387 100644 --- a/include/ensmallen_bits/problems/maf/maf3_function.hpp +++ b/include/ensmallen_bits/problems/maf/maf3_function.hpp @@ -56,10 +56,9 @@ namespace test { { private: - // A fixed no. of Objectives and Variables(|x| = 7, M = 3). + // A fixed no. of Objectives and Variables(|x| = 12, M = 3). size_t numObjectives {3}; size_t numVariables {12}; - size_t numParetoPoints; public: @@ -69,11 +68,10 @@ namespace test { * * @param numParetoPoint No. of pareto points in the reference front. */ - MAF3(size_t numParetoPoints = 136) : - numParetoPoints(numParetoPoints), + MAF3() : objectiveF1(0, *this), objectiveF2(1, *this), - objectiveF3(2, *this) + objectiveF3(2, *this) {/*Nothing to do here.*/} //! Get the starting point. @@ -94,14 +92,6 @@ namespace test { size_t GetNumVariables() { return this -> numVariables;} - /** - * Set the no. of pareto points. - * - * @param numParetoPoint No. of pareto points in the reference front. - */ - void SetNumParetoPoint(size_t numParetoPoint) - { this -> numParetoPoints = numParetoPoint;} - /** * Evaluate the G(x) with the given coordinate. * @@ -173,14 +163,14 @@ namespace test { value = value * std::cos(coords[i] * arma::datum::pi * 0.5); } - if (stop != maf.GetNumObjectives() - 1) + if(stop != maf.GetNumObjectives() - 1) { value = value * std::sin(coords[stop] * arma::datum::pi * 0.5); } value = value * (1. + maf.g(coords)[0]); - if (stop == 0) { + if(stop == 0) { return std::pow(value, 2); } return std::pow(value, 4); diff --git a/include/ensmallen_bits/problems/maf/maf4_function.hpp b/include/ensmallen_bits/problems/maf/maf4_function.hpp index 3826d3f54..92584681b 100644 --- a/include/ensmallen_bits/problems/maf/maf4_function.hpp +++ b/include/ensmallen_bits/problems/maf/maf4_function.hpp @@ -60,7 +60,6 @@ namespace test { size_t numObjectives {3}; size_t numVariables {12}; double a; - size_t numParetoPoints; public: @@ -71,12 +70,11 @@ namespace test { * @param numParetoPoint No. of pareto points in the reference front. * @param a The scale factor of the objectives. */ - MAF4(size_t numParetoPoints = 136, double a = 2) : - numParetoPoints(numParetoPoints), - objectiveF1(0, *this), - objectiveF2(1, *this), - objectiveF3(2, *this), - a(a) + MAF4(double a = 2) : + objectiveF1(0, *this), + objectiveF2(1, *this), + objectiveF3(2, *this), + a(a) {/*Nothing to do here.*/} //! Get the starting point. @@ -101,14 +99,6 @@ namespace test { size_t GetA() { return this -> a; } - /** - * Set the no. of pareto points. - * - * @param numParetoPoint No. of pareto points in the reference front. - */ - void SetNumParetoPoint(size_t numParetoPoint) - { this -> numParetoPoints = numParetoPoint;} - /** * Set the scale factor of the objectives. * @@ -132,7 +122,7 @@ namespace test { arma::Row innerSum(size(coords)[1], arma::fill::zeros); - for(size_t i = numObjectives - 1; i < numVariables; i++) + for (size_t i = numObjectives - 1; i < numVariables; i++) { innerSum += arma::pow((coords.row(i) - 0.5), 2) - arma::cos(20 * arma::datum::pi * (coords.row(i) - 0.5)); @@ -155,7 +145,7 @@ namespace test { arma::Mat objectives(numObjectives, size(coords)[1]); arma::Row G = g(coords); arma::Row value(coords.n_cols, arma::fill::ones); - for(size_t i = 0; i < numObjectives - 1; i++) + for (size_t i = 0; i < numObjectives - 1; i++) { objectives.row(i) = (1.0 - value % arma::sin(coords.row(i) * arma::datum::pi * 0.5)) % (1. + G) * @@ -185,7 +175,7 @@ namespace test { // Convenience typedef. typedef typename MatType::elem_type ElemType; ElemType value = 1.0; - for(size_t i = 0; i < stop; i++) + for (size_t i = 0; i < stop; i++) { value = value * std::cos(coords[i] * arma::datum::pi * 0.5); } @@ -195,7 +185,7 @@ namespace test { value = value * std::sin(coords[stop] * arma::datum::pi * 0.5); } - value = std::pow(maf.GetA(), maf.GetNumObjectives() - stop) * + value = std::pow(maf.GetA(), maf.GetNumObjectives() - stop) * (1 - value) * (1. + maf.g(coords)[0]); return value; diff --git a/include/ensmallen_bits/problems/maf/maf5_function.hpp b/include/ensmallen_bits/problems/maf/maf5_function.hpp index 435b8d4e9..65c1b8d33 100644 --- a/include/ensmallen_bits/problems/maf/maf5_function.hpp +++ b/include/ensmallen_bits/problems/maf/maf5_function.hpp @@ -60,7 +60,6 @@ namespace test { // A fixed no. of Objectives and Variables(|x| = 7, M = 3). size_t numObjectives {3}; size_t numVariables {12}; - size_t numParetoPoints; size_t alpha; size_t a; @@ -74,9 +73,8 @@ namespace test { * @param numParetoPoint No. of pareto points in the reference front. * @param a The scale factor of the objectives. */ - MAF5(size_t alpha = 100, size_t numParetoPoints = 136, double a = 2) : + MAF5(size_t alpha = 100, double a = 2) : alpha(alpha), - numParetoPoints(numParetoPoints), a(a), objectiveF1(0, *this), objectiveF2(1, *this), @@ -125,14 +123,6 @@ namespace test { void SetAlpha(size_t alpha) { this -> alpha = alpha; } - /** - * Set the no. of pareto points. - * - * @param numParetoPoint - */ - void SetNumParetoPoint(size_t numParetoPoint) - { this -> numParetoPoints = numParetoPoint; } - /** * Evaluate the G(x) with the given coordinate. * @@ -205,7 +195,7 @@ namespace test { * arma::datum::pi * 0.5); } - if (stop != maf.GetNumObjectives() - 1) + if(stop != maf.GetNumObjectives() - 1) { value = value * std::sin(std::pow(coords[stop], maf.GetAlpha()) * arma::datum::pi * 0.5); diff --git a/include/ensmallen_bits/problems/maf/maf6_function.hpp b/include/ensmallen_bits/problems/maf/maf6_function.hpp index 4b33be953..e443e5c81 100644 --- a/include/ensmallen_bits/problems/maf/maf6_function.hpp +++ b/include/ensmallen_bits/problems/maf/maf6_function.hpp @@ -61,7 +61,6 @@ namespace test { size_t numObjectives {3}; size_t numVariables {12}; size_t I; - size_t numParetoPoints; public: @@ -72,8 +71,7 @@ namespace test { * @param numParetoPoint No. of pareto points in the reference front. * @param I The manifold dimension (zero indexed). */ - MAF6(size_t numParetoPoints = 136, size_t I = 2) : - numParetoPoints(numParetoPoints), + MAF6(size_t I = 2) : objectiveF1(0, *this), objectiveF2(1, *this), objectiveF3(2, *this), @@ -99,17 +97,9 @@ namespace test { { return this -> numVariables; } // Get the manifold dimension. - size_t GetI(size_t I) + size_t GetI() { return this -> I; } - /** - * Set the no. of pareto points. - * - * @param numParetoPoint The no. points in the reference front. - */ - void SetNumParetoPoint(size_t numParetoPoint) - { this -> numParetoPoints = numParetoPoint; } - /** * Set the no. of pareto points. * @@ -158,9 +148,9 @@ namespace test { arma::Row theta; for (size_t i = 0; i < numObjectives - 1; i++) { - if (i < I - 1) + if(i < I) { - theta = coords.row(i) * arma::datum::pi * 0.5; + theta = coords.row(i) * arma::datum::pi * 0.5; } else { @@ -178,7 +168,7 @@ namespace test { // Changes based on stop variable provided. struct MAF6Objective { - MAF6Objective(size_t stop, MAF6& dtlz): stop(stop), maf(maf) + MAF6Objective(size_t stop, MAF6& maf): stop(stop), maf(maf) {/* Nothing to do here. */} /** @@ -196,15 +186,21 @@ namespace test { ElemType G = maf.g(coords)[0]; for (size_t i = 0; i < stop; i++) { - if (i < maf.GetI() - 1){ theta = arma::datum::pi * coords[i] * 0.5; } + if(i < maf.GetI()) + { + theta = arma::datum::pi * coords[i] * 0.5; + } else { theta = 0.25 * (1.0 + 2.0 * coords[i] * G) / (1.0 + G); } - value = value * std::cos(theta * arma::datum::pi * 0.5); + value = value * std::cos(theta); } - if (stop < maf.GetI() - 1){ theta = arma::datum::pi * coords[stop] * 0.5; } + if(stop < maf.GetI()) + { + theta = arma::datum::pi * coords[stop] * 0.5; + } else { theta = 0.25 * (1.0 + 2.0 * coords[stop] * G) / (1.0 + G); @@ -212,7 +208,7 @@ namespace test { if (stop != maf.GetNumObjectives() - 1) { - value = value * std::sin(theta * arma::datum::pi * 0.5); + value = value * std::sin(theta); } value = value * (1.0 + 100 * G);