Passage du code dans un pretty printer

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1813 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-05-17 14:56:42 +00:00
commit 3d8057ac4d
88 changed files with 2726 additions and 2720 deletions

View file

@ -46,42 +46,42 @@
* To compute the autocorrelation function:
* Perform a random walk based on the neighborhood,
* The fitness values of solutions are collected during the random walk
* The autocorrelation can be computed from the serie of fitness values
*
* The autocorrelation can be computed from the serie of fitness values
*
*/
template <class Neighbor>
class moAutocorrelationSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of steps of the random walk
*/
moAutocorrelationSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moSampling<Neighbor>(_init, * new moRandomWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat){}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moAutocorrelationSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of steps of the random walk
*/
moAutocorrelationSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moSampling<Neighbor>(_init, * new moRandomWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat) {}
/**
* default destructor
*/
~moAutocorrelationSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moFitnessStat<EOT> fitnessStat;
};

View file

@ -42,40 +42,40 @@
#include <sampling/moSampling.h>
/**
* To compute the density of states:
* To compute the density of states:
* Sample the fitness of random solution in the search space
* The fitness values of solutions are collected during the random search
*
*
*/
template <class Neighbor>
class moDensityOfStatesSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval Fitness function, full evaluation function
* @param _nbSol Number of solutions in the sample
*/
moDensityOfStatesSampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat){}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moDensityOfStatesSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval Fitness function, full evaluation function
* @param _nbSol Number of solutions in the sample
*/
moDensityOfStatesSampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat) {}
/**
* default destructor
*/
~moDensityOfStatesSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moFitnessStat<EOT> fitnessStat;
};

View file

@ -45,7 +45,7 @@
#include <sampling/moSampling.h>
/**
* To compute the fitness distance correlation:
* To compute the fitness distance correlation:
* Sample the fitness and the distance from a particular solution of random solution in the search space
* The fitness values and distances of solutions are collected during the random search
* Then the correlation between the fitness and the distance can be computed
@ -55,40 +55,40 @@ template <class Neighbor>
class moFDCsampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval a full evaluation function
* @param _dist the distance function between solution
* @param _refSol the reference solution to compute the distance (think of global optimum when possible)
* @param _nbSol Number of solutions of the sample
*/
moFDCsampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
eoDistance<EOT>& _dist,
EOT& _refSol,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
distStat(_dist, _refSol)
{
add(distStat);
}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moFDCsampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval a full evaluation function
* @param _dist the distance function between solution
* @param _refSol the reference solution to compute the distance (think of global optimum when possible)
* @param _nbSol Number of solutions of the sample
*/
moFDCsampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
eoDistance<EOT>& _dist,
EOT& _refSol,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
distStat(_dist, _refSol)
{
add(distStat);
}
/**
* default destructor
*/
~moFDCsampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moDistanceStat<EOT> distStat;
moFitnessStat<EOT> fitnessStat;
moDistanceStat<EOT> distStat;
};

View file

@ -45,8 +45,8 @@
#include <sampling/moSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* This class do nothing. See others mo(...)FitnessCloudSampling classes
* with different fitness sampling methods
@ -55,44 +55,44 @@ template <class Neighbor>
class moFitnessCloudSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get a neighbor
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moDummyLS<Neighbor>(_fullEval), fitnessStat),
neighborhood(_neighborhood),
fullEval(_fullEval),
eval(_eval),
nbSol(_nbSol)
{}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moFitnessCloudSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get a neighbor
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moDummyLS<Neighbor>(_fullEval), fitnessStat),
neighborhood(_neighborhood),
fullEval(_fullEval),
eval(_eval),
nbSol(_nbSol)
{}
/**
* default destructor
*/
~moFitnessCloudSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moNeighborhood<Neighbor> & neighborhood;
eoEvalFunc<EOT>& fullEval;
moEval<Neighbor>& eval;
unsigned int nbSol;
moFitnessStat<EOT> fitnessStat;
moNeighborhood<Neighbor> & neighborhood;
eoEvalFunc<EOT>& fullEval;
moEval<Neighbor>& eval;
unsigned int nbSol;
moFitnessStat<EOT> fitnessStat;
};

View file

