Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jaduro committed Jan 2, 2021
1 parent b1b2dd2 commit 0e45d27
Showing 1 changed file with 4 additions and 92 deletions.
96 changes: 4 additions & 92 deletions tests/auto/test_tigon/test_sparego/tst_sparego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ private slots:
void test_sParEGO_workflow();
void test_sParEGO();
void test_LogDirectionVector();
void test_sParEGOWithMonteCarloValidation();
};

inline void writeVector(QTextStream &st, TVector<double> vec, QString sep = "\t", QString endLine = "\n")
{
for(int i=0; i<vec.size(); i++) {
for(size_t i=0; i<vec.size(); i++) {
st << vec[i];
if(i<vec.size()-1) {
st << sep;
Expand Down Expand Up @@ -248,8 +247,8 @@ void tst_sparego::test_SparegoInit()

TVector<ISet*> neighbourhoods = nFilt->outputSets();
TVector<int> counts;
for(int i=0; i<neighbourhoods.size(); i++) {
int s = neighbourhoods[i]->size();
for(size_t i=0; i<neighbourhoods.size(); i++) {
size_t s = neighbourhoods[i]->size();
if(counts.size() < s) {
counts.resize(s);
}
Expand Down Expand Up @@ -882,7 +881,6 @@ void tst_sparego::test_sParEGO()
double nRaduis = 0.2;
int budget = 14;
int maxSurrogateSize = 30;
int stallIterations = 10;

PSetBase* base = new PSetBase();
IFormulation* prob = new IFormulation(base);
Expand Down Expand Up @@ -938,7 +936,6 @@ void tst_sparego::test_LogDirectionVector()
// the maximum distance for neighbourhood is 0.2*sqrt(8) ~= 0.56569
double nRaduis = 0.2;
int maxSurrogateSize = 10;
int stallIterations = 10;

/// sParEGO optimization workflow
PSetBase* base = new PSetBase();
Expand Down Expand Up @@ -981,7 +978,7 @@ void tst_sparego::test_LogDirectionVector()

TVector<double> dv = sol->weightingVec();

for(int i=0; i<ref.size(); i++) {
for(size_t i=0; i<ref.size(); i++) {
if( areVectorsEqual(ref[i],dv) ) {
foundRef[i]=true;
break;
Expand All @@ -1000,91 +997,6 @@ void tst_sparego::test_LogDirectionVector()
delete base;
}

void tst_sparego::test_sParEGOWithMonteCarloValidation()
{
TRAND.defineSeed(0);
cout.precision(4);

int dVecSize = 3;
int oVecSize = 2;
int N = 20; // number of Monte Carlo evaluations
int popsize = 8; // population size generated by SparegoInit
double nRaduis = 0.2;
int nDirs = 6;
int nIter = 2;
int maxSurrogateSize = 100;
double confidenceLevel = 0.9;
int stallIterations = 10;

int budget = 0;
for(int i=1; i<=(nDirs*nIter); i++) {
budget += N * (popsize + (i*2-2));
}
// 1. iteration: popsize*N
// 2. iteration: popsize*N + 2*N
// 3. iteration: popsize*N + 4*N
// 4. iteration: popsize*N + 6*N
// ...
// 12. iteration: popsize*N + 22*N

/// create the workflow
PSetBase* base = new PSetBase();
IFormulation* form = new IFormulation(base);
sParEGOInit* init = new sParEGOInit(form);
SimplexLatticeDirectionIterator* dirs =
new SimplexLatticeDirectionIterator(init);

ValidationWithScalarisation* val = new ValidationWithScalarisation(dirs);
RobustnessAssignment* iVal = new RobustnessAssignment(val);
DirectionFitnessFiltration* filt = new DirectionFitnessFiltration(iVal);
SurrogateBasedOptimizerWithPerturbation* opt =
new SurrogateBasedOptimizerWithPerturbation(filt);

IFunctionSPtr func = IFunctionSPtr(new DTLZ2);
func->TP_defineNInputs(dVecSize);
func->TP_defineNOutputs(oVecSize);
form->appendFunction(func);

init->TP_defineSetSize(popsize);
init->TP_defineNeighbourhoodRadius(nRaduis);
init->addOutputTag(Tigon::TValidation);

dirs->TP_defineReferenceSetSize(nDirs);

filt->TP_defineMaxSolutions(maxSurrogateSize);

val->TP_defineOperateOnFinal(false);
val->TP_defineCountEvaluations(true);
val->TP_defineScalarisingFunction(Tigon::WeightedChebyshev);
val->TP_defineNEvaluations(N);
val->addAdditionalOutputTag(Tigon::TFitness);

opt->defineBudget(budget);
opt->TP_defineNeighbourhoodRadius(nRaduis);
opt->TP_defineErrorMethod(Tigon::ErrConfidenceIntervalBased);
opt->TP_defineOptimizationSearchQuality(0);

iVal->defineIndicator(ConfidenceType, confidenceLevel);

while(opt->remainingBudget() > 0) {
opt->evaluate();
opt->incrementIteration();

cout << "Iteration: " << opt->currentIteration()
<< ", Used budget " << opt->usedBudget()
<< ", Remaining budget " << opt->remainingBudget() << endl;
}

delete opt;
delete filt;
delete iVal;
delete val;
delete dirs;
delete init;
delete form;
delete base;
}

QTEST_GUILESS_MAIN(tst_sparego)

#include "tst_sparego.moc"

0 comments on commit 0e45d27

Please sign in to comment.