Skip to content

Commit

Permalink
Merge pull request #327
Browse files Browse the repository at this point in the history
Fix MOEAD test stability
  • Loading branch information
conradsnicta authored Oct 20, 2021
2 parents 99de75c + 7a8c5ae commit ee3f0e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
* Update Catch2 to 2.13.7
([#322](https://github.com/mlpack/ensmallen/pull/322)).

* Remove redundant template argument for C++20 compatibility
([#324](https://github.com/mlpack/ensmallen/pull/324)).

* Fix MOEAD test stability
([#327](https://github.com/mlpack/ensmallen/pull/327)).

### ensmallen 2.17.0: "Pachis Din Me Pesa Double"
###### 2021-07-06
* CheckArbitraryFunctionTypeAPI extended for MOO support
Expand Down
34 changes: 23 additions & 11 deletions tests/moead_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TEST_CASE("MOEADSchafferN1DoubleTest", "[MOEADTest]")

// We allow a few trials in case of poor convergence.
bool success = false;
for (size_t trial = 0; trial < 3; ++trial)
for (size_t trial = 0; trial < 5; ++trial)
{
arma::mat coords = SCH.GetInitialPoint();
std::tuple<ObjectiveTypeA, ObjectiveTypeB> objectives = SCH.GetObjectives();
Expand Down Expand Up @@ -506,6 +506,9 @@ TEST_CASE("MOEADFonsecaFlemingTestVectorFloatBounds", "[MOEADTest]")
*
* NOTE: For the sake of runtime, only ZDT-1 is tested against the
* algorithm. Others have been tested separately.
*
* We run the test multiple times, since it sometimes fails, in order to get the
* probability of failure down.
*/
TEST_CASE("MOEADZDTONETest", "[MOEADTest]")
{
Expand All @@ -531,17 +534,26 @@ TEST_CASE("MOEADZDTONETest", "[MOEADTest]")
typedef decltype(ZDT_ONE.objectiveF1) ObjectiveTypeA;
typedef decltype(ZDT_ONE.objectiveF2) ObjectiveTypeB;

arma::mat coords = ZDT_ONE.GetInitialPoint();
std::tuple<ObjectiveTypeA, ObjectiveTypeB> objectives = ZDT_ONE.GetObjectives();
const size_t trials = 8;
for (size_t trial = 0; trial < trials; ++trial)
{
arma::mat coords = ZDT_ONE.GetInitialPoint();
std::tuple<ObjectiveTypeA, ObjectiveTypeB> objectives =
ZDT_ONE.GetObjectives();

opt.Optimize(objectives, coords);
opt.Optimize(objectives, coords);

//! Refer the ZDT_ONE implementation for g objective implementation.
//! The optimal g value is taken from the docs of ZDT_ONE.
size_t numVariables = coords.size();
double sum = arma::accu(coords(arma::span(1, numVariables - 1), 0));
const double g = 1.0 + 9.0 * sum / (static_cast<double>(numVariables - 1));
if (trial < trials - 1 && g != Approx(1.0).margin(0.99))
continue;

//! Refer the ZDT_ONE implementation for g objective implementation.
//! The optimal g value is taken from the docs of ZDT_ONE.
size_t numVariables = coords.size();
double sum = arma::accu(coords(arma::span(1, numVariables - 1), 0));
double g = 1. + 9. * sum / (static_cast<double>(numVariables - 1));
REQUIRE(g == Approx(1.0).margin(0.99));
REQUIRE(g == Approx(1.0).margin(0.99));
break;
}
}

/**
Expand Down Expand Up @@ -615,4 +627,4 @@ TEST_CASE("MOEADDIRICHLETZDT3Test", "[MOEADTest]")

const arma::cube& finalPopulation = opt.ParetoSet();
REQUIRE(VariableBoundsCheck(finalPopulation));
}
}

0 comments on commit ee3f0e1

Please sign in to comment.