metrics modification

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@180 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-02-14 15:08:50 +00:00
commit 6d62e3f13a
4 changed files with 78 additions and 70 deletions

View file

@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// moeoBinaryMetricSavingUpdater.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -20,18 +20,18 @@
#include <metric/moeoMetric.h>
/**
* This class allows to save the progression of a binary metric comparing the fitness values of the current population (or archive)
* with the fitness values of the population (or archive) of the generation (n-1) into a file
* This class allows to save the progression of a binary metric comparing the objective vectors of the current population (or archive)
* with the objective vectors of the population (or archive) of the generation (n-1) into a file
*/
template <class EOT>
template < class MOEOT >
class moeoBinaryMetricSavingUpdater : public eoUpdater
{
public:
/**
* The fitness type of a solution
* The objective vector type of a solution
*/
typedef typename EOT::ObjectiveVector ObjectiveVector;
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor
@ -39,7 +39,7 @@ public:
* @param _pop the main population
* @param _filename the target filename
*/
moeoBinaryMetricSavingUpdater (moeoPopVsPopBinaryMetric<EOT,double> & _metric, const eoPop<EOT> & _pop, std::string _filename) :
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
metric(_metric), pop(_pop), filename(_filename), counter(1)
{}
@ -53,17 +53,15 @@ public:
}
else {
// creation of the two Pareto sets
/*
std::vector<ObjectiveVector> from;
std::vector<ObjectiveVector> to;
std::vector < ObjectiveVector > from;
std::vector < ObjectiveVector > to;
for (unsigned i=0; i<pop.size(); i++)
from.push_back(pop[i].objectiveVector());
for (unsigned i=0 ; i<oldPop.size(); i++)
to.push_back(oldPop[i].objectiveVector());
*/
// writing the result into the file
std::ofstream f (filename.c_str(), std::ios::app);
f << counter++ << ' ' << metric(pop,oldPop) << std::endl;
f << counter++ << ' ' << metric(from,to) << std::endl;
f.close();
}
oldPop = pop;
@ -73,11 +71,11 @@ public:
private:
/** binary metric comparing two Pareto sets */
moeoPopVsPopBinaryMetric<EOT,double> & metric;
moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
/** main population */
const eoPop<EOT> & pop;
const eoPop < MOEOT > & pop;
/** (n-1) population */
eoPop<EOT> oldPop;
eoPop< MOEOT > oldPop;
/** target filename */
std::string filename;
/** is it the first generation ? */

View file

