diff --git a/mo/src/continuator/moAverageFitnessNeighborStat.h b/mo/src/continuator/moAverageFitnessNeighborStat.h index 4c268d6d3..7d12abc0a 100644 --- a/mo/src/continuator/moAverageFitnessNeighborStat.h +++ b/mo/src/continuator/moAverageFitnessNeighborStat.h @@ -55,7 +55,7 @@ public : * @param _nhStat a neighborhoodStat */ moAverageFitnessNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0.0, "average"), nhStat(_nhStat) {} + moStat(0.0, "mean"), nhStat(_nhStat) {} /** * Set the average of fitness in the neighborhood diff --git a/mo/src/continuator/moMaxNeighborStat.h b/mo/src/continuator/moMaxNeighborStat.h index d0dbd8136..f0b165d72 100644 --- a/mo/src/continuator/moMaxNeighborStat.h +++ b/mo/src/continuator/moMaxNeighborStat.h @@ -56,7 +56,7 @@ public : * @param _nhStat a neighborhoodStat */ moMaxNeighborStat(moNeighborhoodStat & _nhStat): - moStat(Fitness(), "min"), nhStat(_nhStat) {} + moStat(Fitness(), "max"), nhStat(_nhStat) {} /** * Set the max fitness in the neighborhood diff --git a/mo/src/continuator/moMedianNeighborStat.h b/mo/src/continuator/moMedianNeighborStat.h new file mode 100644 index 000000000..4c3cfb8f2 --- /dev/null +++ b/mo/src/continuator/moMedianNeighborStat.h @@ -0,0 +1,90 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef moMedianNeighborStat_h +#define moMedianNeighborStat_h + +#include +#include +#include + +/** + * From moNeighborhoodStat, + * to compute the meadian fitness in the neighborhood + */ +template< class Neighbor > +class moMedianNeighborStat : public moStat +{ +public : + typedef typename Neighbor::EOT EOT ; + typedef typename EOT::Fitness Fitness ; + + using moStat< EOT, Fitness >::value; + + /** + * Constructor + * @param _nhStat a neighborhoodStat + */ + moMedianNeighborStat(moNeighborhoodStat & _nhStat): + moStat(Fitness(), "median"), nhStat(_nhStat) {} + + /** + * Set the median fitness in the neighborhood + * @param _sol the first solution + */ + virtual void init(EOT & _sol) { + value() = nhStat.getMedian(); + } + + /** + * Set the median fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getMedian(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moMedianNeighborStat"; + } + +private: + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; +}; + +#endif diff --git a/mo/src/continuator/moNbInfNeighborStat.h b/mo/src/continuator/moNbInfNeighborStat.h index 1fa6783bb..e3bc27bb7 100644 --- a/mo/src/continuator/moNbInfNeighborStat.h +++ b/mo/src/continuator/moNbInfNeighborStat.h @@ -57,7 +57,7 @@ public : * @param _nhStat a neighborhoodStat */ moNbInfNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "nb inf"), nhStat(_nhStat) {} + moStat(0, "inf"), nhStat(_nhStat) {} /** * Set the number of solutions in the neighborhood with (strictly) lower fitness than the current solution diff --git a/mo/src/continuator/moNbSupNeighborStat.h b/mo/src/continuator/moNbSupNeighborStat.h index 027d8f1e8..8febf94f8 100644 --- a/mo/src/continuator/moNbSupNeighborStat.h +++ b/mo/src/continuator/moNbSupNeighborStat.h @@ -57,7 +57,7 @@ public : * @param _nhStat a neighborhoodStat */ moNbSupNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "nb sup"), nhStat(_nhStat) {} + moStat(0, "sup"), nhStat(_nhStat) {} /** * Set the number of solutions in the neighborhood with better fitness than the current solution diff --git a/mo/src/continuator/moNeighborhoodStat.h b/mo/src/continuator/moNeighborhoodStat.h index 6dfe4fde9..3ce7d3757 100644 --- a/mo/src/continuator/moNeighborhoodStat.h +++ b/mo/src/continuator/moNeighborhoodStat.h @@ -41,6 +41,8 @@ #include #include #include +#include +#include // std::sort /** * All possible statitic on the neighborhood fitness @@ -102,8 +104,11 @@ public : Neighbor lowest ; if (neighborhood.hasNeighbor(_solution)) { - //init the first neighbor - neighborhood.init(_solution, current); + // to save the fitness values of the neighbors + std::vector neighborFitness; + + //init the first neighbor + neighborhood.init(_solution, current); //eval the _solution moved with the neighbor and stock the result in the neighbor eval(_solution, current); @@ -112,7 +117,7 @@ public : value() = true; mean = current.fitness(); - sd = mean * mean; + neighborFitness.push_back( (double) current.fitness() ); nb = 1; nbInf = 0; nbEqual = 0; @@ -137,7 +142,7 @@ public : eval(_solution, current); mean += current.fitness(); - sd += current.fitness() * current.fitness(); + neighborFitness.push_back( (double) current.fitness() ); nb++; if (solNeighborComparator.equals(_solution, current)) @@ -159,10 +164,24 @@ public : min = lowest.fitness(); mean /= nb; - if (nb > 1) - sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); - else + + if (nb > 1) { + sd = 0; + for(int i = 0; i < nb; i++) + sd += (neighborFitness[i] - mean) * (neighborFitness[i] - mean) ; + sd = sqrt( sd / (nb - 1.0) ); // becareful: could be infinite when large values + //sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); // becareful: could be negative due to approximation of large values + + std::sort(neighborFitness.begin(), neighborFitness.end()); // to compute the quartiles + q1 = neighborFitness[nb / 4]; + q2 = neighborFitness[nb / 2]; + q3 = neighborFitness[3 * nb / 4]; + } else { sd = 0.0; + q1 = max; + q2 = q1; + q3 = q1; + } } else { //if _solution hasn't neighbor, @@ -198,6 +217,27 @@ public : return sd; } + /** + * @return the first quartile of fitness in the neighborhood + */ + Fitness getQ1() { + return q1; + } + + /** + * @return the third quartile of fitness in the neighborhood + */ + Fitness getQ3() { + return q3; + } + + /** + * @return the median fitness value of the neighborhood + */ + Fitness getMedian() { + return q2; + } + /** * @return the size of the neighborhood */ @@ -251,9 +291,13 @@ protected: // the stastics of the fitness Fitness max, min; - //mean and standard deviation + + // mean and standard deviation double mean, sd ; + // quartiles + Fitness q1, q2, q3; + // number of neighbors in the neighborhood; unsigned int nb; diff --git a/mo/src/continuator/moNeutralDegreeNeighborStat.h b/mo/src/continuator/moNeutralDegreeNeighborStat.h index 88ab663b4..d46e99475 100644 --- a/mo/src/continuator/moNeutralDegreeNeighborStat.h +++ b/mo/src/continuator/moNeutralDegreeNeighborStat.h @@ -57,7 +57,7 @@ public : * @param _nhStat a neighborhoodStat */ moNeutralDegreeNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "neutral degree"), nhStat(_nhStat) {} + moStat(0, "nd"), nhStat(_nhStat) {} /** * Set the neutral degree of the solution which is the number of solutions in the neighborhood with equals fitness diff --git a/mo/src/continuator/moQ1NeighborStat.h b/mo/src/continuator/moQ1NeighborStat.h new file mode 100644 index 000000000..4d74be68d --- /dev/null +++ b/mo/src/continuator/moQ1NeighborStat.h @@ -0,0 +1,90 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef moQ1NeighborStat_h +#define moQ1NeighborStat_h + +#include +#include +#include + +/** + * From moNeighborhoodStat, + * to compute the first quartile of fitness in the neighborhood + */ +template< class Neighbor > +class moQ1NeighborStat : public moStat +{ +public : + typedef typename Neighbor::EOT EOT ; + typedef typename EOT::Fitness Fitness ; + + using moStat< EOT, Fitness >::value; + + /** + * Constructor + * @param _nhStat a neighborhoodStat + */ + moQ1NeighborStat(moNeighborhoodStat & _nhStat): + moStat(Fitness(), "q1"), nhStat(_nhStat) {} + + /** + * Set the first quartile of fitness in the neighborhood + * @param _sol the first solution + */ + virtual void init(EOT & _sol) { + value() = nhStat.getQ1(); + } + + /** + * Set the first quartile of fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getQ1(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moQ1NeighborStat"; + } + +private: + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; +}; + +#endif diff --git a/mo/src/continuator/moQ3NeighborStat.h b/mo/src/continuator/moQ3NeighborStat.h new file mode 100644 index 000000000..50426e65f --- /dev/null +++ b/mo/src/continuator/moQ3NeighborStat.h @@ -0,0 +1,90 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef moQ3NeighborStat_h +#define moQ3NeighborStat_h + +#include +#include +#include + +/** + * From moNeighborhoodStat, + * to compute the third quartile of fitness in the neighborhood + */ +template< class Neighbor > +class moQ3NeighborStat : public moStat +{ +public : + typedef typename Neighbor::EOT EOT ; + typedef typename EOT::Fitness Fitness ; + + using moStat< EOT, Fitness >::value; + + /** + * Constructor + * @param _nhStat a neighborhoodStat + */ + moQ3NeighborStat(moNeighborhoodStat & _nhStat): + moStat(Fitness(), "q3"), nhStat(_nhStat) {} + + /** + * Set the third quartile of fitness in the neighborhood + * @param _sol the third solution + */ + virtual void init(EOT & _sol) { + value() = nhStat.getQ3(); + } + + /** + * Set the third quartile of fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getQ3(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moQ3NeighborStat"; + } + +private: + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; +}; + +#endif diff --git a/mo/src/continuator/moQuartilesNeighborStat.h b/mo/src/continuator/moQuartilesNeighborStat.h new file mode 100644 index 000000000..69f6af68a --- /dev/null +++ b/mo/src/continuator/moQuartilesNeighborStat.h @@ -0,0 +1,91 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + ParadisEO WebSite : http://paradiseo.gforge.inria.fr + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef moQuartilesNeighborStat_h +#define moQuartilesNeighborStat_h + +#include +#include + +/** + * From moNeighborhoodStat, + * to compute the first and the third quartile of fitness in the neighborhood + */ +template< class Neighbor > +class moQuartilesNeighborStat : public moStat > +{ +public : + typedef typename Neighbor::EOT EOT ; + typedef typename EOT::Fitness Fitness ; + + using moStat< EOT, std::pair >::value; + + /** + * Constructor + * @param _nhStat a neighborhoodStat + */ + moQuartilesNeighborStat(moNeighborhoodStat & _nhStat): + moStat >(std::make_pair(0.0,0.0), "first and third quartile"), nhStat(_nhStat) {} + + /** + * Set the first and the third quartile of fitness in the neighborhood + * @param _sol the first solution + */ + virtual void init(EOT & _sol) { + value().first = nhStat.getQ1(); + value().second = nhStat.getQ3(); + } + + /** + * Set the first and the third quartile fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value().first = nhStat.getQ1(); + value().second = nhStat.getQ3(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moQuartilesNeighborStat"; + } + +private: + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; +}; + +#endif diff --git a/mo/src/continuator/moSecondMomentNeighborStat.h b/mo/src/continuator/moSecondMomentNeighborStat.h index c5b1009f7..7c3a08fff 100644 --- a/mo/src/continuator/moSecondMomentNeighborStat.h +++ b/mo/src/continuator/moSecondMomentNeighborStat.h @@ -55,7 +55,7 @@ public : * @param _nhStat a neighborhoodStat */ moSecondMomentNeighborStat(moNeighborhoodStat & _nhStat): - moStat >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat) {} + moStat >(std::make_pair(0.0,0.0), "mean sd"), nhStat(_nhStat) {} /** * Set the average and the standard deviation of fitness in the neighborhood diff --git a/mo/src/continuator/moSizeNeighborStat.h b/mo/src/continuator/moSizeNeighborStat.h index 6e7ae60f1..1a5b5b123 100644 --- a/mo/src/continuator/moSizeNeighborStat.h +++ b/mo/src/continuator/moSizeNeighborStat.h @@ -56,7 +56,7 @@ public : * @param _nhStat a neighborhoodStat */ moSizeNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "size"), nhStat(_nhStat) {} + moStat(0, "nghsize"), nhStat(_nhStat) {} /** * Set the number of solutions in the neighborhood diff --git a/mo/src/continuator/moSolutionStat.h b/mo/src/continuator/moSolutionStat.h index 17a997e25..93c4f57f5 100644 --- a/mo/src/continuator/moSolutionStat.h +++ b/mo/src/continuator/moSolutionStat.h @@ -53,7 +53,7 @@ public : * @param _description a description of the parameter */ moSolutionStat(std::string _description = "solution"): - moStat(EOT(), _description) { } + moStat(EOT(), "fitness solution") { } /** * Initialization the solution by copy diff --git a/mo/src/continuator/moStatFromStat.h b/mo/src/continuator/moStatFromStat.h index e8da634ad..962106eb0 100644 --- a/mo/src/continuator/moStatFromStat.h +++ b/mo/src/continuator/moStatFromStat.h @@ -50,7 +50,7 @@ public : * Constructor * @param _stat a stat */ - moStatFromStat(moStat & _stat): moStat(0, _stat.description()), stat(_stat) { + moStatFromStat(moStat & _stat): moStat(0, _stat.longName()), stat(_stat) { } /** diff --git a/mo/src/continuator/moStdFitnessNeighborStat.h b/mo/src/continuator/moStdFitnessNeighborStat.h index b9a547954..649308f74 100644 --- a/mo/src/continuator/moStdFitnessNeighborStat.h +++ b/mo/src/continuator/moStdFitnessNeighborStat.h @@ -55,7 +55,7 @@ public : * @param _nhStat a neighborhoodStat */ moStdFitnessNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0.0, "stdev"), nhStat(_nhStat) {} + moStat(0.0, "sd"), nhStat(_nhStat) {} /** * Set the average and the standard deviation of fitness in the neighborhood diff --git a/mo/src/continuator/moVectorMonitor.h b/mo/src/continuator/moVectorMonitor.h index d6870bb80..cd2b6c4e0 100644 --- a/mo/src/continuator/moVectorMonitor.h +++ b/mo/src/continuator/moVectorMonitor.h @@ -174,6 +174,24 @@ public: return os.str(); } + /** + * Returns the long name of the statistic (which is a eoParam) + * + * @return longName of the statistic + */ + const std::string& longName() const { + if (doubleParam != NULL) + return doubleParam->longName(); + else + if (intParam != NULL) + return intParam->longName(); + else + if (intLongParam != NULL) + return intLongParam->longName(); + else + return eotParam->longName(); + } + /** * clear the vector */ diff --git a/mo/src/sampling/moAdaptiveWalkSampling.h b/mo/src/sampling/moAdaptiveWalkSampling.h index 0dae8633c..04dafe876 100644 --- a/mo/src/sampling/moAdaptiveWalkSampling.h +++ b/mo/src/sampling/moAdaptiveWalkSampling.h @@ -95,8 +95,14 @@ public: // to count the number of step in the HC checkpoint.add(lengthStat); + // set the long name of this statistic which is the length of the walk + copyStat.setLongName("length"); + // to count the number of evaluations checkpoint.add(nEvalStat); + + // set the long name of this statistic which is the number of neighbor evaluation + copyEvalStat.setLongName("ngheval"); // add the solution into statistics this->add(copyEvalStat); diff --git a/mo/src/sampling/moHillClimberSampling.h b/mo/src/sampling/moHillClimberSampling.h index 7ca2fb538..d6bc45a28 100644 --- a/mo/src/sampling/moHillClimberSampling.h +++ b/mo/src/sampling/moHillClimberSampling.h @@ -84,6 +84,9 @@ public: // to count the number of step in the HC checkpoint.add(lengthStat); + // set the long name of this statistic which is the length of the walk + copyStat.setLongName("length"); + // add the solution into statistics this->add(solStat); } diff --git a/mo/src/sampling/moNeutralWalkSampling.h b/mo/src/sampling/moNeutralWalkSampling.h index 708f0ac14..0db5f6c06 100644 --- a/mo/src/sampling/moNeutralWalkSampling.h +++ b/mo/src/sampling/moNeutralWalkSampling.h @@ -47,6 +47,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -63,9 +66,12 @@ * Informations collected: * - the current solution of the walk * - the distance from the starting solution - * - the minimal fitness in the neighborhood * - the average fitness * - the standard deviation of the fitness + * - the minimal fitness in the neighborhood + * - the first quartile of fitness in the neighborhood + * - the median fitness in the neighborhood + * - the third quartile of fitness in the neighborhood * - the maximal fitness * - the size of the neighborhood * - the number of neighbors with lower fitness @@ -99,20 +105,26 @@ public: init(_initSol), distStat(_distance, _initSol), neighborhoodStat(_neighborhood, _eval), - minStat(neighborhoodStat), averageStat(neighborhoodStat), stdStat(neighborhoodStat), + minStat(neighborhoodStat), maxStat(neighborhoodStat), nbSupStat(neighborhoodStat), nbInfStat(neighborhoodStat), sizeStat(neighborhoodStat), - ndStat(neighborhoodStat) + ndStat(neighborhoodStat), + q1Stat(neighborhoodStat), + medianStat(neighborhoodStat), + q3Stat(neighborhoodStat) { this->add(neighborhoodStat, false); this->add(distStat); - this->add(minStat); this->add(averageStat); this->add(stdStat); + this->add(minStat); + this->add(q1Stat); + this->add(medianStat); + this->add(q3Stat); this->add(maxStat); this->add(sizeStat); this->add(nbInfStat); @@ -145,13 +157,19 @@ public: nbSupStat(neighborhoodStat), nbInfStat(neighborhoodStat), sizeStat(neighborhoodStat), - ndStat(neighborhoodStat) + ndStat(neighborhoodStat), + q1Stat(neighborhoodStat), + medianStat(neighborhoodStat), + q3Stat(neighborhoodStat) { this->add(neighborhoodStat, false); // this->add(distStat); - this->add(minStat); this->add(averageStat); this->add(stdStat); + this->add(minStat); + this->add(q1Stat); + this->add(medianStat); + this->add(q3Stat); this->add(maxStat); this->add(sizeStat); this->add(nbInfStat); @@ -182,6 +200,9 @@ protected: moNbInfNeighborStat< Neighbor > nbInfStat; moSizeNeighborStat< Neighbor > sizeStat; moNeutralDegreeNeighborStat< Neighbor > ndStat; + moQ1NeighborStat< Neighbor > q1Stat; + moMedianNeighborStat< Neighbor > medianStat; + moQ3NeighborStat< Neighbor > q3Stat; }; diff --git a/mo/src/sampling/moSampling.h b/mo/src/sampling/moSampling.h index b118b9d48..c2db1fa73 100644 --- a/mo/src/sampling/moSampling.h +++ b/mo/src/sampling/moSampling.h @@ -140,19 +140,20 @@ public: /** * to export the vectors of values into one file + * * @param _filename file name * @param _delim delimiter between statistics * @param _openFile to specify if it writes at the following of the file + * @param _header if true, print the headers which are the name of the statistic */ - void fileExport(std::string _filename, std::string _delim = " ", bool _openFile=false) { + void fileExport(std::string _filename, std::string _delim = " ", bool _openFile = false, bool _header = false) { // create file std::ofstream os; if(! _openFile) os.open(_filename.c_str()); - else - os.open(_filename.c_str(),std::ios::app); + os.open(_filename.c_str(), std::ios::app); if (!os) { std::string str = "moSampling: Could not open " + _filename; @@ -164,6 +165,16 @@ public: for (unsigned int j = 0; j < monitorVec.size(); j++) monitorVec[j]->precision(precisionOutput); + if (!_openFile && _header) { + os << monitorVec[0]->longName(); + + for (unsigned int j = 1; j < monitorVec.size(); j++) { + os << _delim.c_str() << monitorVec[j]->longName(); + } + + os << std::endl ; + } + // all vector have the same size unsigned vecSize = monitorVec[0]->size(); diff --git a/mo/test/t-moAdaptiveWalkSampling.cpp b/mo/test/t-moAdaptiveWalkSampling.cpp index 586624246..3bc232096 100755 --- a/mo/test/t-moAdaptiveWalkSampling.cpp +++ b/mo/test/t-moAdaptiveWalkSampling.cpp @@ -57,7 +57,7 @@ int main() { std::vector res; std::vector res2; - res = test.getValues(1); + res = test.getValues(2); res2= test.getSolutions(0); for (unsigned int i=0; i #include #include +#include +#include +#include +#include #include "moTestClass.h" @@ -85,6 +89,9 @@ int main() { assert(test.getMean()==6.6); double sd=test.getSD(); assert(sd>0.966 && sd<0.967); + assert(test.getMedian()==6); + assert(test.getQ1()==6); + assert(test.getQ3()==8); assert(test.getSize()==10); assert(test.getNbSup()==7); assert(test.getNbInf()==3); @@ -167,6 +174,40 @@ int main() { assert(test10.className()=="moStdFitnessNeighborStat"); std::cout << "[t-moStdFitnessNeighborStat] => OK" << std::endl; + //test of moQuartilesNeighborStat.h + std::cout << "[t-moQuartilesNeighborStat] => START" << std::endl; + moQuartilesNeighborStat test11(test); + test11.init(sol); + test11(sol); + assert(test11.value().first==6); + assert(test11.value().second==8); + assert(test11.className()=="moQuartilesNeighborStat"); + std::cout << "[t-moQuartilesNeighborStat] => OK" << std::endl; + + //test of moMedianNeighborStat.h + std::cout << "[t-moMedianNeighborStat] => START" << std::endl; + moMedianNeighborStat test12(test); + test12(sol); + assert(test12.value()==6); + assert(test12.className()=="moMedianNeighborStat"); + std::cout << "[t-moMedianNeighborStat] => OK" << std::endl; + + //test of moQ1NeighborStat.h + std::cout << "[t-moQ1NeighborStat] => START" << std::endl; + moQ1NeighborStat test13(test); + test13(sol); + assert(test13.value()==6); + assert(test13.className()=="moQ1NeighborStat"); + std::cout << "[t-moQ1NeighborStat] => OK" << std::endl; + + //test of moQ3NeighborStat.h + std::cout << "[t-moQ3NeighborStat] => START" << std::endl; + moQ3NeighborStat test14(test); + test14(sol); + assert(test14.value()==8); + assert(test14.className()=="moQ3NeighborStat"); + std::cout << "[t-moQ3NeighborStat] => OK" << std::endl; + return EXIT_SUCCESS; }