Skip to content

Commit

Permalink
style and error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IWNMWE committed Aug 9, 2024
1 parent dfd7cb5 commit 4ba00c1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 111 deletions.
38 changes: 14 additions & 24 deletions include/ensmallen_bits/problems/maf/maf1_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ namespace test {
// A fixed no. of Objectives and Variables(|x| = 7, M = 3).
size_t numObjectives {3};
size_t numVariables {12};
size_t numParetoPoints;

public:

Expand All @@ -68,30 +67,21 @@ namespace test {
*
* @param numParetoPoint No. of pareto points in the reference front.
*/
MAF1 (size_t numParetoPoint = 136) :
numParetoPoints(numParetoPoint),
objectiveF1(0, *this),
objectiveF2(1, *this),
objectiveF3(2, *this)
MAF1() :
objectiveF1(0, *this),
objectiveF2(1, *this),
objectiveF3(2, *this)
{/* Nothing to do here */}

// Get the private variables.
size_t GetNumObjectives ()
size_t GetNumObjectives()
{ return this -> numObjectives; }

size_t GetNumVariables ()
size_t GetNumVariables()
{ return this -> numVariables; }

/**
* Set the no. of pareto points.
*
* @param numParetoPoint
*/
void SetNumParetoPoint (size_t numParetoPoint)
{ this -> numParetoPoints = numParetoPoint; }

// Get the starting point.
arma::Col<typename MatType::elem_type> GetInitialPoint ()
arma::Col<typename MatType::elem_type> GetInitialPoint()
{
// Convenience typedef.
typedef typename MatType::elem_type ElemType;
Expand All @@ -104,14 +94,14 @@ namespace test {
* @param coords The function coordinates.
* @return arma::Row<typename MatType::elem_type>
*/
arma::Row<typename MatType::elem_type> g (const MatType& coords)
arma::Row<typename MatType::elem_type> g(const MatType& coords)
{
// Convenience typedef.
typedef typename MatType::elem_type ElemType;

arma::Row<ElemType> innerSum(size(coords)[1], arma::fill::zeros);

for(size_t i = numObjectives - 1;i < numVariables;i++)
for (size_t i = numObjectives - 1;i < numVariables;i++)
{
innerSum += arma::pow((coords.row(i) - 0.5), 2);
}
Expand All @@ -125,15 +115,15 @@ namespace test {
* @param coords The function coordinates.
* @return arma::Mat<typename MatType::elem_type>
*/
arma::Mat<typename MatType::elem_type> Evaluate (const MatType& coords)
arma::Mat<typename MatType::elem_type> Evaluate(const MatType& coords)
{
// Convenience typedef.
typedef typename MatType::elem_type ElemType;

arma::Mat<ElemType> objectives(numObjectives, size(coords)[1]);
arma::Row<ElemType> G = g(coords);
arma::Row<ElemType> value(coords.n_cols, arma::fill::ones);
for(size_t i = 0;i < numObjectives - 1;i++)
for (size_t i = 0;i < numObjectives - 1;i++)
{
objectives.row(i) = (1 - value % (1.0 - coords.row(i))) % (1. + G);
value = value % coords.row(i);
Expand All @@ -146,7 +136,7 @@ namespace test {
// Changes based on stop variable provided.
struct MAF1Objective
{
MAF1Objective (size_t stop, MAF1<MatType>& maf): stop(stop), maf(maf)
MAF1Objective(size_t stop, MAF1& maf): stop(stop), maf(maf)
{/* Nothing to do here. */}

/**
Expand All @@ -155,10 +145,10 @@ namespace test {
* @param coords The function coordinates.
* @return arma::Col<typename MatType::elem_type>
*/
typename MatType::elem_type Evaluate (const MatType& coords)
typename MatType::elem_type Evaluate(const MatType& coords)
{
// Convenience typedef.
if (stop == 0)
if(stop == 0)
{
return coords[0] * (1. + maf.g(coords)[0]);
}
Expand Down
33 changes: 11 additions & 22 deletions include/ensmallen_bits/problems/maf/maf2_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ namespace test {
*
* @param numParetoPoint No. of pareto points in the reference front.
*/
MAF2(size_t numParetoPoints = 136) :
numParetoPoints(numParetoPoints),
MAF2() :
objectiveF1(0, *this),
objectiveF2(1, *this),
objectiveF3(2, *this)
Expand All @@ -95,14 +94,6 @@ namespace test {
size_t GetNumVariables()
{ return this -> numVariables; }

/**
* Set the no. of pareto points.
*
* @param numParetoPoint The no. points in the reference front.
*/
void SetNumParetoPoint(size_t numParetoPoint)
{ this -> numParetoPoints = numParetoPoint; }

/**
* Evaluate the G(x) with the given coordinate.
*
Expand All @@ -116,12 +107,13 @@ namespace test {
// Convenience typedef.
typedef typename MatType::elem_type ElemType;

arma::Mat<ElemType> innerSum(numObjectives, size(coords)[1], arma::fill::zeros);
arma::Mat<ElemType> innerSum(numObjectives, size(coords)[1],
arma::fill::zeros);

for (size_t i = 0; i < numObjectives; i++)
{
size_t j = numObjectives - 1 + (i * c);
for(; j < numVariables + (i + 1) *c && j < numObjectives; i++)
for(; j < numVariables - 1 + (i + 1) *c && j < numObjectives; j++)
{
innerSum.row(i) += arma::pow((coords.row(i) - 0.5), 2) * 0.25;
}
Expand All @@ -143,16 +135,17 @@ namespace test {

arma::Mat<ElemType> objectives(numObjectives, size(coords)[1]);
arma::Mat<ElemType> G = g(coords);
arma::Row<ElemType> value(numObjectives, arma::fill::ones);
arma::Row<ElemType> value(size(coords)[1], arma::fill::ones);
arma::Row<ElemType> theta;
for (size_t i = 0; i < numObjectives - 1; i++)
{
theta = arma::datum::pi * 0.5 * (coords.row(i) / 2 + 0.25);
theta = arma::datum::pi * 0.5 * ((coords.row(i) / 2) + 0.25);
objectives.row(i) = value %
arma::sin(theta) % (1.0 + G.row(numObjectives - 1 - i));
value = value % arma::cos(theta);
}
objectives.row(numObjectives - 1) = value;
objectives.row(numObjectives - 1) = value %
(1.0 + G.row(0));
return objectives;
}

Expand All @@ -178,18 +171,14 @@ namespace test {
arma::Col<ElemType> G = maf.g(coords).col(0);
for (size_t i = 0; i < stop; i++)
{
theta = arma::datum::pi * 0.5 * (coords[i] / 2 + 0.25);
theta = arma::datum::pi * 0.5 * ((coords[i] / 2) + 0.25);
value = value * std::cos(theta);
}
theta = arma::datum::pi * 0.5 * (coords[stop] / 2 + 0.25);
if (stop != maf.numObjectives - 1)
theta = arma::datum::pi * 0.5 * ((coords[stop] / 2) + 0.25);
if(stop != maf.numObjectives - 1)
{
value = value * std::sin(theta);
}
else
{
value = value * std::cos(theta);
}

value = value * (1.0 + G[maf.GetNumObjectives() - 1 - stop]);
return value;
Expand Down
20 changes: 5 additions & 15 deletions include/ensmallen_bits/problems/maf/maf3_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ namespace test {
{
private:

// A fixed no. of Objectives and Variables(|x| = 7, M = 3).
// A fixed no. of Objectives and Variables(|x| = 12, M = 3).
size_t numObjectives {3};
size_t numVariables {12};
size_t numParetoPoints;

public:

Expand All @@ -69,11 +68,10 @@ namespace test {
*
* @param numParetoPoint No. of pareto points in the reference front.
*/
MAF3(size_t numParetoPoints = 136) :
numParetoPoints(numParetoPoints),
MAF3() :
objectiveF1(0, *this),
objectiveF2(1, *this),
objectiveF3(2, *this)
objectiveF3(2, *this)
{/*Nothing to do here.*/}

//! Get the starting point.
Expand All @@ -94,14 +92,6 @@ namespace test {
size_t GetNumVariables()
{ return this -> numVariables;}

/**
* Set the no. of pareto points.
*
* @param numParetoPoint No. of pareto points in the reference front.
*/
void SetNumParetoPoint(size_t numParetoPoint)
{ this -> numParetoPoints = numParetoPoint;}

/**
* Evaluate the G(x) with the given coordinate.
*
Expand Down Expand Up @@ -173,14 +163,14 @@ namespace test {
value = value * std::cos(coords[i] * arma::datum::pi * 0.5);
}

if (stop != maf.GetNumObjectives() - 1)
if(stop != maf.GetNumObjectives() - 1)
{
value = value * std::sin(coords[stop] * arma::datum::pi * 0.5);
}

value = value * (1. + maf.g(coords)[0]);

if (stop == 0) {
if(stop == 0) {
return std::pow(value, 2);
}
return std::pow(value, 4);
Expand Down
28 changes: 9 additions & 19 deletions include/ensmallen_bits/problems/maf/maf4_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace test {
size_t numObjectives {3};
size_t numVariables {12};
double a;
size_t numParetoPoints;

public:

Expand All @@ -71,12 +70,11 @@ namespace test {
* @param numParetoPoint No. of pareto points in the reference front.
* @param a The scale factor of the objectives.
*/
MAF4(size_t numParetoPoints = 136, double a = 2) :
numParetoPoints(numParetoPoints),
objectiveF1(0, *this),
objectiveF2(1, *this),
objectiveF3(2, *this),
a(a)
MAF4(double a = 2) :
objectiveF1(0, *this),
objectiveF2(1, *this),
objectiveF3(2, *this),
a(a)
{/*Nothing to do here.*/}

//! Get the starting point.
Expand All @@ -101,14 +99,6 @@ namespace test {
size_t GetA()
{ return this -> a; }

/**
* Set the no. of pareto points.
*
* @param numParetoPoint No. of pareto points in the reference front.
*/
void SetNumParetoPoint(size_t numParetoPoint)
{ this -> numParetoPoints = numParetoPoint;}

/**
* Set the scale factor of the objectives.
*
Expand All @@ -132,7 +122,7 @@ namespace test {

arma::Row<ElemType> innerSum(size(coords)[1], arma::fill::zeros);

for(size_t i = numObjectives - 1; i < numVariables; i++)
for (size_t i = numObjectives - 1; i < numVariables; i++)
{
innerSum += arma::pow((coords.row(i) - 0.5), 2) -
arma::cos(20 * arma::datum::pi * (coords.row(i) - 0.5));
Expand All @@ -155,7 +145,7 @@ namespace test {
arma::Mat<ElemType> objectives(numObjectives, size(coords)[1]);
arma::Row<ElemType> G = g(coords);
arma::Row<ElemType> value(coords.n_cols, arma::fill::ones);
for(size_t i = 0; i < numObjectives - 1; i++)
for (size_t i = 0; i < numObjectives - 1; i++)
{
objectives.row(i) = (1.0 - value %
arma::sin(coords.row(i) * arma::datum::pi * 0.5)) % (1. + G) *
Expand Down Expand Up @@ -185,7 +175,7 @@ namespace test {
// Convenience typedef.
typedef typename MatType::elem_type ElemType;
ElemType value = 1.0;
for(size_t i = 0; i < stop; i++)
for (size_t i = 0; i < stop; i++)
{
value = value * std::cos(coords[i] * arma::datum::pi * 0.5);
}
Expand All @@ -195,7 +185,7 @@ namespace test {
value = value * std::sin(coords[stop] * arma::datum::pi * 0.5);
}

value = std::pow(maf.GetA(), maf.GetNumObjectives() - stop) *
value = std::pow(maf.GetA(), maf.GetNumObjectives() - stop) *
(1 - value) * (1. + maf.g(coords)[0]);

return value;
Expand Down
14 changes: 2 additions & 12 deletions include/ensmallen_bits/problems/maf/maf5_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace test {
// A fixed no. of Objectives and Variables(|x| = 7, M = 3).
size_t numObjectives {3};
size_t numVariables {12};
size_t numParetoPoints;
size_t alpha;
size_t a;

Expand All @@ -74,9 +73,8 @@ namespace test {
* @param numParetoPoint No. of pareto points in the reference front.
* @param a The scale factor of the objectives.
*/
MAF5(size_t alpha = 100, size_t numParetoPoints = 136, double a = 2) :
MAF5(size_t alpha = 100, double a = 2) :
alpha(alpha),
numParetoPoints(numParetoPoints),
a(a),
objectiveF1(0, *this),
objectiveF2(1, *this),
Expand Down Expand Up @@ -125,14 +123,6 @@ namespace test {
void SetAlpha(size_t alpha)
{ this -> alpha = alpha; }

/**
* Set the no. of pareto points.
*
* @param numParetoPoint
*/
void SetNumParetoPoint(size_t numParetoPoint)
{ this -> numParetoPoints = numParetoPoint; }

/**
* Evaluate the G(x) with the given coordinate.
*
Expand Down Expand Up @@ -205,7 +195,7 @@ namespace test {
* arma::datum::pi * 0.5);
}

if (stop != maf.GetNumObjectives() - 1)
if(stop != maf.GetNumObjectives() - 1)
{
value = value * std::sin(std::pow(coords[stop], maf.GetAlpha())
* arma::datum::pi * 0.5);
Expand Down
Loading

0 comments on commit 4ba00c1

Please sign in to comment.