@ -52,58 +52,58 @@
* Perform a simple Hill-climber based on the neighborhood (adaptive walk),
* The lengths of HC are collected and the final solution which are local optima
* The adaptive walk is repeated several times
*
*
*/
template <class Neighbor>
class moHillClimberSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval a full evaluation function
* @param _eval an incremental evaluation of neighbors
* @param _nbAdaptWalk Number of adaptive walks
*/
moHillClimberSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbAdaptWalk) :
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
copyStat(lengthStat),
checkpoint(trueCont),
hc(_neighborhood, _fullEval, _eval, checkpoint),
initHC(_init, hc)
{
// to count the number of step in the HC
checkpoint.add(lengthStat);
using moSampling<Neighbor>::localSearch;
// add the solution into statistics
add(solStat);
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval a full evaluation function
* @param _eval an incremental evaluation of neighbors
* @param _nbAdaptWalk Number of adaptive walks
*/
moHillClimberSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbAdaptWalk) :
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
copyStat(lengthStat),
checkpoint(trueCont),
hc(_neighborhood, _fullEval, _eval, checkpoint),
initHC(_init, hc)
{
// to count the number of step in the HC
checkpoint.add(lengthStat);
/**
* default destructor
*/
~moHillClimberSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
// add the solution into statistics
add(solStat);
}
/**
* default destructor
*/
~moHillClimberSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moSolutionStat<EOT> solStat;
moMinusOneCounterStat<EOT> lengthStat;
moTrueContinuator<Neighbor> trueCont;
moStatFromStat<EOT, unsigned int> copyStat;
moCheckpoint<Neighbor> checkpoint;
moSimpleHC<Neighbor> hc;
moLocalSearchInit<Neighbor> initHC;
moSolutionStat<EOT> solStat;
moMinusOneCounterStat<EOT> lengthStat;
moTrueContinuator<Neighbor> trueCont;
moStatFromStat<EOT, unsigned int> copyStat;
moCheckpoint<Neighbor> checkpoint;
moSimpleHC<Neighbor> hc;
moLocalSearchInit<Neighbor> initHC;
};

View file

@ -44,8 +44,8 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Here solution are sampled with Metropolis-Hasting method
*
@ -53,59 +53,59 @@
* and the best fitness of k random neighbor
*
* The values are collected during the Metropolis-Hasting walk
*
*
*/
template <class Neighbor>
class moMHBestFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborBestStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborBestStat);
}
protected:
moNeighborBestStat< Neighbor > neighborBestStat;
moNeighborBestStat< Neighbor > neighborBestStat;
};

View file

@ -44,8 +44,8 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Here solution are sampled with Metropolis-Hasting method
*
@ -53,59 +53,59 @@
* and the fitness of one random neighbor
*
* The values are collected during the Metropolis-Hasting walk
*
*
*/
template <class Neighbor>
class moMHRndFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborFitnessStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborFitnessStat);
}
protected:
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
};

View file

@ -46,78 +46,78 @@
#include <sampling/moSampling.h>
/**
* To compute the neutral degree:
* To compute the neutral degree:
* Sample the fitness of random solution in the search space (1er information)
* and sample the neutral degree (2nd information), i.e. the number of neighbor solutions with the same fitness value
* The values are collected during the random search
*
*
*/
template <class Neighbor>
class moNeutralDegreeSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
using moSampling<Neighbor>::localSearch;
/**
* Constructor with comparators
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _neighborComparator a neighbor Comparator
* @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
/**
* default destructor
*/
~moNeutralDegreeSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Constructor with comparators
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _neighborComparator a neighbor Comparator
* @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
/**
* default destructor
*/
~moNeutralDegreeSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
moFitnessStat<EOT> fitnessStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
};

View file

