intermediate commit 7
This commit is contained in:
parent
9d0b83022d
commit
ba19b29a22
3 changed files with 76 additions and 27 deletions
|
|
@ -52,7 +52,11 @@ public :
|
|||
moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) {
|
||||
monitors.push_back(&_mon);
|
||||
}
|
||||
|
||||
|
||||
moCounterMonitorSaver(unsigned _interval)
|
||||
: interval(_interval), counter(0)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* call monitors if interval is reach by a counter
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -35,8 +35,11 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
|
|||
#include <continuator/moFitnessMomentsStat.h>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
//#include <iostream>
|
||||
//using namespace std;
|
||||
|
||||
#include <limits>
|
||||
|
||||
|
||||
//!
|
||||
/*!
|
||||
|
|
@ -51,23 +54,30 @@ public:
|
|||
//! Constructor
|
||||
/*!
|
||||
*/
|
||||
|
||||
moHuangCoolingSchedule (double _initTemp, double _stdDevEstimation, double _lambda = .7, double _finalTemp = .01)
|
||||
: initTemp(_initTemp),
|
||||
stdDevEstimation(_stdDevEstimation),
|
||||
lambda(_lambda),
|
||||
finalTemp(_finalTemp)
|
||||
{ }
|
||||
|
||||
// moHuangCoolingSchedule (double _initTemp, int _spanSize, double _lambda = .7, double _finalTemp = .01)
|
||||
// moHuangCoolingSchedule (double _initTemp, int _spanSize, double _lambda = .7, double _finalStdDev = .01)
|
||||
moHuangCoolingSchedule (double _initTemp, int _spanSize, double _lambda = .7, double _finalTempDecrease = .995)
|
||||
: initTemp(_initTemp)
|
||||
, spanSize(_spanSize)
|
||||
, lambda(_lambda)
|
||||
// , finalTemp(_finalTemp)
|
||||
, finalStdDev(_finalTempDecrease)
|
||||
// , statIsInitialized(false)
|
||||
// , step(0)
|
||||
// , currentStdDevEstimation(std::numeric_limits<double>::max())
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Initial temperature
|
||||
* @param _solution initial solution
|
||||
*/
|
||||
double init(EOT & _solution) {
|
||||
|
||||
statIsInitialized = terminated = false;
|
||||
step = 0;
|
||||
return initTemp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update the temperature by a factor
|
||||
* @param _temp current temperature to update
|
||||
|
|
@ -75,8 +85,30 @@ public:
|
|||
*/
|
||||
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
|
||||
|
|
@ -84,8 +116,9 @@ public:
|
|||
*/
|
||||
bool operator() (double temperature)
|
||||
{
|
||||
return temperature > finalTemp;
|
||||
|
||||
//return temperature > finalTemp;
|
||||
//return currentStdDevEstimation > finalStdDev;
|
||||
return !terminated;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -93,11 +126,19 @@ private:
|
|||
|
||||
const double
|
||||
// parameters of the algorithm
|
||||
initTemp,
|
||||
stdDevEstimation,
|
||||
lambda,
|
||||
finalTemp
|
||||
initTemp
|
||||
// , stdDevEstimation
|
||||
, lambda
|
||||
// , finalTemp
|
||||
, finalStdDev
|
||||
;
|
||||
const int spanSize;
|
||||
int step;
|
||||
|
||||
//double currentStdDevEstimation;
|
||||
|
||||
moFitnessMomentsStat<EOT> momentStat;
|
||||
bool statIsInitialized, terminated;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,8 @@ public:
|
|||
|
||||
negative_temp = equilibrium_not_reached = frozen = 0;
|
||||
|
||||
chainStat.delta = initTemp/mu2;
|
||||
|
||||
//cout << "acc " << max_accepted << " " << max_generated << endl;
|
||||
|
||||
/*
|
||||
|
|
@ -230,7 +232,9 @@ public:
|
|||
//double stdDev = sqrt(variance);
|
||||
chainStat.stdDev = sqrt(variance);
|
||||
double sigma = chainStat.stdDev;
|
||||
double delta = sigma/mu2;
|
||||
///////////////
|
||||
//double delta = sigma/mu2;
|
||||
///////////////
|
||||
|
||||
|
||||
//outf << avgFitness << endl;
|
||||
|
|
@ -262,7 +266,7 @@ public:
|
|||
//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;
|
||||
else equilibrium_not_reached = 0;
|
||||
}
|
||||
|
|
@ -277,10 +281,10 @@ public:
|
|||
//chainStat.equilibriumNotReached = true;
|
||||
|
||||
alpha = lambda1;
|
||||
delta = sigma/mu1;
|
||||
chainStat.delta = sigma/mu1;
|
||||
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;
|
||||
|
|
@ -293,7 +297,7 @@ public:
|
|||
if (negative_temp < K2)
|
||||
{
|
||||
alpha = lambda1;
|
||||
delta = sigma/mu1;
|
||||
chainStat.delta = sigma/mu1;
|
||||
} else
|
||||
alpha = lambda2;
|
||||
}
|
||||
|
|
@ -320,7 +324,7 @@ public:
|
|||
reinitializing = false;
|
||||
//chainStat.avgFitness = avgFitness;
|
||||
//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
|
||||
|
||||
|
|
@ -338,12 +342,12 @@ public:
|
|||
|
||||
chainStat.currentFitness = _solution.fitness(); // FIXME here?
|
||||
chainStat.alpha = alpha;
|
||||
chainStat.delta = delta;
|
||||
//chainStat.delta = delta;
|
||||
chainStat.avgFitness = avgFitness;
|
||||
|
||||
|
||||
// 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++;
|
||||
else frozen = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue