intermediate commit 7

This commit is contained in:
LPTK 2013-07-15 11:34:55 +02:00
commit ba19b29a22
3 changed files with 76 additions and 27 deletions

View file

@ -53,6 +53,10 @@ public :
monitors.push_back(&_mon); monitors.push_back(&_mon);
} }
moCounterMonitorSaver(unsigned _interval)
: interval(_interval), counter(0)
{ }
/** /**
* call monitors if interval is reach by a counter * call monitors if interval is reach by a counter
*/ */

View file

@ -35,8 +35,11 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
#include <continuator/moFitnessMomentsStat.h> #include <continuator/moFitnessMomentsStat.h>
#include <iostream> //#include <iostream>
using namespace std; //using namespace std;
#include <limits>
//! //!
/*! /*!
@ -52,11 +55,17 @@ public:
/*! /*!
*/ */
moHuangCoolingSchedule (double _initTemp, double _stdDevEstimation, double _lambda = .7, double _finalTemp = .01) // moHuangCoolingSchedule (double _initTemp, int _spanSize, double _lambda = .7, double _finalTemp = .01)
: initTemp(_initTemp), // moHuangCoolingSchedule (double _initTemp, int _spanSize, double _lambda = .7, double _finalStdDev = .01)
stdDevEstimation(_stdDevEstimation), moHuangCoolingSchedule (double _initTemp, int _spanSize, double _lambda = .7, double _finalTempDecrease = .995)
lambda(_lambda), : initTemp(_initTemp)
finalTemp(_finalTemp) , spanSize(_spanSize)
, lambda(_lambda)
// , finalTemp(_finalTemp)
, finalStdDev(_finalTempDecrease)
// , statIsInitialized(false)
// , step(0)
// , currentStdDevEstimation(std::numeric_limits<double>::max())
{ } { }
/** /**
@ -64,7 +73,8 @@ public:
* @param _solution initial solution * @param _solution initial solution
*/ */
double init(EOT & _solution) { double init(EOT & _solution) {
statIsInitialized = terminated = false;
step = 0;
return initTemp; return initTemp;
} }
@ -75,8 +85,30 @@ public:
*/ */
void update(double& _temp, bool _acceptedMove, EOT & _solution) { void update(double& _temp, bool _acceptedMove, EOT & _solution) {
_temp *= exp ( -lambda*_temp / stdDevEstimation ) ; if (_acceptedMove)
{
if (statIsInitialized)
momentStat(_solution);
else momentStat.init(_solution), statIsInitialized = true;
}
if (step >= spanSize)
{
step = 0;
/*
//double avgFitness = momentStat.value().first;
double variance = momentStat.value().second;
//double stdDevEstimation = sqrt(variance);
double currentStdDevEstimation = sqrt(variance);
_temp *= exp( -lambda*_temp / currentStdDevEstimation );*/
double alpha = exp( -lambda*_temp / sqrt(momentStat.value().second) );
_temp *= alpha;
//std::cout << alpha << std::endl;
terminated = alpha > finalStdDev;
}
step++;
} }
//! Function which proceeds to the cooling //! Function which proceeds to the cooling
@ -84,8 +116,9 @@ public:
*/ */
bool operator() (double temperature) bool operator() (double temperature)
{ {
return temperature > finalTemp; //return temperature > finalTemp;
//return currentStdDevEstimation > finalStdDev;
return !terminated;
} }
@ -93,11 +126,19 @@ private:
const double const double
// parameters of the algorithm // parameters of the algorithm
initTemp, initTemp
stdDevEstimation, // , stdDevEstimation
lambda, , lambda
finalTemp // , finalTemp
, finalStdDev
; ;
const int spanSize;
int step;
//double currentStdDevEstimation;
moFitnessMomentsStat<EOT> momentStat;
bool statIsInitialized, terminated;
}; };

View file

@ -144,6 +144,8 @@ public:
negative_temp = equilibrium_not_reached = frozen = 0; negative_temp = equilibrium_not_reached = frozen = 0;
chainStat.delta = initTemp/mu2;
//cout << "acc " << max_accepted << " " << max_generated << endl; //cout << "acc " << max_accepted << " " << max_generated << endl;
/* /*
@ -230,7 +232,9 @@ public:
//double stdDev = sqrt(variance); //double stdDev = sqrt(variance);
chainStat.stdDev = sqrt(variance); chainStat.stdDev = sqrt(variance);
double sigma = chainStat.stdDev; double sigma = chainStat.stdDev;
double delta = sigma/mu2; ///////////////
//double delta = sigma/mu2;
///////////////
//outf << avgFitness << endl; //outf << avgFitness << endl;
@ -262,7 +266,7 @@ public:
//if (avgFitness/(chainStat.prevAvgFitness-delta) > xi) cout << "/!\\ eq not reached!" << endl; //if (avgFitness/(chainStat.prevAvgFitness-delta) > xi) cout << "/!\\ eq not reached!" << endl;
/// ///
if (avgFitness/(prevAvgFitness-delta) > xi) if (avgFitness/(prevAvgFitness-chainStat.delta) > xi)
equilibrium_not_reached++, chainStat.equilibriumNotReached = true; equilibrium_not_reached++, chainStat.equilibriumNotReached = true;
else equilibrium_not_reached = 0; else equilibrium_not_reached = 0;
} }
@ -277,10 +281,10 @@ public:
//chainStat.equilibriumNotReached = true; //chainStat.equilibriumNotReached = true;
alpha = lambda1; alpha = lambda1;
delta = sigma/mu1; chainStat.delta = sigma/mu1;
equilibrium_not_reached = 0; // ADDED! Otherwise the algo gets trapped here! equilibrium_not_reached = 0; // ADDED! Otherwise the algo gets trapped here!
} }
else if (_temp*delta/(sigma*sigma) >= 1) else if (_temp*chainStat.delta/(sigma*sigma) >= 1)
{ {
/// ///
//cout << "/!\\ neg temp!" << endl; //cout << "/!\\ neg temp!" << endl;
@ -293,7 +297,7 @@ public:
if (negative_temp < K2) if (negative_temp < K2)
{ {
alpha = lambda1; alpha = lambda1;
delta = sigma/mu1; chainStat.delta = sigma/mu1;
} else } else
alpha = lambda2; alpha = lambda2;
} }
@ -320,7 +324,7 @@ public:
reinitializing = false; reinitializing = false;
//chainStat.avgFitness = avgFitness; //chainStat.avgFitness = avgFitness;
//alpha = 1-_temp*delta/(sigma*sigma); //alpha = 1-_temp*delta/(sigma*sigma);
alpha = 1-_temp*delta/variance; alpha = 1-_temp*chainStat.delta/variance;
//alpha = (sigma==0? 1: 1-_temp*delta/(sigma*sigma)); // ADDED! but removed //alpha = (sigma==0? 1: 1-_temp*delta/(sigma*sigma)); // ADDED! but removed
@ -338,12 +342,12 @@ public:
chainStat.currentFitness = _solution.fitness(); // FIXME here? chainStat.currentFitness = _solution.fitness(); // FIXME here?
chainStat.alpha = alpha; chainStat.alpha = alpha;
chainStat.delta = delta; //chainStat.delta = delta;
chainStat.avgFitness = avgFitness; chainStat.avgFitness = avgFitness;
// Never seems to be used // Never seems to be used
if (avgFitness == prevAvgFitness) // use a neighborhood to approximate double equality? if (avgFitness == prevAvgFitness) // use a neighborhood to approximate double floating equality?
frozen++; frozen++;
else frozen = 0; else frozen = 0;