@ -58,8 +58,8 @@
* To explore the evolvability of solutions in a neutral networks:
* Perform a random neutral walk based on the neighborhood,
* The measures of evolvability of solutions are collected during the random neutral walk
* The distribution and autocorrelation can be computed from the serie of values
*
* The distribution and autocorrelation can be computed from the serie of values
*
* Informations collected:
* - the current solution of the walk
* - the distance from the starting solution
@ -76,71 +76,71 @@ template <class Neighbor>
class moNeutralWalkSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _initSol the first the solution of the walk
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _distance the distance to measure the distance from the initial solution
* @param _nbStep Number of steps of the random walk
*/
moNeutralWalkSampling(EOT & _initSol,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
eoDistance<EOT> & _distance,
unsigned int _nbStep) :
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
init(_initSol),
distStat(_distance, _initSol),
neighborhoodStat(_neighborhood, _eval),
minStat(neighborhoodStat),
averageStat(neighborhoodStat),
stdStat(neighborhoodStat),
maxStat(neighborhoodStat),
nbSupStat(neighborhoodStat),
nbInfStat(neighborhoodStat),
sizeStat(neighborhoodStat),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(distStat);
add(minStat);
add(averageStat);
add(stdStat);
add(maxStat);
add(sizeStat);
add(nbInfStat);
add(ndStat);
add(nbSupStat);
}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moNeutralWalkSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _initSol the first the solution of the walk
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _distance the distance to measure the distance from the initial solution
* @param _nbStep Number of steps of the random walk
*/
moNeutralWalkSampling(EOT & _initSol,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
eoDistance<EOT> & _distance,
unsigned int _nbStep) :
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
init(_initSol),
distStat(_distance, _initSol),
neighborhoodStat(_neighborhood, _eval),
minStat(neighborhoodStat),
averageStat(neighborhoodStat),
stdStat(neighborhoodStat),
maxStat(neighborhoodStat),
nbSupStat(neighborhoodStat),
nbInfStat(neighborhoodStat),
sizeStat(neighborhoodStat),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(distStat);
add(minStat);
add(averageStat);
add(stdStat);
add(maxStat);
add(sizeStat);
add(nbInfStat);
add(ndStat);
add(nbSupStat);
}
/**
* default destructor
*/
~moNeutralWalkSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moSolInit<EOT> init;
moSolutionStat<EOT> solutionStat;
moDistanceStat<EOT> distStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moMinNeighborStat< Neighbor > minStat;
moAverageFitnessNeighborStat< Neighbor > averageStat;
moStdFitnessNeighborStat< Neighbor > stdStat;
moMaxNeighborStat< Neighbor > maxStat;
moNbSupNeighborStat< Neighbor > nbSupStat;
moNbInfNeighborStat< Neighbor > nbInfStat;
moSizeNeighborStat< Neighbor > sizeStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
moSolInit<EOT> init;
moSolutionStat<EOT> solutionStat;
moDistanceStat<EOT> distStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moMinNeighborStat< Neighbor > minStat;
moAverageFitnessNeighborStat< Neighbor > averageStat;
moStdFitnessNeighborStat< Neighbor > stdStat;
moMaxNeighborStat< Neighbor > maxStat;
moNbSupNeighborStat< Neighbor > nbSupStat;
moNbInfNeighborStat< Neighbor > nbInfStat;
moSizeNeighborStat< Neighbor > sizeStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
};

View file

@ -44,66 +44,66 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Sample the fitness of random solution in the search space
* and the best fitness of k random neighbor
*
* The values are collected during the random search
*
*
*/
template <class Neighbor>
class moRndBestFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborBestStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborBestStat);
}
protected:
moNeighborBestStat< Neighbor > neighborBestStat;
moNeighborBestStat< Neighbor > neighborBestStat;
};

View file

@ -44,66 +44,66 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Sample the fitness of random solution in the search space
* and the fitness of one random neighbor
*
* The values are collected during the random search
*
*
*/
template <class Neighbor>
class moRndRndFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborFitnessStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborFitnessStat);
}
protected:
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
};

View file