@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// moeoContributionMetric.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -17,37 +17,24 @@
/**
* The contribution metric evaluates the proportion of non-dominated solutions given by a Pareto set relatively to another Pareto set
*
* (Meunier, Talbi, Reininger: 'A multiobjective genetic algorithm for radio network optimization', in Proc. of the 2000 Congress on Evolutionary Computation, IEEE Press, pp. 317-324)
*/
template < class MOEOT >
class moeoContributionMetric : public moeoPopVsPopBinaryMetric < MOEOT, double >
template < class ObjectiveVector >
class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
{
public:
/** the objective vector type of a solution */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2'
* @param _set1 the first Pareto set
* @param _set2 the second Pareto set
*/
double operator()(const eoPop < MOEOT > & _pop1, const eoPop < MOEOT > & _pop2) {
/************/
std::vector<ObjectiveVector> set1;
std::vector<ObjectiveVector> set2;
for (unsigned i=0; i<_pop1.size(); i++)
set1.push_back(_pop1[i].objectiveVector());
for (unsigned i=0 ; i<_pop2.size(); i++)
set2.push_back(_pop2[i].objectiveVector());
/****************/
unsigned c = card_C(set1, set2);
unsigned w1 = card_W(set1, set2);
unsigned n1 = card_N(set1, set2);
unsigned w2 = card_W(set2, set1);
unsigned n2 = card_N(set2, set1);
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned c = card_C(_set1, _set2);
unsigned w1 = card_W(_set1, _set2);
unsigned n1 = card_N(_set1, _set2);
unsigned w2 = card_W(_set2, _set1);
unsigned n2 = card_N(_set2, _set1);
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
}

View file

@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// moeoEntropyMetric.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -16,18 +16,14 @@
#include <metric/moeoMetric.h>
/**
* The entropy gives an idea of the diversity of a Pareto set relatively to another Pareto set
*
* The entropy gives an idea of the diversity of a Pareto set relatively to another
* (Basseur, Seynhaeve, Talbi: 'Design of Multi-objective Evolutionary Algorithms: Application to the Flow-shop Scheduling Problem', in Proc. of the 2002 Congress on Evolutionary Computation, IEEE Press, pp. 1155-1156)
*/
template < class MOEOT >
class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < MOEOT, double >
template < class ObjectiveVector >
class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
{
public:
/** the objective vector type of a solution */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2'
* @param _set1 the first Pareto set
@ -72,10 +68,17 @@ public:
private:
/** vector of min values */
std::vector<double> vect_min_val;
/** vector of max values */
std::vector<double> vect_max_val;
void removeDominated(std::vector< ObjectiveVector > & _f) {
/**
* Removes the dominated individuals contained in _f
* @param _f a Pareto set
*/
void removeDominated(std::vector < ObjectiveVector > & _f) {
for (unsigned i=0 ; i<_f.size(); i++) {
bool dom = false;
for (unsigned j=0; j<_f.size(); j++)
@ -91,6 +94,11 @@ private:
}
}
/**
* Prenormalization
* @param _f a Pareto set
*/
void prenormalize (const std::vector< ObjectiveVector > & _f) {
vect_min_val.clear();
vect_max_val.clear();
@ -108,12 +116,24 @@ private:
}
}
/**
* Normalization
* @param _f a Pareto set
*/
void normalize (std::vector< ObjectiveVector > & _f) {
for (unsigned i=0 ; i<ObjectiveVector::nObjectives(); i++)
for (unsigned j=0; j<_f.size(); j++)
_f[j][i] = (_f[j][i] - vect_min_val[i]) / (vect_max_val[i] - vect_min_val[i]);
}
/**
* Computation of the union of _f1 and _f2 in _f
* @param _f1 the first Pareto set
* @param _f2 the second Pareto set
* @param _f the final Pareto set
*/
void computeUnion(const std::vector< ObjectiveVector > & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f) {
_f = _f1 ;
for (unsigned i=0; i<_f2.size(); i++) {
@ -128,6 +148,10 @@ private:
}
}
/**
* How many in niche
*/
unsigned howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned _size) {
unsigned n=0;
for (unsigned i=0 ; i<_f.size(); i++) {
@ -137,6 +161,10 @@ private:
return n;
}
/**
* Euclidian distance
*/
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned _deg = 2) {
double dist=0;
for (unsigned i=0; i<_set1.size(); i++)

View file

@ -16,14 +16,14 @@
#include <eoFunctor.h>
/**
* Base class for performance metrics (also called quality indicators)
* Base class for performance metrics (also known as quality indicators).
*/
class moeoMetric : public eoFunctorBase
{};
/**
* Base class for unary metrics
* Base class for unary metrics.
*/
template < class A, class R >
class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric
@ -31,7 +31,7 @@ class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric
/**
* Base class for binary metrics
* Base class for binary metrics.
*/
template < class A1, class A2, class R >
class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric
@ -39,47 +39,42 @@ class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric
/**
* Base class for unary metrics dedicated to the performance evaluation of a single solution's Pareto fitness
* Base class for unary metrics dedicated to the performance evaluation of a single solution's objective vector.
*/
template < class MOEOT, class R>//, class ObjVector = typename MOEOT::ObjectiveVector >
//class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjVector &, R >
class moeoSolutionUnaryMetric : public moeoUnaryMetric < const MOEOT &, R >
template < class ObjectiveVector, class R >
class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R >
{};
/**
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of Pareto fitnesses)
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of objective vectors)
*/
template < class MOEOT, class R>//, class ObjVector = typename MOEOT::ObjectiveVector >
//class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjVector > &, R >
class moeoPopUnaryMetric : public moeoUnaryMetric < const eoPop < MOEOT > &, R >
template < class ObjectiveVector, class R >
class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R >
{};
/**
* Base class for binary metrics dedicated to the performance comparison between two solutions's Pareto fitnesses
* Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors.
*/
template < class MOEOT, class R>//, class ObjVector = typename MOEOT::ObjectiveVector >
//class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjVector &, const ObjVector &, R >
class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const MOEOT &, const MOEOT &, R >
template < class ObjectiveVector, class R >
class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R >
{};
/**
* Base class for binary metrics dedicated to the performance comparison between a Pareto set (a vector of Pareto fitnesses) and a single solution's Pareto fitness
* Base class for binary metrics dedicated to the performance comparison between a Pareto set (a vector of objective vectors) and a single solution's objective vector.
*/
template < class MOEOT, class R>//, class ObjVector = typename MOEOT::ObjectiveVector >
//class moeoVectorVsSolutionBinaryMetric : public moeoBinaryMetric < const std::vector < ObjVector > &, const ObjVector &, R >
class moeoPopVsSolutionBinaryMetric : public moeoBinaryMetric < const eoPop < MOEOT > &, const MOEOT &, R >
template < class ObjectiveVector, class R >
class moeoVectorVsSolutionBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const ObjectiveVector &, R >
{};
/**
* Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of Pareto fitnesses)
* Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of objective vectors)
*/
template < class MOEOT, class R >//, class ObjVector = typename MOEOT::ObjectiveVector >
//class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjVector > &, const std::vector < ObjVector > &, R >
class moeoPopVsPopBinaryMetric : public moeoBinaryMetric < const eoPop < MOEOT > &, const eoPop < MOEOT > &, R >
template < class ObjectiveVector, class R >
class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R >
{};