From e8506960a06ea524fa1e4d376025bca508b44633 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sat, 20 Mar 2021 09:45:28 +0530 Subject: [PATCH 01/49] Changes (See below) => Fix crowdingAssignment => Type robust => Add bounds to initial population => Reduced if / for blocks => Added float test => Minor additional docs --- HISTORY.md | 3 + include/ensmallen_bits/nsga2/nsga2.hpp | 23 +- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 101 ++++++--- tests/nsga2_test.cpp | 228 +++++++++++++++++++- 4 files changed, 309 insertions(+), 46 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5623e05f2..8f4cc598c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,9 @@ ([#270](https://github.com/mlpack/ensmallen/pull/270), [#271](https://github.com/mlpack/ensmallen/pull/271)). + * Refactor NSGA2 + ([#263](https://github.com/mlpack/ensmallen/pull/263)). + ### ensmallen 2.16.1: "Severely Dented Can Of Polyurethane" ###### 2021-03-02 * Fix test compilation issue when `ENS_USE_OPENMP` is set diff --git a/include/ensmallen_bits/nsga2/nsga2.hpp b/include/ensmallen_bits/nsga2/nsga2.hpp index ffaaaaab9..5a315152a 100644 --- a/include/ensmallen_bits/nsga2/nsga2.hpp +++ b/include/ensmallen_bits/nsga2/nsga2.hpp @@ -188,7 +188,7 @@ class NSGA2 { typename std::enable_if::type EvaluateObjectives(std::vector&, std::tuple&, - std::vector >&); + std::vector >&); template::type EvaluateObjectives(std::vector& population, std::tuple& objectives, - std::vector >& calculatedObjectives); + std::vector >& + calculatedObjectives); /** * Reproduce candidates from the elite population to generate a new @@ -281,11 +282,15 @@ class NSGA2 { * Assigns crowding distance metric for sorting. * * @param front The previously generated Pareto fronts. - * @param objectives The set of objectives. - * @param crowdingDistance The previously calculated objectives. + * @param calculatedObjectives The previously calculated objectives. + * @param crowdingDistance The crowding distance for each individual in + * the population. */ - void CrowdingDistanceAssignment(const std::vector& front, - std::vector& crowdingDistance); + template + void CrowdingDistanceAssignment( + const std::vector& front, + std::vector>& calculatedObjectives, + std::vector& crowdingDistance); /** * The operator used in the crowding distance based sorting. @@ -299,13 +304,15 @@ class NSGA2 { * @param idxQ The index of the second cadidate from the elite population * being sorted. * @param ranks The previously calculated ranks. - * @param crowdingDistance The previously calculated objectives. + * @param crowdingDistance The crowding distance for each individual in + * the population. * @return true if the first candidate is preferred, otherwise, false. */ + template bool CrowdingOperator(size_t idxP, size_t idxQ, const std::vector& ranks, - const std::vector& crowdingDistance); + const std::vector& crowdingDistance); //! The number of objectives being optimised for. size_t numObjectives; diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 9b083be3c..ed07ddc8c 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -102,9 +102,10 @@ typename MatType::elem_type NSGA2::Optimize( population.reserve(2 * populationSize + 1); // Pareto fronts, initialized during non-dominated sorting. + // Stores indices of population belonging to a certain front. std::vector > fronts; // Initialised in CrowdingDistanceAssignment. - std::vector crowdingDistance; + std::vector crowdingDistance; // Initialised during non-dominated sorting. std::vector ranks; @@ -117,6 +118,16 @@ typename MatType::elem_type NSGA2::Optimize( { population.push_back(arma::randu(iterate.n_rows, iterate.n_cols) - 0.5 + iterate); + + // Ensure population is within variable space. + for (size_t geneIdx = 0; geneIdx < numVariables; geneIdx++) + { + if (population[i][geneIdx] < lowerBound[geneIdx]) + population[i][geneIdx] = lowerBound[geneIdx]; + + if (population[i][geneIdx] > upperBound[geneIdx]) + population[i][geneIdx] = upperBound[geneIdx]; + } } Info << "NSGA2 initialized successfully. Optimization started." << std::endl; @@ -150,10 +161,11 @@ typename MatType::elem_type NSGA2::Optimize( // Perform crowding distance assignment. crowdingDistance.resize(population.size()); - + std::fill(crowdingDistance.begin(), crowdingDistance.end(), 0.); for (size_t fNum = 0; fNum < fronts.size(); fNum++) { - CrowdingDistanceAssignment(fronts[fNum], crowdingDistance); + CrowdingDistanceAssignment( + fronts[fNum], calculatedObjectives, crowdingDistance); } // Sort based on crowding distance. @@ -171,11 +183,12 @@ typename MatType::elem_type NSGA2::Optimize( idxQ = i; } - return CrowdingOperator(idxP, idxQ, ranks, crowdingDistance); + return CrowdingOperator(idxP, idxQ, ranks, crowdingDistance); } ); // Yield a new population P_{t+1} of size populationSize. + // Discards unfit population from the R_{t} to yield P_{t+1}. population.resize(populationSize); } @@ -186,16 +199,20 @@ typename MatType::elem_type NSGA2::Optimize( front.push_back(population[f]); // bestFront is stored, can be obtained by the Front() getter. - bestFront = front; + std::transform(front.begin(), front.end(), std::back_inserter(bestFront), + [&](const MatType& individual) + { + return arma::conv_to::from(individual); + }); // Assign iterate to first element of the best front. - iterate = bestFront[0]; + iterate = front[0]; Callback::EndOptimization(*this, objectives, iterate, callbacks...); ElemType performance = std::numeric_limits::max(); - for(arma::Col objective: calculatedObjectives) + for (const arma::Col& objective: calculatedObjectives) if (arma::accu(objective) < performance) performance = arma::accu(objective); @@ -210,7 +227,7 @@ typename std::enable_if::type NSGA2::EvaluateObjectives( std::vector&, std::tuple&, - std::vector >&) + std::vector >&) { // Nothing to do here. } @@ -223,7 +240,7 @@ typename std::enable_if::type NSGA2::EvaluateObjectives( std::vector& population, std::tuple& objectives, - std::vector >& calculatedObjectives) + std::vector >& calculatedObjectives) { for (size_t i = 0; i < populationSize; i++) { @@ -344,7 +361,7 @@ inline void NSGA2::FastNonDominatedSort( size_t i = 0; - while (fronts[i].size() > 0) + while (!fronts[i].empty()) { std::vector nextFront; @@ -365,6 +382,8 @@ inline void NSGA2::FastNonDominatedSort( i++; fronts.push_back(nextFront); } + // Remove the empty final set. + fronts.pop_back(); } //! Check if a candidate Pareto dominates another candidate. @@ -393,37 +412,59 @@ inline bool NSGA2::Dominates( } //! Assign crowding distance to the population. -inline void NSGA2::CrowdingDistanceAssignment(const std::vector& front, - std::vector& crowdingDistance) +template +inline void NSGA2::CrowdingDistanceAssignment( + const std::vector& front, + std::vector>& calculatedObjectives, + std::vector& crowdingDistance) { - if (front.size() > 0) - { - for (size_t elem: front) - crowdingDistance[elem] = 0; + // Convenience typedefs. + typedef typename MatType::elem_type ElemType; - size_t fSize = front.size(); + size_t fSize = front.size(); + // Stores the sorted indices of the fronts. + std::vector sortedIdx(fSize); + std::iota(sortedIdx.begin(), sortedIdx.end(), 0u); - for (size_t m = 0; m < numObjectives; m++) - { - crowdingDistance[front[0]] = std::numeric_limits::max(); - crowdingDistance[front[fSize - 1]] = std::numeric_limits::max(); + for (size_t m = 0; m < numObjectives; m++) + { + // Cache fValues of individuals for current objective. + arma::Col fValues(fSize); + std::transform(front.begin(), front.end(), fValues.begin(), + [&](const size_t& individual) + { + return calculatedObjectives[individual](m); + }); - for (size_t i = 1; i < fSize - 1 ; i++) - { - crowdingDistance[front[i]] += (crowdingDistance[front[i - 1]] - - crowdingDistance[front[i + 1]]) / - (std::numeric_limits::max() - - std::numeric_limits::min()); - } + // Sort front indices by ascending fValues for current objective. + std::sort(sortedIdx.begin(), sortedIdx.end(), + [&](const size_t& frontIdxA, const size_t& frontIdxB) + { + return (fValues[frontIdxA] < fValues[frontIdxB]); + }); + + crowdingDistance[front[sortedIdx[0]]] = + std::numeric_limits::max(); + crowdingDistance[front[sortedIdx[fSize - 1]]] = + std::numeric_limits::max(); + ElemType minFval = fValues[sortedIdx[0]]; + ElemType maxFval = fValues[sortedIdx[fSize - 1]]; + ElemType scale = (maxFval == minFval) ? 1 : maxFval - minFval; + + for (size_t i = 1; i < fSize - 1; i++) + { + crowdingDistance[front[sortedIdx[i]]] += + (fValues[sortedIdx[i + 1]] - fValues[sortedIdx[i - 1]]) / scale; + } } - } } //! Comparator for crowding distance based sorting. +template inline bool NSGA2::CrowdingOperator(size_t idxP, size_t idxQ, const std::vector& ranks, - const std::vector& crowdingDistance) + const std::vector& crowdingDistance) { if (ranks[idxP] < ranks[idxQ]) return true; diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index e1737b1af..2beb2e3a7 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -22,18 +22,21 @@ using namespace std; * @param value The value being checked. * @param low The lower bound. * @param high The upper bound. + * @tparam The type of elements in the population set. * @return true if value lies in the range [low, high]. * @return false if value does not lie in the range [low, high]. */ -bool IsInBounds(const double& value, const double& low, const double& high) +template +bool IsInBounds(const ElemType& value, const ElemType& low, const ElemType& high) { return !(value < low) && !(high < value); } /** * Optimize for the Schaffer N.1 function using NSGA-II optimizer. + * Tests for data of type double. */ -TEST_CASE("NSGA2SchafferN1Test", "[NSGA2Test]") +TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") { SchafferFunctionN1 SCH; const double lowerBound = -1000; @@ -79,8 +82,9 @@ TEST_CASE("NSGA2SchafferN1Test", "[NSGA2Test]") /** * Optimize for the Schaffer N.1 function using NSGA-II optimizer. + * Tests for data of type double. */ -TEST_CASE("NSGA2SchafferN1TestVectorBounds", "[NSGA2Test]") +TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") { // This test can be a little flaky, so we try it a few times. SchafferFunctionN1 SCH; @@ -126,8 +130,9 @@ TEST_CASE("NSGA2SchafferN1TestVectorBounds", "[NSGA2Test]") /** * Optimize for the Fonseca Fleming function using NSGA-II optimizer. + * Tests for data of type double. */ -TEST_CASE("NSGA2FonsecaFlemingTest", "[NSGA2Test]") +TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") { FonsecaFlemingFunction FON; const double lowerBound = -4; @@ -157,9 +162,9 @@ TEST_CASE("NSGA2FonsecaFlemingTest", "[NSGA2Test]") double valY = arma::as_scalar(solution(1)); double valZ = arma::as_scalar(solution(2)); - if (!IsInBounds(valX, expectedLowerBound, expectedUpperBound) || - !IsInBounds(valY, expectedLowerBound, expectedUpperBound) || - !IsInBounds(valZ, expectedLowerBound, expectedUpperBound)) + if (!IsInBounds(valX, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valY, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valZ, expectedLowerBound, expectedUpperBound)) { allInRange = false; break; @@ -170,8 +175,9 @@ TEST_CASE("NSGA2FonsecaFlemingTest", "[NSGA2Test]") /** * Optimize for the Fonseca Fleming function using NSGA-II optimizer. + * Tests for data of type double. */ -TEST_CASE("NSGA2FonsecaFlemingTestVectorBounds", "[NSGA2Test]") +TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") { FonsecaFlemingFunction FON; const arma::vec lowerBound = {-4, -4, -4}; @@ -211,3 +217,209 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorBounds", "[NSGA2Test]") } REQUIRE(allInRange); } + +/** + * @brief Convert the individuals from pareto front to requested data type. + * + * @tparam MatType The type to be casted to. + * @param bestFront Vector containing individuals from the pareto front. + * @return std::vector The casted individuals. + */ +template +std::vector castFront(const std::vector& bestFront) +{ + std::vector castedFront; + std::transform(bestFront.begin(), bestFront.end(), std::back_inserter(castedFront), + [&](const arma::mat& individual) + { + return arma::conv_to::from(individual); + }); + + return castedFront; +} + +/** + * Optimize for the Schaffer N.1 function using NSGA-II optimizer. + * Tests for data of type float. + */ +TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") +{ + SchafferFunctionN1 SCH; + const double lowerBound = -1000; + const double upperBound = 1000; + + NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + + typedef decltype(SCH.objectiveA) ObjectiveTypeA; + typedef decltype(SCH.objectiveB) ObjectiveTypeB; + + // We allow a few trials in case of poor convergence. + bool success = false; + for (size_t trial = 0; trial < 3; ++trial) + { + arma::fmat coords = SCH.GetInitialPoint(); + std::tuple objectives = SCH.GetObjectives(); + + opt.Optimize(objectives, coords); + std::vector bestFront = castFront(opt.Front()); + + bool allInRange = true; + + for (arma::fmat solution: bestFront) + { + float val = arma::as_scalar(solution); + + if (val < 0.f || val > 2.f) + { + allInRange = false; + break; + } + } + + if (allInRange) + { + success = true; + break; + } + } + + REQUIRE(success == true); +} + +/** + * Optimize for the Schaffer N.1 function using NSGA-II optimizer. + * Tests for data of type float. + */ +TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") +{ + // This test can be a little flaky, so we try it a few times. + SchafferFunctionN1 SCH; + const arma::vec lowerBound = {-1000}; + const arma::vec upperBound = {1000}; + + NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + + typedef decltype(SCH.objectiveA) ObjectiveTypeA; + typedef decltype(SCH.objectiveB) ObjectiveTypeB; + + bool success = false; + for (size_t trial = 0; trial < 3; ++trial) + { + arma::fmat coords = SCH.GetInitialPoint(); + std::tuple objectives = SCH.GetObjectives(); + + opt.Optimize(objectives, coords); + std::vector bestFront = castFront(opt.Front()); + + bool allInRange = true; + + for (arma::fmat solution: bestFront) + { + float val = arma::as_scalar(solution); + + if (val < 0.f || val > 2.f) + { + allInRange = false; + break; + } + } + + if (allInRange) + { + success = true; + break; + } + } + + REQUIRE(success == true); +} + +/** + * Optimize for the Fonseca Fleming function using NSGA-II optimizer. + * Tests for data of type float. + */ +TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") +{ + FonsecaFlemingFunction FON; + const double lowerBound = -4; + const double upperBound = 4; + const double tolerance = 1e-6; + const double strength = 1e-4; + const float expectedLowerBound = -1.0 / sqrt(3); + const float expectedUpperBound = 1.0 / sqrt(3); + + NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + + typedef decltype(FON.objectiveA) ObjectiveTypeA; + typedef decltype(FON.objectiveB) ObjectiveTypeB; + + arma::fmat coords = FON.GetInitialPoint(); + std::tuple objectives = FON.GetObjectives(); + + opt.Optimize(objectives, coords); + std::vector bestFront = castFront(opt.Front()); + + bool allInRange = true; + + for (size_t i = 0; i < bestFront.size(); i++) + { + const arma::fmat solution = bestFront[i]; + float valX = arma::as_scalar(solution(0)); + float valY = arma::as_scalar(solution(1)); + float valZ = arma::as_scalar(solution(2)); + + if (!IsInBounds(valX, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valY, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valZ, expectedLowerBound, expectedUpperBound)) + { + allInRange = false; + break; + } + } + REQUIRE(allInRange); +} + +/** + * Optimize for the Fonseca Fleming function using NSGA-II optimizer. + * Tests for data of type float. + */ +TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") +{ + FonsecaFlemingFunction FON; + const arma::vec lowerBound = {-4, -4, -4}; + const arma::vec upperBound = {4, 4, 4}; + const double tolerance = 1e-6; + const double strength = 1e-4; + const float expectedLowerBound = -1.0 / sqrt(3); + const float expectedUpperBound = 1.0 / sqrt(3); + + NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + + typedef decltype(FON.objectiveA) ObjectiveTypeA; + typedef decltype(FON.objectiveB) ObjectiveTypeB; + + arma::fmat coords = FON.GetInitialPoint(); + std::tuple objectives = FON.GetObjectives(); + + opt.Optimize(objectives, coords); + std::vector bestFront = castFront(opt.Front()); + + bool allInRange = true; + + for (size_t i = 0; i < bestFront.size(); i++) + { + const arma::fmat solution = bestFront[i]; + float valX = arma::as_scalar(solution(0)); + float valY = arma::as_scalar(solution(1)); + float valZ = arma::as_scalar(solution(2)); + + if (!IsInBounds(valX, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valY, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valZ, expectedLowerBound, expectedUpperBound)) + { + allInRange = false; + break; + } + } + REQUIRE(allInRange); +} \ No newline at end of file From b2f525f5aa9682c4dc9f14473ed5d5ddb6a6347e Mon Sep 17 00:00:00 2001 From: NanuSai Date: Mon, 22 Mar 2021 17:47:18 +0530 Subject: [PATCH 02/49] allow floatonly --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index ed07ddc8c..8d4d41184 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -61,7 +61,7 @@ template typename MatType::elem_type NSGA2::Optimize( std::tuple& objectives, - MatType& iterate, + MatType& iterateIn, CallbackTypes&&... callbacks) { // Make sure for evolution to work at least four candidates are present. @@ -71,6 +71,13 @@ typename MatType::elem_type NSGA2::Optimize( " least 4, and, a multiple of 4!"); } + // Convenience typedefs. + typedef typename MatType::elem_type ElemType; + typedef typename MatTypeTraits::BaseMatType BaseMatType; + + BaseMatType& iterate = (BaseMatType&) iterateIn; + RequireDenseFloatingPointType(); + // Check if lower bound is a vector of a single dimension. if (lowerBound.n_rows == 1) lowerBound = lowerBound(0, 0) * arma::ones(iterate.n_rows, iterate.n_cols); @@ -85,9 +92,6 @@ typename MatType::elem_type NSGA2::Optimize( assert(upperBound.n_rows == iterate.n_rows && "The dimensions of " "upperBound are not the same as the dimensions of iterate."); - // Convenience typedefs. - typedef typename MatType::elem_type ElemType; - numObjectives = sizeof...(ArbitraryFunctionType); numVariables = iterate.n_rows; @@ -98,7 +102,7 @@ typename MatType::elem_type NSGA2::Optimize( // Population size reserved to 2 * populationSize + 1 to accommodate // for the size of intermediate candidate population. - std::vector population; + std::vector population; population.reserve(2 * populationSize + 1); // Pareto fronts, initialized during non-dominated sorting. @@ -116,7 +120,7 @@ typename MatType::elem_type NSGA2::Optimize( // starting point. for (size_t i = 0; i < populationSize; i++) { - population.push_back(arma::randu(iterate.n_rows, + population.push_back(arma::randu(iterate.n_rows, iterate.n_cols) - 0.5 + iterate); // Ensure population is within variable space. @@ -157,21 +161,21 @@ typename MatType::elem_type NSGA2::Optimize( // Perform fast non dominated sort on P_t ∪ G_t. ranks.resize(population.size()); - FastNonDominatedSort(fronts, ranks, calculatedObjectives); + FastNonDominatedSort(fronts, ranks, calculatedObjectives); // Perform crowding distance assignment. crowdingDistance.resize(population.size()); std::fill(crowdingDistance.begin(), crowdingDistance.end(), 0.); for (size_t fNum = 0; fNum < fronts.size(); fNum++) { - CrowdingDistanceAssignment( + CrowdingDistanceAssignment( fronts[fNum], calculatedObjectives, crowdingDistance); } // Sort based on crowding distance. std::sort(population.begin(), population.end(), - [this, ranks, crowdingDistance, population](MatType candidateP, - MatType candidateQ) + [this, ranks, crowdingDistance, population](BaseMatType candidateP, + BaseMatType candidateQ) { size_t idxP, idxQ; for (size_t i = 0; i < population.size(); i++) @@ -183,7 +187,7 @@ typename MatType::elem_type NSGA2::Optimize( idxQ = i; } - return CrowdingOperator(idxP, idxQ, ranks, crowdingDistance); + return CrowdingOperator(idxP, idxQ, ranks, crowdingDistance); } ); @@ -193,14 +197,14 @@ typename MatType::elem_type NSGA2::Optimize( } // Set the candidates from the best front as the output. - std::vector front; + std::vector front; for (size_t f: fronts[0]) front.push_back(population[f]); // bestFront is stored, can be obtained by the Front() getter. std::transform(front.begin(), front.end(), std::back_inserter(bestFront), - [&](const MatType& individual) + [&](const BaseMatType& individual) { return arma::conv_to::from(individual); }); From b12d050fd5a309a208a05b60e139a7063536a254 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Mon, 22 Mar 2021 17:47:32 +0530 Subject: [PATCH 03/49] a minor change to spot error(will be removed) --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index a312289cd..92d23511a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -50,7 +50,7 @@ build_script: -DCMAKE_BUILD_TYPE=Release .. - > "%MSBUILD%" "ensmallen.sln" - /m /verbosity:minimal /nologo /p:BuildInParallel=true + /m /verbosity:minimal /nologo /p:BuildInParallel=false # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ From e508278039da5dacae3e992e22001b4e72df7911 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Mon, 22 Mar 2021 18:01:32 +0530 Subject: [PATCH 04/49] single threaded --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 92d23511a..f1a0960a7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -50,7 +50,7 @@ build_script: -DCMAKE_BUILD_TYPE=Release .. - > "%MSBUILD%" "ensmallen.sln" - /m /verbosity:minimal /nologo /p:BuildInParallel=false + /m:1 /verbosity:minimal /nologo /p:BuildInParallel=false # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ From 31e96e2bb421d8d30b3a12edea49879e1efac48b Mon Sep 17 00:00:00 2001 From: NanuSai Date: Mon, 22 Mar 2021 20:21:54 +0530 Subject: [PATCH 05/49] make class template --- include/ensmallen_bits/nsga2/nsga2.hpp | 1 + include/ensmallen_bits/nsga2/nsga2_impl.hpp | 37 +++++++++++++-------- tests/callbacks_test.cpp | 2 +- tests/nsga2_test.cpp | 16 ++++----- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2.hpp b/include/ensmallen_bits/nsga2/nsga2.hpp index 5a315152a..be6db9bbf 100644 --- a/include/ensmallen_bits/nsga2/nsga2.hpp +++ b/include/ensmallen_bits/nsga2/nsga2.hpp @@ -50,6 +50,7 @@ namespace ens { * see the documentation on function types included with this distribution or * on the ensmallen website. */ +template class NSGA2 { public: /** diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 8d4d41184..6fcbdc772 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -19,7 +19,8 @@ namespace ens { -inline NSGA2::NSGA2(const size_t populationSize, +template + NSGA2::NSGA2(const size_t populationSize, const size_t maxGenerations, const double crossoverProb, const double mutationProb, @@ -36,8 +37,8 @@ inline NSGA2::NSGA2(const size_t populationSize, lowerBound(lowerBound), upperBound(upperBound) { /* Nothing to do here. */ } - -inline NSGA2::NSGA2(const size_t populationSize, +template + NSGA2::NSGA2(const size_t populationSize, const size_t maxGenerations, const double crossoverProb, const double mutationProb, @@ -56,10 +57,11 @@ inline NSGA2::NSGA2(const size_t populationSize, { /* Nothing to do here. */ } //! Optimize the function. +template template -typename MatType::elem_type NSGA2::Optimize( +typename MatType::elem_type NSGA2::Optimize( std::tuple& objectives, MatType& iterateIn, CallbackTypes&&... callbacks) @@ -224,11 +226,12 @@ typename MatType::elem_type NSGA2::Optimize( } //! No objectives to evaluate. +template template typename std::enable_if::type -NSGA2::EvaluateObjectives( +NSGA2::EvaluateObjectives( std::vector&, std::tuple&, std::vector >&) @@ -237,11 +240,12 @@ NSGA2::EvaluateObjectives( } //! Evaluate the objectives for the entire population. +template template typename std::enable_if::type -NSGA2::EvaluateObjectives( +NSGA2::EvaluateObjectives( std::vector& population, std::tuple& objectives, std::vector >& calculatedObjectives) @@ -255,8 +259,9 @@ NSGA2::EvaluateObjectives( } //! Reproduce and generate new candidates. +template template -inline void NSGA2::BinaryTournamentSelection(std::vector& population, + void NSGA2::BinaryTournamentSelection(std::vector& population, const arma::vec& lowerBound, const arma::vec& upperBound) { @@ -295,8 +300,9 @@ inline void NSGA2::BinaryTournamentSelection(std::vector& population, } //! Perform crossover of genes for the children. +template template -inline void NSGA2::Crossover(MatType& childA, + void NSGA2::Crossover(MatType& childA, MatType& childB, const MatType& parentA, const MatType& parentB) @@ -311,8 +317,9 @@ inline void NSGA2::Crossover(MatType& childA, } //! Perform mutation of the candidates weights with some noise. +template template -inline void NSGA2::Mutate(MatType& child, + void NSGA2::Mutate(MatType& child, const arma::vec& lowerBound, const arma::vec& upperBound) { @@ -330,8 +337,9 @@ inline void NSGA2::Mutate(MatType& child, } //! Sort population into Pareto fronts. +template template -inline void NSGA2::FastNonDominatedSort( + void NSGA2::FastNonDominatedSort( std::vector >& fronts, std::vector& ranks, std::vector >& calculatedObjectives) @@ -391,8 +399,9 @@ inline void NSGA2::FastNonDominatedSort( } //! Check if a candidate Pareto dominates another candidate. +template template -inline bool NSGA2::Dominates( + bool NSGA2::Dominates( std::vector >& calculatedObjectives, size_t candidateP, size_t candidateQ) @@ -416,8 +425,9 @@ inline bool NSGA2::Dominates( } //! Assign crowding distance to the population. +template template -inline void NSGA2::CrowdingDistanceAssignment( + void NSGA2::CrowdingDistanceAssignment( const std::vector& front, std::vector>& calculatedObjectives, std::vector& crowdingDistance) @@ -464,8 +474,9 @@ inline void NSGA2::CrowdingDistanceAssignment( } //! Comparator for crowding distance based sorting. +template template -inline bool NSGA2::CrowdingOperator(size_t idxP, + bool NSGA2::CrowdingOperator(size_t idxP, size_t idxQ, const std::vector& ranks, const std::vector& crowdingDistance) diff --git a/tests/callbacks_test.cpp b/tests/callbacks_test.cpp index b2ffbfff9..b742e7cbe 100644 --- a/tests/callbacks_test.cpp +++ b/tests/callbacks_test.cpp @@ -378,7 +378,7 @@ TEST_CASE("NSGA2CallbacksFullFunctionTest", "[CallbackTest]") { arma::vec lowerBound = {-1000}; arma::vec upperBound = {1000}; - NSGA2 optimizer(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2<> optimizer(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); CallbacksFullMultiobjectiveFunctionTest(optimizer, false, false, false, false, true, true, false, false, true); } diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 2beb2e3a7..6c5e30a53 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -42,7 +42,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") const double lowerBound = -1000; const double upperBound = 1000; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -91,7 +91,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") const arma::vec lowerBound = {-1000}; const arma::vec upperBound = {1000}; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -142,7 +142,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -187,7 +187,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -248,7 +248,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") const double lowerBound = -1000; const double upperBound = 1000; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -297,7 +297,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") const arma::vec lowerBound = {-1000}; const arma::vec upperBound = {1000}; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -348,7 +348,7 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -393,7 +393,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; From 69906e100c9a0b68cb45dd583e3c1c7959d73347 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:01:56 +0530 Subject: [PATCH 06/49] test appveyor --- .appveyor.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index f1a0960a7..0189bf038 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,6 +2,7 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" + APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -21,6 +22,9 @@ configuration: Release install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" +init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + build_script: # First, download and build Armadillo. - cd .. @@ -50,7 +54,7 @@ build_script: -DCMAKE_BUILD_TYPE=Release .. - > "%MSBUILD%" "ensmallen.sln" - /m:1 /verbosity:minimal /nologo /p:BuildInParallel=false + /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ From eec6cad59493057f747c30e173ff44f7d388d249 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:13:01 +0530 Subject: [PATCH 07/49] Update .appveyor.yml --- .appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0189bf038..6a5dc65de 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,6 +4,9 @@ environment: BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" APPVEYOR_RDP_PASSWORD: ASDzxc123! +init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 VSVER: Visual Studio 14 2015 Win64 @@ -22,9 +25,6 @@ configuration: Release install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" -init: - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - build_script: # First, download and build Armadillo. - cd .. From 1c290c3235b76ec821f2ff199370c01d4988c0ad Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 11:48:58 +0530 Subject: [PATCH 08/49] back2square1 --- .appveyor.yml | 4 +-- include/ensmallen_bits/nsga2/nsga2.hpp | 1 - include/ensmallen_bits/nsga2/nsga2_impl.hpp | 38 +++++++-------------- tests/callbacks_test.cpp | 2 +- tests/nsga2_test.cpp | 16 ++++----- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 6a5dc65de..d4803b572 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,8 +4,8 @@ environment: BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" APPVEYOR_RDP_PASSWORD: ASDzxc123! -init: - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 diff --git a/include/ensmallen_bits/nsga2/nsga2.hpp b/include/ensmallen_bits/nsga2/nsga2.hpp index be6db9bbf..5a315152a 100644 --- a/include/ensmallen_bits/nsga2/nsga2.hpp +++ b/include/ensmallen_bits/nsga2/nsga2.hpp @@ -50,7 +50,6 @@ namespace ens { * see the documentation on function types included with this distribution or * on the ensmallen website. */ -template class NSGA2 { public: /** diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 6fcbdc772..8b4269f12 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -19,8 +19,7 @@ namespace ens { -template - NSGA2::NSGA2(const size_t populationSize, +inline NSGA2::NSGA2(const size_t populationSize, const size_t maxGenerations, const double crossoverProb, const double mutationProb, @@ -37,8 +36,7 @@ template lowerBound(lowerBound), upperBound(upperBound) { /* Nothing to do here. */ } -template - NSGA2::NSGA2(const size_t populationSize, +inline NSGA2::NSGA2(const size_t populationSize, const size_t maxGenerations, const double crossoverProb, const double mutationProb, @@ -57,11 +55,10 @@ template { /* Nothing to do here. */ } //! Optimize the function. -template template -typename MatType::elem_type NSGA2::Optimize( +inline typename MatType::elem_type NSGA2::Optimize( std::tuple& objectives, MatType& iterateIn, CallbackTypes&&... callbacks) @@ -226,12 +223,11 @@ typename MatType::elem_type NSGA2::Optimize( } //! No objectives to evaluate. -template template -typename std::enable_if::type -NSGA2::EvaluateObjectives( +inline typename std::enable_if::type +NSGA2::EvaluateObjectives( std::vector&, std::tuple&, std::vector >&) @@ -240,12 +236,11 @@ NSGA2::EvaluateObjectives( } //! Evaluate the objectives for the entire population. -template template typename std::enable_if::type -NSGA2::EvaluateObjectives( +NSGA2::EvaluateObjectives( std::vector& population, std::tuple& objectives, std::vector >& calculatedObjectives) @@ -259,9 +254,8 @@ NSGA2::EvaluateObjectives( } //! Reproduce and generate new candidates. -template template - void NSGA2::BinaryTournamentSelection(std::vector& population, +inline void NSGA2::BinaryTournamentSelection(std::vector& population, const arma::vec& lowerBound, const arma::vec& upperBound) { @@ -300,9 +294,8 @@ template } //! Perform crossover of genes for the children. -template template - void NSGA2::Crossover(MatType& childA, +inline void NSGA2::Crossover(MatType& childA, MatType& childB, const MatType& parentA, const MatType& parentB) @@ -317,9 +310,8 @@ template } //! Perform mutation of the candidates weights with some noise. -template template - void NSGA2::Mutate(MatType& child, +inline void NSGA2::Mutate(MatType& child, const arma::vec& lowerBound, const arma::vec& upperBound) { @@ -337,9 +329,8 @@ template } //! Sort population into Pareto fronts. -template template - void NSGA2::FastNonDominatedSort( +inline void NSGA2::FastNonDominatedSort( std::vector >& fronts, std::vector& ranks, std::vector >& calculatedObjectives) @@ -399,9 +390,8 @@ template } //! Check if a candidate Pareto dominates another candidate. -template template - bool NSGA2::Dominates( +inline bool NSGA2::Dominates( std::vector >& calculatedObjectives, size_t candidateP, size_t candidateQ) @@ -425,9 +415,8 @@ template } //! Assign crowding distance to the population. -template template - void NSGA2::CrowdingDistanceAssignment( +inline void NSGA2::CrowdingDistanceAssignment( const std::vector& front, std::vector>& calculatedObjectives, std::vector& crowdingDistance) @@ -474,9 +463,8 @@ template } //! Comparator for crowding distance based sorting. -template template - bool NSGA2::CrowdingOperator(size_t idxP, +inline bool NSGA2::CrowdingOperator(size_t idxP, size_t idxQ, const std::vector& ranks, const std::vector& crowdingDistance) diff --git a/tests/callbacks_test.cpp b/tests/callbacks_test.cpp index b742e7cbe..b2ffbfff9 100644 --- a/tests/callbacks_test.cpp +++ b/tests/callbacks_test.cpp @@ -378,7 +378,7 @@ TEST_CASE("NSGA2CallbacksFullFunctionTest", "[CallbackTest]") { arma::vec lowerBound = {-1000}; arma::vec upperBound = {1000}; - NSGA2<> optimizer(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 optimizer(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); CallbacksFullMultiobjectiveFunctionTest(optimizer, false, false, false, false, true, true, false, false, true); } diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 6c5e30a53..2beb2e3a7 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -42,7 +42,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") const double lowerBound = -1000; const double upperBound = 1000; - NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -91,7 +91,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") const arma::vec lowerBound = {-1000}; const arma::vec upperBound = {1000}; - NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -142,7 +142,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -187,7 +187,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -248,7 +248,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") const double lowerBound = -1000; const double upperBound = 1000; - NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -297,7 +297,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") const arma::vec lowerBound = {-1000}; const arma::vec upperBound = {1000}; - NSGA2<> opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -348,7 +348,7 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -393,7 +393,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2<> opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; From 8f6af30aec074de0bfd384d31f6d2e9fad8a05d8 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 11:54:14 +0530 Subject: [PATCH 09/49] appveyor validated --- .appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index d4803b572..3f12810af 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,9 +4,6 @@ environment: BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" APPVEYOR_RDP_PASSWORD: ASDzxc123! - init: - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 VSVER: Visual Studio 14 2015 Win64 @@ -22,6 +19,9 @@ environment: configuration: Release +init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" From 6254ac14b2ddb47e2ca1673a35032384e9cc2e18 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 13:58:22 +0530 Subject: [PATCH 10/49] remove some inlines --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 8b4269f12..1fc4f1093 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -36,6 +36,7 @@ inline NSGA2::NSGA2(const size_t populationSize, lowerBound(lowerBound), upperBound(upperBound) { /* Nothing to do here. */ } + inline NSGA2::NSGA2(const size_t populationSize, const size_t maxGenerations, const double crossoverProb, @@ -58,7 +59,7 @@ inline NSGA2::NSGA2(const size_t populationSize, template -inline typename MatType::elem_type NSGA2::Optimize( +typename MatType::elem_type NSGA2::Optimize( std::tuple& objectives, MatType& iterateIn, CallbackTypes&&... callbacks) @@ -122,14 +123,13 @@ inline typename MatType::elem_type NSGA2::Optimize( population.push_back(arma::randu(iterate.n_rows, iterate.n_cols) - 0.5 + iterate); - // Ensure population is within variable space. + // Constrain all genes to be between bounds. for (size_t geneIdx = 0; geneIdx < numVariables; geneIdx++) { - if (population[i][geneIdx] < lowerBound[geneIdx]) - population[i][geneIdx] = lowerBound[geneIdx]; - - if (population[i][geneIdx] > upperBound[geneIdx]) - population[i][geneIdx] = upperBound[geneIdx]; + if (population[i](geneIdx) < lowerBound(geneIdx)) + population[i](geneIdx) = lowerBound(geneIdx); + else if (population[i](geneIdx) > upperBound(geneIdx)) + population[i](geneIdx) = upperBound(geneIdx); } } @@ -226,7 +226,7 @@ inline typename MatType::elem_type NSGA2::Optimize( template -inline typename std::enable_if::type +typename std::enable_if::type NSGA2::EvaluateObjectives( std::vector&, std::tuple&, @@ -459,7 +459,7 @@ inline void NSGA2::CrowdingDistanceAssignment( crowdingDistance[front[sortedIdx[i]]] += (fValues[sortedIdx[i + 1]] - fValues[sortedIdx[i - 1]]) / scale; } - } + } } //! Comparator for crowding distance based sorting. From a43c447c848281e0103e17e135e1a95566c78087 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 14:08:59 +0530 Subject: [PATCH 11/49] dont build! --- .appveyor.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3f12810af..b898b5c4d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -52,9 +52,10 @@ build_script: -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% -DCMAKE_BUILD_TYPE=Release .. - - > - "%MSBUILD%" "ensmallen.sln" - /m /verbosity:minimal /nologo /p:BuildInParallel=true + # DONT BUILD ENSMALLEN + # - > + # "%MSBUILD%" "ensmallen.sln" + # /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ From a691584fa30a3d761ff346016a7b9568e4fb6d20 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 14:15:16 +0530 Subject: [PATCH 12/49] dont run test as well --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b898b5c4d..fd9b9789f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -58,5 +58,5 @@ build_script: # /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . + # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + # - ctest -C Release -V --output-on-failure . From f76c2f2ae71cddd4249ad00f2fecfb7628320214 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 14:19:56 +0530 Subject: [PATCH 13/49] on finish --- .appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index fd9b9789f..6253958bc 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -19,9 +19,6 @@ environment: configuration: Release -init: - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" @@ -60,3 +57,6 @@ build_script: # Run tests after copying libraries. # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ # - ctest -C Release -V --output-on-failure . + +on_finish: + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) \ No newline at end of file From c19c5f687032e4724bc94dbc8f4eb0a909158a7d Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 14:54:20 +0530 Subject: [PATCH 14/49] MSVC-15 fails back_inserter --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 1fc4f1093..a1cae3a15 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -201,8 +201,9 @@ typename MatType::elem_type NSGA2::Optimize( for (size_t f: fronts[0]) front.push_back(population[f]); + bestFront.resize(front.size()); // bestFront is stored, can be obtained by the Front() getter. - std::transform(front.begin(), front.end(), std::back_inserter(bestFront), + std::transform(front.begin(), front.end(), bestFront.begin(), [&](const BaseMatType& individual) { return arma::conv_to::from(individual); From a1ef11a077b6c1d5fe5ec03d6bacaeacc00cb2c9 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 16:15:44 +0530 Subject: [PATCH 15/49] some more removals --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 17 ++++++++--------- tests/nsga2_test.cpp | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index a1cae3a15..36016a0d6 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -427,8 +427,7 @@ inline void NSGA2::CrowdingDistanceAssignment( size_t fSize = front.size(); // Stores the sorted indices of the fronts. - std::vector sortedIdx(fSize); - std::iota(sortedIdx.begin(), sortedIdx.end(), 0u); + arma::uvec sortedIdx = arma::regspace(0, 1, fSize - 1); for (size_t m = 0; m < numObjectives; m++) { @@ -444,21 +443,21 @@ inline void NSGA2::CrowdingDistanceAssignment( std::sort(sortedIdx.begin(), sortedIdx.end(), [&](const size_t& frontIdxA, const size_t& frontIdxB) { - return (fValues[frontIdxA] < fValues[frontIdxB]); + return (fValues(frontIdxA) < fValues(frontIdxB)); }); - crowdingDistance[front[sortedIdx[0]]] = + crowdingDistance[front[sortedIdx(0)]] = std::numeric_limits::max(); - crowdingDistance[front[sortedIdx[fSize - 1]]] = + crowdingDistance[front[sortedIdx(fSize - 1)]] = std::numeric_limits::max(); - ElemType minFval = fValues[sortedIdx[0]]; - ElemType maxFval = fValues[sortedIdx[fSize - 1]]; + ElemType minFval = fValues(sortedIdx(0)); + ElemType maxFval = fValues(sortedIdx(fSize - 1)); ElemType scale = (maxFval == minFval) ? 1 : maxFval - minFval; for (size_t i = 1; i < fSize - 1; i++) { - crowdingDistance[front[sortedIdx[i]]] += - (fValues[sortedIdx[i + 1]] - fValues[sortedIdx[i - 1]]) / scale; + crowdingDistance[front[sortedIdx(i)]] += + (fValues(sortedIdx(i + 1)) - fValues(sortedIdx(i - 1))) / scale; } } } diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 2beb2e3a7..53e9b6f72 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -228,8 +228,8 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") template std::vector castFront(const std::vector& bestFront) { - std::vector castedFront; - std::transform(bestFront.begin(), bestFront.end(), std::back_inserter(castedFront), + std::vector castedFront(bestFront.size()); + std::transform(bestFront.begin(), bestFront.end(), castedFront.begin(), [&](const arma::mat& individual) { return arma::conv_to::from(individual); From 1b0b51f570c9cb76e3c19398fd7cb4dfb7d723d0 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 23 Mar 2021 16:58:29 +0530 Subject: [PATCH 16/49] appveyor to normal MSVC Works! --- .appveyor.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 6253958bc..a312289cd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,6 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" - APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -49,14 +48,10 @@ build_script: -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% -DCMAKE_BUILD_TYPE=Release .. - # DONT BUILD ENSMALLEN - # - > - # "%MSBUILD%" "ensmallen.sln" - # /m /verbosity:minimal /nologo /p:BuildInParallel=true + - > + "%MSBUILD%" "ensmallen.sln" + /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - # - ctest -C Release -V --output-on-failure . - -on_finish: - - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) \ No newline at end of file + - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + - ctest -C Release -V --output-on-failure . From 0256405a4f1a7d3f759c840a4d6e978b56195da4 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 05:33:31 +0530 Subject: [PATCH 17/49] check error --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 36016a0d6..f0f5a9b40 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -202,6 +202,7 @@ typename MatType::elem_type NSGA2::Optimize( front.push_back(population[f]); bestFront.resize(front.size()); + // bestFront is stored, can be obtained by the Front() getter. std::transform(front.begin(), front.end(), bestFront.begin(), [&](const BaseMatType& individual) From 6c388a0cac815e16dd096cfeaf267da60bfef634 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 05:38:46 +0530 Subject: [PATCH 18/49] appveyor checks again --- .appveyor.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a312289cd..92a26f53b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,6 +2,7 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" + APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -48,10 +49,13 @@ build_script: -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% -DCMAKE_BUILD_TYPE=Release .. - - > - "%MSBUILD%" "ensmallen.sln" - /m /verbosity:minimal /nologo /p:BuildInParallel=true + # - > + # "%MSBUILD%" "ensmallen.sln" + # /m /verbosity:minimal /nologo /p:BuildInParallel=true + + # # Run tests after copying libraries. + # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + # - ctest -C Release -V --output-on-failure . - # Run tests after copying libraries. - - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . +on_finish: + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) From 679d9045393c50aa4f0a1bf59166ec05df9c1d45 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 05:55:13 +0530 Subject: [PATCH 19/49] cxx11 compiler error? --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index f0f5a9b40..36016a0d6 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -202,7 +202,6 @@ typename MatType::elem_type NSGA2::Optimize( front.push_back(population[f]); bestFront.resize(front.size()); - // bestFront is stored, can be obtained by the Front() getter. std::transform(front.begin(), front.end(), bestFront.begin(), [&](const BaseMatType& individual) From d18192e251e442c4e5d2c74227a323f71c92aa94 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 07:27:04 +0530 Subject: [PATCH 20/49] building works, now just test fails on double --- .appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 92a26f53b..4543c095a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -49,9 +49,9 @@ build_script: -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% -DCMAKE_BUILD_TYPE=Release .. - # - > - # "%MSBUILD%" "ensmallen.sln" - # /m /verbosity:minimal /nologo /p:BuildInParallel=true + - > + "%MSBUILD%" "ensmallen.sln" + /m /verbosity:minimal /nologo /p:BuildInParallel=true # # Run tests after copying libraries. # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ From 1d163131127bb4f4b82104d8a3d9c528991f03d5 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 08:54:09 +0530 Subject: [PATCH 21/49] build in debug --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4543c095a..3f389bdc6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -48,14 +48,14 @@ build_script: -DARMADILLO_LIBRARIES=%BLAS_LIBRARY% -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% - -DCMAKE_BUILD_TYPE=Release .. + -DCMAKE_BUILD_TYPE=Debug .. - > "%MSBUILD%" "ensmallen.sln" /m /verbosity:minimal /nologo /p:BuildInParallel=true # # Run tests after copying libraries. # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - # - ctest -C Release -V --output-on-failure . + # - ctest -C Debug -V --output-on-failure . on_finish: - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) From 2689d5c19e0d9721f6fe346f6535c73bfadce15f Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 09:14:24 +0530 Subject: [PATCH 22/49] use absolute diff --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 36016a0d6..4ec39bb9a 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -452,7 +452,8 @@ inline void NSGA2::CrowdingDistanceAssignment( std::numeric_limits::max(); ElemType minFval = fValues(sortedIdx(0)); ElemType maxFval = fValues(sortedIdx(fSize - 1)); - ElemType scale = (maxFval == minFval) ? 1 : maxFval - minFval; + ElemType scale = + std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); for (size_t i = 1; i < fSize - 1; i++) { From d9c049606ae0226bd1817ee966263ebedadcf108 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 10:00:27 +0530 Subject: [PATCH 23/49] maybe the error should be ok now --- .appveyor.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3f389bdc6..51ea46f0a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -17,7 +17,7 @@ environment: VSVER: Visual Studio 16 2019 MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -configuration: Release +configuration: Debug install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" @@ -48,14 +48,14 @@ build_script: -DARMADILLO_LIBRARIES=%BLAS_LIBRARY% -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% - -DCMAKE_BUILD_TYPE=Debug .. + -DCMAKE_BUILD_TYPE=Release .. - > "%MSBUILD%" "ensmallen.sln" /m /verbosity:minimal /nologo /p:BuildInParallel=true - # # Run tests after copying libraries. - # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - # - ctest -C Debug -V --output-on-failure . + # Run tests after copying libraries. + - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + - ctest -C Release -V --output-on-failure . -on_finish: - - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) +# on_finish: +# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) From 38f88ab2f26896a58e5965f2605940b871cb69eb Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 10:01:54 +0530 Subject: [PATCH 24/49] minor --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 51ea46f0a..0ef53cb7b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -17,7 +17,7 @@ environment: VSVER: Visual Studio 16 2019 MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -configuration: Debug +configuration: Release install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" From 1ad7181e84c029599cf77a169f293ff008bba328 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 28 Mar 2021 15:26:00 +0530 Subject: [PATCH 25/49] everyone use IsInBounds --- tests/nsga2_test.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 53e9b6f72..945656907 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -41,6 +41,8 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") SchafferFunctionN1 SCH; const double lowerBound = -1000; const double upperBound = 1000; + const double expectedLowerBound = 0.0; + const double expectedUpperBound = 2.0; NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); @@ -63,7 +65,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") { double val = arma::as_scalar(solution); - if (val < 0.0 || val > 2.0) + if (!IsInBounds(val, expectedLowerBound, expectedUpperBound)) { allInRange = false; break; @@ -90,6 +92,8 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") SchafferFunctionN1 SCH; const arma::vec lowerBound = {-1000}; const arma::vec upperBound = {1000}; + const double expectedLowerBound = 0.0; + const double expectedUpperBound = 2.0; NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); @@ -111,7 +115,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") { double val = arma::as_scalar(solution); - if (val < 0.0 || val > 2.0) + if (!IsInBounds(val, expectedLowerBound, expectedUpperBound)) { allInRange = false; break; @@ -207,9 +211,9 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") double valY = arma::as_scalar(solution(1)); double valZ = arma::as_scalar(solution(2)); - if (!IsInBounds(valX, expectedLowerBound, expectedUpperBound) || - !IsInBounds(valY, expectedLowerBound, expectedUpperBound) || - !IsInBounds(valZ, expectedLowerBound, expectedUpperBound)) + if (!IsInBounds(valX, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valY, expectedLowerBound, expectedUpperBound) || + !IsInBounds(valZ, expectedLowerBound, expectedUpperBound)) { allInRange = false; break; @@ -247,6 +251,8 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") SchafferFunctionN1 SCH; const double lowerBound = -1000; const double upperBound = 1000; + const double expectedLowerBound = 0.0; + const double expectedUpperBound = 2.0; NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); @@ -269,7 +275,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") { float val = arma::as_scalar(solution); - if (val < 0.f || val > 2.f) + if (!IsInBounds(val, expectedLowerBound, expectedUpperBound)) { allInRange = false; break; @@ -296,6 +302,8 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") SchafferFunctionN1 SCH; const arma::vec lowerBound = {-1000}; const arma::vec upperBound = {1000}; + const double expectedLowerBound = 0.0; + const double expectedUpperBound = 2.0; NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); @@ -317,7 +325,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") { float val = arma::as_scalar(solution); - if (val < 0.f || val > 2.f) + if (!IsInBounds(val, expectedLowerBound, expectedUpperBound)) { allInRange = false; break; From 70bfceebc52c4c53ec0cfc9dec0aff22e39a9dbc Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Mon, 29 Mar 2021 22:30:04 +0530 Subject: [PATCH 26/49] Reason for changing: a) 5k gen is too much, papers stick to ~150 b) The test error which I get is off by 1e-2 c) Solutions are loosing diversity at higher number of generations (repeating solutions even) --- tests/nsga2_test.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 945656907..60b8e8c8d 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -44,7 +44,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -95,7 +95,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -146,7 +146,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -191,7 +191,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -254,7 +254,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -305,7 +305,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 5000, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -356,7 +356,7 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -401,7 +401,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 4000, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; From d3b2ce932a4bcdf4ec0657fb70d37647d4e3122f Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Tue, 30 Mar 2021 01:31:14 +0530 Subject: [PATCH 27/49] Use params from paper 1) crossoverProb: 0.9 2) mutationRate: 1/n; n = num vars 3) numGeneration = 250 --- tests/nsga2_test.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 60b8e8c8d..9abe2c2d8 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -44,7 +44,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -95,7 +95,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -146,7 +146,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -191,7 +191,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -254,7 +254,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -305,7 +305,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -356,7 +356,7 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -401,7 +401,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; From c98b16acd15ef7defeea9e6514f80d728e81b6fe Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Tue, 30 Mar 2021 01:40:03 +0530 Subject: [PATCH 28/49] SchafferN1 double debug Appveyor --- .appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0ef53cb7b..f25723fa9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -54,8 +54,8 @@ build_script: /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . + # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + # - ctest -C Release -V --output-on-failure . -# on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) +on_finish: + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) From a975138f4eb4ddbf9900c50fb9daf7ce37b6b3e8 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Tue, 30 Mar 2021 02:37:26 +0530 Subject: [PATCH 29/49] appveyor old --- .appveyor.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index f25723fa9..a312289cd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,6 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" - APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -54,8 +53,5 @@ build_script: /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - # - ctest -C Release -V --output-on-failure . - -on_finish: - - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + - ctest -C Release -V --output-on-failure . From 15618563b9e12156727457315cc5f80a74813ab3 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Tue, 30 Mar 2021 11:17:18 +0530 Subject: [PATCH 30/49] introduced tolerance --- tests/nsga2_test.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 9abe2c2d8..164c5fd26 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -29,7 +29,8 @@ using namespace std; template bool IsInBounds(const ElemType& value, const ElemType& low, const ElemType& high) { - return !(value < low) && !(high < value); + ElemType tolerance = 1e-3; + return !(value < low - tolerance) && !(high + tolerance < value); } /** @@ -44,7 +45,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -95,7 +96,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -146,7 +147,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -186,12 +187,12 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") FonsecaFlemingFunction FON; const arma::vec lowerBound = {-4, -4, -4}; const arma::vec upperBound = {4, 4, 4}; - const double tolerance = 1e-6; + const double epsilon = 1e-6; const double strength = 1e-4; const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 0.33, strength, epsilon, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -254,7 +255,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -305,7 +306,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 250, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -351,12 +352,12 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") FonsecaFlemingFunction FON; const double lowerBound = -4; const double upperBound = 4; - const double tolerance = 1e-6; + const double epsilon = 1e-6; const double strength = 1e-4; const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 0.33, strength, epsilon, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -396,12 +397,12 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") FonsecaFlemingFunction FON; const arma::vec lowerBound = {-4, -4, -4}; const arma::vec upperBound = {4, 4, 4}; - const double tolerance = 1e-6; + const double epsilon = 1e-6; const double strength = 1e-4; const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 250, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.9, 0.33, strength, epsilon, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; From 12c513d26c0708a1b9b5e9b0e88a145fb1e31cea Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 30 Mar 2021 14:32:06 +0530 Subject: [PATCH 31/49] appveyor debug to check tolerance level --- .appveyor.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a312289cd..e6c12ffb2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,6 +2,7 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" + APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -47,11 +48,14 @@ build_script: -DARMADILLO_LIBRARIES=%BLAS_LIBRARY% -DLAPACK_LIBRARY=%BLAS_LIBRARY% -DBLAS_LIBRARY=%BLAS_LIBRARY% - -DCMAKE_BUILD_TYPE=Release .. + -DCMAKE_BUILD_TYPE=Debug .. - > "%MSBUILD%" "ensmallen.sln" /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . + # - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + # - ctest -C Release -V --output-on-failure . + +on_finish: + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) From 68157eede0e4dce983b389a275680d4cf650e631 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Tue, 30 Mar 2021 19:29:08 +0530 Subject: [PATCH 32/49] build in debug --- .appveyor.yml | 2 +- tests/nsga2_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index e6c12ffb2..98301b7d2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -17,7 +17,7 @@ environment: VSVER: Visual Studio 16 2019 MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -configuration: Release +configuration: Debug install: - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}" diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 164c5fd26..3a774e143 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -29,8 +29,8 @@ using namespace std; template bool IsInBounds(const ElemType& value, const ElemType& low, const ElemType& high) { - ElemType tolerance = 1e-3; - return !(value < low - tolerance) && !(high + tolerance < value); + ElemType roundoff = 1e-3; + return !( value < (low - roundoff) ) && !( (high + roundoff) < value ); } /** From bad9062cd698267566b19ce0bf790bb462b64a16 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 31 Mar 2021 11:57:46 +0530 Subject: [PATCH 33/49] increase tolerance --- tests/nsga2_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index 164c5fd26..ee56fbaf9 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -29,8 +29,8 @@ using namespace std; template bool IsInBounds(const ElemType& value, const ElemType& low, const ElemType& high) { - ElemType tolerance = 1e-3; - return !(value < low - tolerance) && !(high + tolerance < value); + ElemType roundoff = 1e-2; + return !(value < low - roundoff) && !(high + roundoff < value); } /** From d9f3e7b7f2b59940eb52c5c6f8406d5a3405b54b Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 31 Mar 2021 12:11:43 +0530 Subject: [PATCH 34/49] Update nsga2_impl.hpp indent fix --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 4ec39bb9a..3707741c4 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -452,8 +452,8 @@ inline void NSGA2::CrowdingDistanceAssignment( std::numeric_limits::max(); ElemType minFval = fValues(sortedIdx(0)); ElemType maxFval = fValues(sortedIdx(fSize - 1)); - ElemType scale = - std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); + ElemType scale = + std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); for (size_t i = 1; i < fSize - 1; i++) { From 252c50069602024024d314852c855eae3dc9d800 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 31 Mar 2021 12:15:47 +0530 Subject: [PATCH 35/49] indent fix --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 3707741c4..9b19fc097 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -453,7 +453,7 @@ inline void NSGA2::CrowdingDistanceAssignment( ElemType minFval = fValues(sortedIdx(0)); ElemType maxFval = fValues(sortedIdx(fSize - 1)); ElemType scale = - std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); + std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); for (size_t i = 1; i < fSize - 1; i++) { From f58e0eba43d7dc79f16864e0b86a587a36101bf8 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Wed, 31 Mar 2021 12:24:31 +0530 Subject: [PATCH 36/49] fix windows indentation --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 9b19fc097..10e84f137 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -453,7 +453,7 @@ inline void NSGA2::CrowdingDistanceAssignment( ElemType minFval = fValues(sortedIdx(0)); ElemType maxFval = fValues(sortedIdx(fSize - 1)); ElemType scale = - std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); + std::abs(maxFval - minFval) == 0. ? 1. : std::abs(maxFval - minFval); for (size_t i = 1; i < fSize - 1; i++) { From 846b01f16551d860bb26f305e552fc838dac1c9c Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:08:50 +0530 Subject: [PATCH 37/49] appveyor debug --- .appveyor.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a312289cd..ac4596597 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,6 +2,7 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" + APPVEYOR_RDP_PASSWORD: "ASDzxc123!" matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -53,5 +54,8 @@ build_script: /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. - - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . +# - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ +# - ctest -C Release -V --output-on-failure . + +on_finish: + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) From 36e43ae21fe45c2beae5b702a359436df02a00c8 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:16:37 +0530 Subject: [PATCH 38/49] run only nsga2 test and use random seeds in main.cpp --- tests/CMakeLists.txt | 42 ------------------------------------------ tests/main.cpp | 6 +++--- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6b55d4a4a..4b335be0f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,49 +1,7 @@ # The tests that need to be compiled. set(ENSMALLEN_TESTS_SOURCES main.cpp - ada_bound_test.cpp - ada_delta_test.cpp - ada_grad_test.cpp - adam_test.cpp - aug_lagrangian_test.cpp - bigbatch_sgd_test.cpp - callbacks_test.cpp - cmaes_test.cpp - cne_test.cpp - de_test.cpp - eve_test.cpp - frankwolfe_test.cpp - ftml_test.cpp - function_test.cpp - gradient_descent_test.cpp - grid_search_test.cpp - iqn_test.cpp - katyusha_test.cpp - lbfgs_test.cpp - line_search_test.cpp - lookahead_test.cpp - lrsdp_test.cpp - momentum_sgd_test.cpp - nesterov_momentum_sgd_test.cpp nsga2_test.cpp - parallel_sgd_test.cpp - proximal_test.cpp - pso_test.cpp - quasi_hyperbolic_momentum_sgd_test.cpp - rmsprop_test.cpp - sa_test.cpp - sarah_test.cpp - scd_test.cpp - sdp_primal_dual_test.cpp - sgdr_test.cpp - sgd_test.cpp - smorms3_test.cpp - snapshot_ensembles.cpp - spalera_sgd_test.cpp - spsa_test.cpp - svrg_test.cpp - swats_test.cpp - wn_grad_test.cpp ) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/tests/main.cpp b/tests/main.cpp index d72bbb82a..1545d2b60 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -22,9 +22,9 @@ int main(int argc, char** argv) * each run. This is good for ensuring that a test's tolerance is sufficient * across many different runs. */ - //size_t seed = std::time(NULL); - //srand((unsigned int) seed); - //arma::arma_rng::set_seed(seed); + size_t seed = std::time(NULL); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); std::cout << "ensmallen version: " << ens::version::as_string() << std::endl; From 400720aa15291d238f2ef9e18732fb900e327c59 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:47:00 +0530 Subject: [PATCH 39/49] appveyor print when test fails --- tests/nsga2_test.cpp | 70 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index fa16ff2b7..e6f20e1e5 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -29,8 +29,8 @@ using namespace std; template bool IsInBounds(const ElemType& value, const ElemType& low, const ElemType& high) { - ElemType roundoff = 1e-2; - return !(value < low - roundoff) && !(high + roundoff < value ); + ElemType roundoff = 0.1; + return !(value < (low - roundoff)) && !((high + roundoff) < value); } /** @@ -45,7 +45,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -79,7 +79,11 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") break; } } - + if (success == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(success == true); } @@ -96,7 +100,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -130,6 +134,12 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") } } + if (success == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } + REQUIRE(success == true); } @@ -147,7 +157,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.9, 0.33, strength, tolerance, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -175,6 +185,11 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") break; } } + if (allInRange == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(allInRange); } @@ -187,12 +202,12 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") FonsecaFlemingFunction FON; const arma::vec lowerBound = {-4, -4, -4}; const arma::vec upperBound = {4, 4, 4}; - const double epsilon = 1e-6; + const double tolerance = 1e-6; const double strength = 1e-4; const double expectedLowerBound = -1.0 / sqrt(3); const double expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.9, 0.33, strength, epsilon, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -220,6 +235,11 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") break; } } + if (allInRange == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(allInRange); } @@ -255,7 +275,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -289,7 +309,11 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") break; } } - + if (success == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(success == true); } @@ -306,7 +330,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") const double expectedLowerBound = 0.0; const double expectedUpperBound = 2.0; - NSGA2 opt(20, 300, 0.9, 1, 1e-3, 1e-6, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.5, 0.5, 1e-3, 1e-6, lowerBound, upperBound); typedef decltype(SCH.objectiveA) ObjectiveTypeA; typedef decltype(SCH.objectiveB) ObjectiveTypeB; @@ -339,7 +363,11 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") break; } } - + if (success == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(success == true); } @@ -352,12 +380,12 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") FonsecaFlemingFunction FON; const double lowerBound = -4; const double upperBound = 4; - const double epsilon = 1e-6; + const double tolerance = 1e-6; const double strength = 1e-4; const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.9, 0.33, strength, epsilon, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -385,6 +413,11 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") break; } } + if (allInRange == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(allInRange); } @@ -397,12 +430,12 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") FonsecaFlemingFunction FON; const arma::vec lowerBound = {-4, -4, -4}; const arma::vec upperBound = {4, 4, 4}; - const double epsilon = 1e-6; + const double tolerance = 1e-6; const double strength = 1e-4; const float expectedLowerBound = -1.0 / sqrt(3); const float expectedUpperBound = 1.0 / sqrt(3); - NSGA2 opt(20, 300, 0.9, 0.33, strength, epsilon, lowerBound, upperBound); + NSGA2 opt(20, 300, 0.6, 0.3, strength, tolerance, lowerBound, upperBound); typedef decltype(FON.objectiveA) ObjectiveTypeA; typedef decltype(FON.objectiveB) ObjectiveTypeB; @@ -430,5 +463,10 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") break; } } + if (allInRange == false) + { + for (arma::mat solution : opt.Front()) + std::cout << solution << std::endl; + } REQUIRE(allInRange); } \ No newline at end of file From f3f699a50879d56156082c98a7a2c48f9a4fd3ed Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:52:30 +0530 Subject: [PATCH 40/49] run appveyor test 3000 times --- .appveyor.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index ac4596597..a05599b3c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -54,8 +54,5 @@ build_script: /m /verbosity:minimal /nologo /p:BuildInParallel=true # Run tests after copying libraries. -# - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ -# - ctest -C Release -V --output-on-failure . - -on_finish: - - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ + - ctest -C Release -V --output-on-failure ---repeat until-fail:3000 . From fb5f23db8b97527b8ee6aeb55fa7e93db5b9772f Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:08:30 +0530 Subject: [PATCH 41/49] revert appveyor and ctest settings --- .appveyor.yml | 2 +- tests/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/main.cpp | 6 +++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a05599b3c..e2ece919d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -55,4 +55,4 @@ build_script: # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure ---repeat until-fail:3000 . + - ctest -C Release -V --output-on-failure . diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b335be0f..6b55d4a4a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,49 @@ # The tests that need to be compiled. set(ENSMALLEN_TESTS_SOURCES main.cpp + ada_bound_test.cpp + ada_delta_test.cpp + ada_grad_test.cpp + adam_test.cpp + aug_lagrangian_test.cpp + bigbatch_sgd_test.cpp + callbacks_test.cpp + cmaes_test.cpp + cne_test.cpp + de_test.cpp + eve_test.cpp + frankwolfe_test.cpp + ftml_test.cpp + function_test.cpp + gradient_descent_test.cpp + grid_search_test.cpp + iqn_test.cpp + katyusha_test.cpp + lbfgs_test.cpp + line_search_test.cpp + lookahead_test.cpp + lrsdp_test.cpp + momentum_sgd_test.cpp + nesterov_momentum_sgd_test.cpp nsga2_test.cpp + parallel_sgd_test.cpp + proximal_test.cpp + pso_test.cpp + quasi_hyperbolic_momentum_sgd_test.cpp + rmsprop_test.cpp + sa_test.cpp + sarah_test.cpp + scd_test.cpp + sdp_primal_dual_test.cpp + sgdr_test.cpp + sgd_test.cpp + smorms3_test.cpp + snapshot_ensembles.cpp + spalera_sgd_test.cpp + spsa_test.cpp + svrg_test.cpp + swats_test.cpp + wn_grad_test.cpp ) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/tests/main.cpp b/tests/main.cpp index 1545d2b60..d72bbb82a 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -22,9 +22,9 @@ int main(int argc, char** argv) * each run. This is good for ensuring that a test's tolerance is sufficient * across many different runs. */ - size_t seed = std::time(NULL); - srand((unsigned int) seed); - arma::arma_rng::set_seed(seed); + //size_t seed = std::time(NULL); + //srand((unsigned int) seed); + //arma::arma_rng::set_seed(seed); std::cout << "ensmallen version: " << ens::version::as_string() << std::endl; From 95bc44f4fa98ee228a3405c9d5ad017265be0beb Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:09:51 +0530 Subject: [PATCH 42/49] rm appveyor pass --- .appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index e2ece919d..a312289cd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,6 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" - APPVEYOR_RDP_PASSWORD: "ASDzxc123!" matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 From 5c31f6ad51123754dda9778d6cb1070444de5544 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Thu, 1 Apr 2021 09:37:22 +0530 Subject: [PATCH 43/49] stress test on appveyor proofs => run 3k times --- .appveyor.yml | 5 ++++- tests/CMakeLists.txt | 42 ------------------------------------------ tests/main.cpp | 6 +++--- 3 files changed, 7 insertions(+), 46 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a312289cd..170d3cc00 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,6 +2,7 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" + APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -54,4 +55,6 @@ build_script: # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . + +on_finish: + - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6b55d4a4a..4b335be0f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,49 +1,7 @@ # The tests that need to be compiled. set(ENSMALLEN_TESTS_SOURCES main.cpp - ada_bound_test.cpp - ada_delta_test.cpp - ada_grad_test.cpp - adam_test.cpp - aug_lagrangian_test.cpp - bigbatch_sgd_test.cpp - callbacks_test.cpp - cmaes_test.cpp - cne_test.cpp - de_test.cpp - eve_test.cpp - frankwolfe_test.cpp - ftml_test.cpp - function_test.cpp - gradient_descent_test.cpp - grid_search_test.cpp - iqn_test.cpp - katyusha_test.cpp - lbfgs_test.cpp - line_search_test.cpp - lookahead_test.cpp - lrsdp_test.cpp - momentum_sgd_test.cpp - nesterov_momentum_sgd_test.cpp nsga2_test.cpp - parallel_sgd_test.cpp - proximal_test.cpp - pso_test.cpp - quasi_hyperbolic_momentum_sgd_test.cpp - rmsprop_test.cpp - sa_test.cpp - sarah_test.cpp - scd_test.cpp - sdp_primal_dual_test.cpp - sgdr_test.cpp - sgd_test.cpp - smorms3_test.cpp - snapshot_ensembles.cpp - spalera_sgd_test.cpp - spsa_test.cpp - svrg_test.cpp - swats_test.cpp - wn_grad_test.cpp ) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/tests/main.cpp b/tests/main.cpp index d72bbb82a..1545d2b60 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -22,9 +22,9 @@ int main(int argc, char** argv) * each run. This is good for ensuring that a test's tolerance is sufficient * across many different runs. */ - //size_t seed = std::time(NULL); - //srand((unsigned int) seed); - //arma::arma_rng::set_seed(seed); + size_t seed = std::time(NULL); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); std::cout << "ensmallen version: " << ens::version::as_string() << std::endl; From 7eafb8a2f500f0e36e26ffa0e484ae6800cc3f10 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Fri, 2 Apr 2021 07:06:49 +0530 Subject: [PATCH 44/49] Revert changes from RDP --- .appveyor.yml | 5 +---- tests/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++ tests/main.cpp | 6 +++--- tests/nsga2_test.cpp | 48 +++++++------------------------------------- 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 170d3cc00..87343033f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,6 @@ environment: ARMADILLO_DOWNLOAD: "http://ftp.fau.de/macports/distfiles/armadillo/armadillo-8.400.0.tar.xz" BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll" - APPVEYOR_RDP_PASSWORD: ASDzxc123! matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -55,6 +54,4 @@ build_script: # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - -on_finish: - - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) \ No newline at end of file + - ctest -C Release -V --output-on-failure . \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b335be0f..6b55d4a4a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,49 @@ # The tests that need to be compiled. set(ENSMALLEN_TESTS_SOURCES main.cpp + ada_bound_test.cpp + ada_delta_test.cpp + ada_grad_test.cpp + adam_test.cpp + aug_lagrangian_test.cpp + bigbatch_sgd_test.cpp + callbacks_test.cpp + cmaes_test.cpp + cne_test.cpp + de_test.cpp + eve_test.cpp + frankwolfe_test.cpp + ftml_test.cpp + function_test.cpp + gradient_descent_test.cpp + grid_search_test.cpp + iqn_test.cpp + katyusha_test.cpp + lbfgs_test.cpp + line_search_test.cpp + lookahead_test.cpp + lrsdp_test.cpp + momentum_sgd_test.cpp + nesterov_momentum_sgd_test.cpp nsga2_test.cpp + parallel_sgd_test.cpp + proximal_test.cpp + pso_test.cpp + quasi_hyperbolic_momentum_sgd_test.cpp + rmsprop_test.cpp + sa_test.cpp + sarah_test.cpp + scd_test.cpp + sdp_primal_dual_test.cpp + sgdr_test.cpp + sgd_test.cpp + smorms3_test.cpp + snapshot_ensembles.cpp + spalera_sgd_test.cpp + spsa_test.cpp + svrg_test.cpp + swats_test.cpp + wn_grad_test.cpp ) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/tests/main.cpp b/tests/main.cpp index 1545d2b60..d72bbb82a 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -22,9 +22,9 @@ int main(int argc, char** argv) * each run. This is good for ensuring that a test's tolerance is sufficient * across many different runs. */ - size_t seed = std::time(NULL); - srand((unsigned int) seed); - arma::arma_rng::set_seed(seed); + //size_t seed = std::time(NULL); + //srand((unsigned int) seed); + //arma::arma_rng::set_seed(seed); std::cout << "ensmallen version: " << ens::version::as_string() << std::endl; diff --git a/tests/nsga2_test.cpp b/tests/nsga2_test.cpp index e6f20e1e5..b0e301b44 100644 --- a/tests/nsga2_test.cpp +++ b/tests/nsga2_test.cpp @@ -79,11 +79,7 @@ TEST_CASE("NSGA2SchafferN1DoubleTest", "[NSGA2Test]") break; } } - if (success == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(success == true); } @@ -134,12 +130,6 @@ TEST_CASE("NSGA2SchafferN1TestVectorDoubleBounds", "[NSGA2Test]") } } - if (success == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } - REQUIRE(success == true); } @@ -185,11 +175,7 @@ TEST_CASE("NSGA2FonsecaFlemingDoubleTest", "[NSGA2Test]") break; } } - if (allInRange == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(allInRange); } @@ -235,11 +221,7 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorDoubleBounds", "[NSGA2Test]") break; } } - if (allInRange == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(allInRange); } @@ -309,11 +291,7 @@ TEST_CASE("NSGA2SchafferN1FloatTest", "[NSGA2Test]") break; } } - if (success == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(success == true); } @@ -363,11 +341,7 @@ TEST_CASE("NSGA2SchafferN1TestVectorFloatBounds", "[NSGA2Test]") break; } } - if (success == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(success == true); } @@ -413,11 +387,7 @@ TEST_CASE("NSGA2FonsecaFlemingFloatTest", "[NSGA2Test]") break; } } - if (allInRange == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(allInRange); } @@ -463,10 +433,6 @@ TEST_CASE("NSGA2FonsecaFlemingTestVectorFloatBounds", "[NSGA2Test]") break; } } - if (allInRange == false) - { - for (arma::mat solution : opt.Front()) - std::cout << solution << std::endl; - } + REQUIRE(allInRange); } \ No newline at end of file From 02d8d94c18a2c9d503185af2ea40acb502732c44 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Fri, 2 Apr 2021 07:18:18 +0530 Subject: [PATCH 45/49] appveyor from master --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 87343033f..a312289cd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -54,4 +54,4 @@ build_script: # Run tests after copying libraries. - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\ - - ctest -C Release -V --output-on-failure . \ No newline at end of file + - ctest -C Release -V --output-on-failure . From c6e76e2c62bb7c176e0fe233e32c9da3f451db68 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 7 Apr 2021 09:38:47 +0530 Subject: [PATCH 46/49] indent fix --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 30 ++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 10e84f137..e664dc04c 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -173,21 +173,21 @@ typename MatType::elem_type NSGA2::Optimize( // Sort based on crowding distance. std::sort(population.begin(), population.end(), - [this, ranks, crowdingDistance, population](BaseMatType candidateP, - BaseMatType candidateQ) - { - size_t idxP, idxQ; - for (size_t i = 0; i < population.size(); i++) - { - if (arma::approx_equal(population[i], candidateP, "absdiff", epsilon)) - idxP = i; - - if (arma::approx_equal(population[i], candidateQ, "absdiff", epsilon)) - idxQ = i; - } - - return CrowdingOperator(idxP, idxQ, ranks, crowdingDistance); - } + [this, ranks, crowdingDistance, population] + (BaseMatType candidateP, BaseMatType candidateQ) + { + size_t idxP, idxQ; + for (size_t i = 0; i < population.size(); i++) + { + if (arma::approx_equal(population[i], candidateP, "absdiff", epsilon)) + idxP = i; + + if (arma::approx_equal(population[i], candidateQ, "absdiff", epsilon)) + idxQ = i; + } + + return CrowdingOperator(idxP, idxQ, ranks, crowdingDistance); + } ); // Yield a new population P_{t+1} of size populationSize. From 850612fd97b06f7dd9e97feea096e3bafd51fac6 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Thu, 8 Apr 2021 19:14:01 +0530 Subject: [PATCH 47/49] sanity fix --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index e664dc04c..bafe8a9c6 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -27,6 +27,8 @@ inline NSGA2::NSGA2(const size_t populationSize, const double epsilon, const arma::vec& lowerBound, const arma::vec& upperBound) : + numObjectives(0), + numVariables(0), populationSize(populationSize), maxGenerations(maxGenerations), crossoverProb(crossoverProb), @@ -45,6 +47,8 @@ inline NSGA2::NSGA2(const size_t populationSize, const double epsilon, const double lowerBound, const double upperBound) : + numObjectives(0), + numVariables(0), populationSize(populationSize), maxGenerations(maxGenerations), crossoverProb(crossoverProb), @@ -176,7 +180,7 @@ typename MatType::elem_type NSGA2::Optimize( [this, ranks, crowdingDistance, population] (BaseMatType candidateP, BaseMatType candidateQ) { - size_t idxP, idxQ; + size_t idxP{}, idxQ{}; for (size_t i = 0; i < population.size(); i++) { if (arma::approx_equal(population[i], candidateP, "absdiff", epsilon)) From 9463b153d1d9b4132c30208eb1e484114bcfd245 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Sat, 10 Apr 2021 23:57:11 +0530 Subject: [PATCH 48/49] Update HISTORY.md white space --- HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 9270d0a23..6bbbd0d4b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -15,7 +15,7 @@ * Add clarifying comments in problems/ implementations ([#276](https://github.com/mlpack/ensmallen/pull/276)). - + * CheckArbitraryFunctionTypeAPI extended for MOO support ([#283](https://github.com/mlpack/ensmallen/pull/283)). From 33974ce3f7355a9da9fe67d3e5bbb327daba815f Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 11 Apr 2021 00:04:51 +0530 Subject: [PATCH 49/49] check arbitrary --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index bafe8a9c6..2c36758c5 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -80,6 +80,10 @@ typename MatType::elem_type NSGA2::Optimize( typedef typename MatTypeTraits::BaseMatType BaseMatType; BaseMatType& iterate = (BaseMatType&) iterateIn; + + // Make sure that we have the methods that we need. Long name... + traits::CheckArbitraryFunctionTypeAPI(); RequireDenseFloatingPointType(); // Check if lower bound is a vector of a single dimension.