Ajout des statistics, j'espère avoir fini ;)

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1804 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
verel 2010-05-07 15:42:18 +00:00
commit fb4a9f1df7
6 changed files with 268 additions and 0 deletions

View file

@ -158,6 +158,7 @@
#include <sampling/moMHRndFitnessCloudSampling.h>
#include <sampling/moMHBestFitnessCloudSampling.h>
#include <sampling/moNeutralWalkSampling.h>
#include <sampling/moStatistics.h>
#include <problems/bitString/moBitNeighbor.h>
#include <problems/eval/moOneMaxIncrEval.h>

View file

@ -0,0 +1,215 @@
/*
<moStatistics.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 moStatistics_h
#define moStatistics_h
#include <vector>
#include <utils/eoDistance.h>
/**
* 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
{
public:
/**
* 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 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();
min = data[0];
max = data[0];
avg = 0.0;
std = 0.0;
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;
}
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 vector<EOT> & data, eoDistance<EOT> & distance,
vector< 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);
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 vector<double> & data, unsigned int nbS,
vector<double> & rho, 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];
rho.resize(nbS+1);
phi.resize(nbS+1);
rho[0] = 1.0;
phi[0] = 1.0; // ?
unsigned s, k;
for(s = 0; s <= nbS; s++) {
cov[s] = 0;
m[s] = 0;
sig[s] = 0;
}
double m0, s0;
unsigned j;
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 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];
}
}
};
#endif

View file

@ -193,6 +193,7 @@ void main_function(int argc, char **argv)
std::cout << "Last values:" << std::endl;
std::cout << "Length " << lengthValues[lengthValues.size() - 1] << std::endl;
}
// A main that catches the exceptions

View file

@ -40,6 +40,10 @@ using namespace std;
// the sampling class
#include <sampling/moAutocorrelationSampling.h>
//-----------------------------------------------------------------------------
// the statistics class
#include <sampling/moStatistics.h>
// Declaration of types
//-----------------------------------------------------------------------------
// Indi is the typedef of the solution type like in paradisEO-eo
@ -195,6 +199,16 @@ void main_function(int argc, char **argv)
std::cout << "Last values:" << std::endl;
std::cout << "Fitness " << fitnessValues[fitnessValues.size() - 1] << std::endl;
// more basic statistics on the distribution:
moStatistics statistics;
vector<double> rho, phi;
statistics.autocorrelation(fitnessValues, 10, rho, phi);
for(unsigned s = 0; s < rho.size(); s++)
std::cout << s << " " << "rho=" << rho[s] << ", phi=" << phi[s] << std::endl;
}
// A main that catches the exceptions

View file

@ -34,6 +34,10 @@ using namespace std;
// the sampling class
#include <sampling/moDensityOfStatesSampling.h>
//-----------------------------------------------------------------------------
// the statistics class
#include <sampling/moStatistics.h>
// Declaration of types
//-----------------------------------------------------------------------------
// Indi is the typedef of the solution type like in paradisEO-eo
@ -165,6 +169,14 @@ void main_function(int argc, char **argv)
std::cout << "Last values:" << std::endl;
std::cout << "Fitness " << fitnessValues[fitnessValues.size() - 1] << std::endl;
// more basic statistics on the distribution:
double min, max, avg, std;
moStatistics statistics;
statistics.basic(fitnessValues, min, max, avg, std);
std::cout << "min=" << min << ", max=" << max << ", average=" << avg << ", std dev=" << std << std::endl;
}
// A main that catches the exceptions

View file

@ -40,6 +40,10 @@ using namespace std;
#include <utils/eoDistance.h>
#include <sampling/moNeutralWalkSampling.h>
//-----------------------------------------------------------------------------
// the statistics class
#include <sampling/moStatistics.h>
// Declaration of types
//-----------------------------------------------------------------------------
// Indi is the typedef of the solution type like in paradisEO-eo
@ -209,6 +213,27 @@ void main_function(int argc, char **argv)
// export only the solution into file
sampling.fileExport(0, str_out + "_sol");
// more basic statistics on the distribution:
moStatistics statistics;
vector< vector<double> > dist;
vector<double> v;
statistics.distances(solutions, distance, dist);
for(unsigned i = 0; i < dist.size(); i++) {
for(unsigned j = 0; j < dist.size(); j++) {
std::cout << dist[i][j] << " " ;
if (j < i)
v.push_back(dist[i][j]);
}
std::cout << std::endl;
}
double min, max, avg, std;
statistics.basic(v, min, max, avg, std);
std::cout << "min=" << min << ", max=" << max << ", average=" << avg << ", std dev=" << std << std::endl;
}
// A main that catches the exceptions