@ -51,159 +51,159 @@
* To sample the search space:
* A local search is used to sample the search space
* Some statistics are computed at each step of the local search
*
*
* Can be used to study the fitness landscape
*/
template <class Neighbor>
class moSampling : public eoF<void>
{
public:
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _localSearch local search to sample the search space
* @param _stat statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template <class ValueType>
moSampling(eoInit<EOT> & _init, moLocalSearch<Neighbor> & _localSearch, moStat<EOT,ValueType> & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator())
{
checkpoint = new moCheckpoint<Neighbor>(*continuator);
add(_stat, _monitoring);
}
typedef typename Neighbor::EOT EOT ;
/**
* default destructor
*/
~moSampling() {
// delete all monitors
for(unsigned i = 0; i < monitorVec.size(); i++)
delete monitorVec[i];
// delete the checkpoint
delete checkpoint ;
}
/**
* Add a statistic
* @param _stat another statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template< class ValueType >
void add(moStat<EOT, ValueType> & _stat, bool _monitoring = true) {
checkpoint->add(_stat);
if (_monitoring) {
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
monitorVec.push_back(monitor);
checkpoint->add(*monitor);
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _localSearch local search to sample the search space
* @param _stat statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template <class ValueType>
moSampling(eoInit<EOT> & _init, moLocalSearch<Neighbor> & _localSearch, moStat<EOT,ValueType> & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator())
{
checkpoint = new moCheckpoint<Neighbor>(*continuator);
add(_stat, _monitoring);
}
}
/**
* To sample the search and get the statistics
* the statistics are stored in the moVectorMonitor vector
*/
void operator()(void) {
// clear all statistic vectors
for(unsigned i = 0; i < monitorVec.size(); i++)
monitorVec[i]->clear();
/**
* default destructor
*/
~moSampling() {
// delete all monitors
for (unsigned i = 0; i < monitorVec.size(); i++)
delete monitorVec[i];
// change the checkpoint to compute the statistics
localSearch->setContinuator(*checkpoint);
// the initial solution
EOT solution;
// initialisation of the solution
init(solution);
// compute the sampling
(*localSearch)(solution);
// set back to initial continuator
localSearch->setContinuator(*continuator);
}
/**
* to export the vectors of values into one file
* @param _filename file name
* @param _delim delimiter between statistics
*/
void fileExport(std::string _filename, std::string _delim = " ") {
// create file
std::ofstream os(_filename.c_str());
if (!os) {
std::string str = "moSampling: Could not open " + _filename;
throw std::runtime_error(str);
// delete the checkpoint
delete checkpoint ;
}
// all vector have the same size
unsigned vecSize = monitorVec[0]->size();
for(unsigned int i = 0; i < vecSize; i++) {
os << monitorVec[0]->getValue(i);
for(unsigned int j = 1; j < monitorVec.size(); j++) {
os << _delim.c_str() << monitorVec[j]->getValue(i);
}
os << std::endl ;
/**
* Add a statistic
* @param _stat another statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template< class ValueType >
void add(moStat<EOT, ValueType> & _stat, bool _monitoring = true) {
checkpoint->add(_stat);
if (_monitoring) {
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
monitorVec.push_back(monitor);
checkpoint->add(*monitor);
}
}
}
/**
* to export one vector of values into a file
* @param _col number of vector to print into file
* @param _filename file name
*/
void fileExport(unsigned int _col, std::string _filename) {
if (_col >= monitorVec.size()) {
std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)";
throw std::runtime_error(str);
/**
* To sample the search and get the statistics
* the statistics are stored in the moVectorMonitor vector
*/
void operator()(void) {
// clear all statistic vectors
for (unsigned i = 0; i < monitorVec.size(); i++)
monitorVec[i]->clear();
// change the checkpoint to compute the statistics
localSearch->setContinuator(*checkpoint);
// the initial solution
EOT solution;
// initialisation of the solution
init(solution);
// compute the sampling
(*localSearch)(solution);
// set back to initial continuator
localSearch->setContinuator(*continuator);
}
monitorVec[_col]->fileExport(_filename);
}
/**
* to get one vector of values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<double> & getValues(unsigned int _numStat) {
return monitorVec[_numStat]->getValues();
}
/**
* to export the vectors of values into one file
* @param _filename file name
* @param _delim delimiter between statistics
*/
void fileExport(std::string _filename, std::string _delim = " ") {
// create file
std::ofstream os(_filename.c_str());
/**
* to get one vector of solutions values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<EOT> & getSolutions(unsigned int _numStat) {
return monitorVec[_numStat]->getSolutions();
}
if (!os) {
std::string str = "moSampling: Could not open " + _filename;
throw std::runtime_error(str);
}
// all vector have the same size
unsigned vecSize = monitorVec[0]->size();
for (unsigned int i = 0; i < vecSize; i++) {
os << monitorVec[0]->getValue(i);
for (unsigned int j = 1; j < monitorVec.size(); j++) {
os << _delim.c_str() << monitorVec[j]->getValue(i);
}
os << std::endl ;
}
}
/**
* to export one vector of values into a file
* @param _col number of vector to print into file
* @param _filename file name
*/
void fileExport(unsigned int _col, std::string _filename) {
if (_col >= monitorVec.size()) {
std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)";
throw std::runtime_error(str);
}
monitorVec[_col]->fileExport(_filename);
}
/**
* to get one vector of values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<double> & getValues(unsigned int _numStat) {
return monitorVec[_numStat]->getValues();
}
/**
* to get one vector of solutions values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<EOT> & getSolutions(unsigned int _numStat) {
return monitorVec[_numStat]->getSolutions();
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moSampling";
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moSampling";
}
protected:
eoInit<EOT> & init;
moLocalSearch<Neighbor> * localSearch;
eoInit<EOT> & init;
moLocalSearch<Neighbor> * localSearch;
moContinuator<Neighbor> * continuator;
moCheckpoint<Neighbor> * checkpoint;
moContinuator<Neighbor> * continuator;
moCheckpoint<Neighbor> * checkpoint;
// std::vector<moStatBase<EOT>*> statVec;
std::vector< moVectorMonitor<EOT> *> monitorVec;
// std::vector<moStatBase<EOT>*> statVec;
std::vector< moVectorMonitor<EOT> *> monitorVec;
};

View file

@ -41,174 +41,174 @@
/**
* Tools to compute some basic statistics
*
*
* Remember it is better to use some statistic tool like R, etc.
* But it could be usefull to have here in paradisEO
*/
class moStatistics
class moStatistics
{
public:
/**
* Default Constructor
*/
moStatistics() { }
/**
* Default Constructor
*/
moStatistics() { }
/**
* To compute min, max , average and standard deviation of a vector of double
*
* @param data vector of double
* @param min to compute
* @param max to compute
* @param avg average to compute
* @param std standard deviation to compute
*/
void basic(const std::vector<double> & data,
double & min, double & max, double & avg, double & std) {
if (data.size() == 0) {
min = 0.0;
max = 0.0;
avg = 0.0;
std = 0.0;
} else {
unsigned int n = data.size();
/**
* To compute min, max , average and standard deviation of a vector of double
*
* @param data vector of double
* @param min to compute
* @param max to compute
* @param avg average to compute
* @param std standard deviation to compute
*/
void basic(const std::vector<double> & data,
double & min, double & max, double & avg, double & std) {
min = data[0];
max = data[0];
avg = 0.0;
std = 0.0;
if (data.size() == 0) {
min = 0.0;
max = 0.0;
avg = 0.0;
std = 0.0;
} else {
unsigned int n = data.size();
double d;
for(unsigned int i = 0; i < n; i++) {
d = data[i];
if (d < min)
min = d;
if (max < d)
max = d;
avg += d;
std += d * d;
}
min = data[0];
max = data[0];
avg = 0.0;
std = 0.0;
avg /= n;
double d;
for (unsigned int i = 0; i < n; i++) {
d = data[i];
if (d < min)
min = d;
if (max < d)
max = d;
avg += d;
std += d * d;
}
std = std / n - avg * avg ;
if (std > 0)
std = sqrt(std);
avg /= n;
std = std / n - avg * avg ;
if (std > 0)
std = sqrt(std);
}
}
}
/**
* To compute the distance between solutions
*
* @param data vector of solutions
* @param distance method to compute the distance
* @param matrix matrix of distances between solutions
*/
template <class EOT>
void distances(const std::vector<EOT> & data, eoDistance<EOT> & distance,
std::vector< std::vector<double> > & matrix) {
if (data.size() == 0) {
matrix.resize(0);
} else {
unsigned int n = data.size();
/**
* To compute the distance between solutions
*
* @param data vector of solutions
* @param distance method to compute the distance
* @param matrix matrix of distances between solutions
*/
template <class EOT>
void distances(const std::vector<EOT> & data, eoDistance<EOT> & distance,
std::vector< std::vector<double> > & matrix) {
if (data.size() == 0) {
matrix.resize(0);
} else {
unsigned int n = data.size();
matrix.resize(n);
for(unsigned i = 0; i < n; i++)
matrix[i].resize(n);
matrix.resize(n);
for (unsigned i = 0; i < n; i++)
matrix[i].resize(n);
unsigned j;
for(unsigned i = 0; i < n; i++) {
matrix[i][i] = 0.0;
for(j = 0; j < i; j++) {
matrix[i][j] = distance(data[i], data[j]);
matrix[j][i] = matrix[i][j];
}
}
unsigned j;
for (unsigned i = 0; i < n; i++) {
matrix[i][i] = 0.0;
for (j = 0; j < i; j++) {
matrix[i][j] = distance(data[i], data[j]);
matrix[j][i] = matrix[i][j];
}
}
}
}
}
/**
* To compute the autocorrelation and partial autocorrelation
*
* @param data vector of double
* @param nbS number of correlation coefficients
* @param rho autocorrelation coefficients
* @param phi partial autocorrelation coefficients
*/
void autocorrelation(const std::vector<double> & data, unsigned int nbS,
std::vector<double> & rho, std::vector<double> & phi) {
if (data.size() == 0) {
rho.resize(0);
phi.resize(0);
} else {
unsigned int n = data.size();
/**
* To compute the autocorrelation and partial autocorrelation
*
* @param data vector of double
* @param nbS number of correlation coefficients
* @param rho autocorrelation coefficients
* @param phi partial autocorrelation coefficients
*/
void autocorrelation(const std::vector<double> & data, unsigned int nbS,
std::vector<double> & rho, std::vector<double> & phi) {
if (data.size() == 0) {
rho.resize(0);
phi.resize(0);
} else {
unsigned int n = data.size();
double cov[nbS+1];
double m[nbS+1];
double sig[nbS+1];
double cov[nbS+1];
double m[nbS+1];
double sig[nbS+1];
rho.resize(nbS+1);
phi.resize(nbS+1);
rho[0] = 1.0;
phi[0] = 1.0; // ?
unsigned s, k;
rho.resize(nbS+1);
phi.resize(nbS+1);
rho[0] = 1.0;
phi[0] = 1.0; // ?
for(s = 0; s <= nbS; s++) {
cov[s] = 0;
m[s] = 0;
sig[s] = 0;
}
unsigned s, k;
double m0, s0;
unsigned j;
for (s = 0; s <= nbS; s++) {
cov[s] = 0;
m[s] = 0;
sig[s] = 0;
}
k = 0;
s = nbS;
while (s > 0) {
while (k + s < n) {
for(j = 0; j <= s; j++) {
m[j] += data[k+j];
sig[j] += data[k+j] * data[k+j];
cov[j] += data[k] * data[k+j];
}
k++;
}
m[s] /= n - s;
sig[s] = sig[s] / (n - s) - m[s] * m[s];
if (sig[s] <= 0)
sig[s] = 0;
else
sig[s] = sqrt(sig[s]);
m0 = m[0] / (n - s);
s0 = sqrt(sig[0] / (n - s) - m0 * m0);
cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s];
rho[s] = cov[s] / (sig[s] * s0);
s--;
}
double m0, s0;
unsigned j;
double phi2[nbS+1][nbS+1];
double tmp1, tmp2;
k = 0;
s = nbS;
while (s > 0) {
while (k + s < n) {
for (j = 0; j <= s; j++) {
m[j] += data[k+j];
sig[j] += data[k+j] * data[k+j];
cov[j] += data[k] * data[k+j];
}
k++;
}
phi2[1][1] = rho[1];
for(k = 2; k <= nbS; k++) {
tmp1 = 0;
tmp2 = 0;
for(j = 1; j < k; j++) {
tmp1 += phi2[k-1][j] * rho[k-j];
tmp2 += phi2[k-1][j] * rho[j];
}
phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2);
for(j = 1; j < k; j++)
phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j];
}
for(j = 1; j <= nbS; j++)
phi[j] = phi2[j][j];
m[s] /= n - s;
sig[s] = sig[s] / (n - s) - m[s] * m[s];
if (sig[s] <= 0)
sig[s] = 0;
else
sig[s] = sqrt(sig[s]);
m0 = m[0] / (n - s);
s0 = sqrt(sig[0] / (n - s) - m0 * m0);
cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s];
rho[s] = cov[s] / (sig[s] * s0);
s--;
}
double phi2[nbS+1][nbS+1];
double tmp1, tmp2;
phi2[1][1] = rho[1];
for (k = 2; k <= nbS; k++) {
tmp1 = 0;
tmp2 = 0;
for (j = 1; j < k; j++) {
tmp1 += phi2[k-1][j] * rho[k-j];
tmp2 += phi2[k-1][j] * rho[j];
}
phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2);
for (j = 1; j < k; j++)
phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j];
}
for (j = 1; j <= nbS; j++)
phi[j] = phi2[j][j];
}
}
}
};