+ boxplot.py: script to generate graphic with boxplot to illustrate distances between theorical and visual means for each population value
This commit is contained in:
parent
b70a60bc59
commit
ba6770df43
3 changed files with 123 additions and 78 deletions
|
|
@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/application/eda_sa)
|
|||
|
||||
SET(SOURCES
|
||||
t-doEstimatorNormalMulti
|
||||
t-mean-distance
|
||||
)
|
||||
|
||||
FOREACH(current ${SOURCES})
|
||||
|
|
|
|||
19
test/boxplot.py
Executable file
19
test/boxplot.py
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from pylab import *
|
||||
|
||||
FILE_LOCATIONS = 'means_distances_results/files_description.txt'
|
||||
|
||||
data = []
|
||||
|
||||
locations = [ line.split()[0] for line in open( FILE_LOCATIONS ) ]
|
||||
|
||||
for cur_file in locations:
|
||||
data.append( [ float(line.split()[7]) for line in open( cur_file ).readlines() ] )
|
||||
|
||||
print locations
|
||||
#print data
|
||||
|
||||
boxplot( data )
|
||||
|
||||
show()
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
|
|
@ -27,9 +30,10 @@ int main(int ac, char** av)
|
|||
|
||||
std::string section("Algorithm parameters");
|
||||
|
||||
unsigned int r_max = parser.createParam((unsigned int)100, "run-number", "Number of run", 'r', section).value(); // r
|
||||
unsigned int p_min = parser.createParam((unsigned int)10, "population-min", "Population min", 'p', section).value(); // p
|
||||
unsigned int p_max = parser.createParam((unsigned int)10000, "population-max", "Population max", 'P', section).value(); // P
|
||||
unsigned int p_step = parser.createParam((unsigned int)10, "population-step", "Population step", 't', section).value(); // t
|
||||
unsigned int p_max = parser.createParam((unsigned int)1000, "population-max", "Population max", 'P', section).value(); // P
|
||||
unsigned int p_step = parser.createParam((unsigned int)50, "population-step", "Population step", 't', section).value(); // t
|
||||
unsigned int s_size = parser.createParam((unsigned int)2, "dimension-size", "Dimension size", 'd', section).value(); // d
|
||||
|
||||
AtomType mean_value = parser.createParam((AtomType)0, "mean", "Mean value", 'm', section).value(); // m
|
||||
|
|
@ -37,6 +41,9 @@ int main(int ac, char** av)
|
|||
AtomType covar2_value = parser.createParam((AtomType)0.5, "covar2", "Covar value 2", '2', section).value(); // 2
|
||||
AtomType covar3_value = parser.createParam((AtomType)1.0, "covar3", "Covar value 3", '3', section).value(); // 3
|
||||
|
||||
std::string results_directory = parser.createParam((std::string)"means_distances_results", "results-directory", "Results directory", 'R', section).value(); // R
|
||||
std::string files_description = parser.createParam((std::string)"files_description.txt", "files-description", "Files description", 'F', section).value(); // F
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
|
|
@ -48,128 +55,146 @@ int main(int ac, char** av)
|
|||
|
||||
//-----------------------------------------------------
|
||||
|
||||
|
||||
assert(r_max >= 1);
|
||||
assert(s_size >= 2);
|
||||
|
||||
eo::log << eo::debug << "p_size s_size mean(0) mean(1) new-mean(0) new-mean(1) distance" << std::endl;
|
||||
eo::log << eo::quiet;
|
||||
|
||||
eo::log << eo::logging;
|
||||
::mkdir( results_directory.c_str(), 0755 );
|
||||
|
||||
for ( unsigned int p_size = p_min; p_size <= p_max; p_size *= p_step )
|
||||
for ( unsigned int p_size = p_min; p_size <= p_max; p_size += p_step )
|
||||
{
|
||||
|
||||
assert(p_size >= p_min);
|
||||
|
||||
eoState state;
|
||||
std::ostringstream desc_file;
|
||||
desc_file << results_directory << "/" << files_description;
|
||||
|
||||
std::ostringstream cur_file;
|
||||
cur_file << results_directory << "/pop_" << p_size << ".txt";
|
||||
|
||||
//-----------------------------------------------------
|
||||
// (1) Population init and sampler
|
||||
//-----------------------------------------------------
|
||||
eo::log << eo::file( desc_file.str() ) << cur_file.str().c_str() << std::endl;
|
||||
|
||||
eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
|
||||
state.storeFunctor(gen);
|
||||
eo::log << eo::file( cur_file.str() );
|
||||
|
||||
eoInitFixedLength< EOT >* init = new eoInitFixedLength< EOT >( s_size, *gen );
|
||||
state.storeFunctor(init);
|
||||
eo::log << eo::logging << "run_number p_size s_size mean(0) mean(1) new-mean(0) new-mean(1) distance" << std::endl;
|
||||
|
||||
// create an empty pop and let the state handle the memory
|
||||
// fill population thanks to eoInit instance
|
||||
eoPop< EOT >& pop = state.takeOwnership( eoPop< EOT >( p_size, *init ) );
|
||||
eo::log << eo::quiet;
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (2) distribution initial parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ublas::vector< AtomType > mean( s_size, mean_value );
|
||||
ublas::symmetric_matrix< AtomType, ublas::lower > varcovar( s_size, s_size );
|
||||
|
||||
varcovar( 0, 0 ) = covar1_value;
|
||||
varcovar( 0, 1 ) = covar2_value;
|
||||
varcovar( 1, 1 ) = covar3_value;
|
||||
|
||||
Distrib distrib( mean, varcovar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare bounder class to set bounds of sampling.
|
||||
// This is used by doSampler.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
doBounder< EOT >* bounder = new doBounderRng< EOT >(EOT(pop[0].size(), -5),
|
||||
EOT(pop[0].size(), 5),
|
||||
*gen);
|
||||
state.storeFunctor(bounder);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare sampler class with a specific distribution
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
doSampler< Distrib >* sampler = new doSamplerNormalMulti< EOT >( *bounder );
|
||||
state.storeFunctor(sampler);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (4) sampling phase
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
pop.clear();
|
||||
|
||||
for (unsigned int i = 0; i < p_size; ++i)
|
||||
for ( unsigned int r = 1; r <= r_max; ++r)
|
||||
{
|
||||
EOT candidate_solution = (*sampler)( distrib );
|
||||
pop.push_back( candidate_solution );
|
||||
|
||||
eoState state;
|
||||
|
||||
|
||||
//-----------------------------------------------------
|
||||
// (1) Population init and sampler
|
||||
//-----------------------------------------------------
|
||||
|
||||
eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
|
||||
state.storeFunctor(gen);
|
||||
|
||||
eoInitFixedLength< EOT >* init = new eoInitFixedLength< EOT >( s_size, *gen );
|
||||
state.storeFunctor(init);
|
||||
|
||||
// create an empty pop and let the state handle the memory
|
||||
// fill population thanks to eoInit instance
|
||||
eoPop< EOT >& pop = state.takeOwnership( eoPop< EOT >( p_size, *init ) );
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (2) distribution initial parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ublas::vector< AtomType > mean( s_size, mean_value );
|
||||
ublas::symmetric_matrix< AtomType, ublas::lower > varcovar( s_size, s_size );
|
||||
|
||||
varcovar( 0, 0 ) = covar1_value;
|
||||
varcovar( 0, 1 ) = covar2_value;
|
||||
varcovar( 1, 1 ) = covar3_value;
|
||||
|
||||
Distrib distrib( mean, varcovar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare bounder class to set bounds of sampling.
|
||||
// This is used by doSampler.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
doBounder< EOT >* bounder = new doBounderRng< EOT >(EOT(pop[0].size(), -5),
|
||||
EOT(pop[0].size(), 5),
|
||||
*gen);
|
||||
state.storeFunctor(bounder);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare sampler class with a specific distribution
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
doSampler< Distrib >* sampler = new doSamplerNormalMulti< EOT >( *bounder );
|
||||
state.storeFunctor(sampler);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (4) sampling phase
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
pop.clear();
|
||||
|
||||
for (unsigned int i = 0; i < p_size; ++i)
|
||||
{
|
||||
EOT candidate_solution = (*sampler)( distrib );
|
||||
pop.push_back( candidate_solution );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (6) estimation phase
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
doEstimator< Distrib >* estimator = new doEstimatorNormalMulti< EOT >();
|
||||
state.storeFunctor(estimator);
|
||||
|
||||
distrib = (*estimator)( pop );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (8) euclidianne distance estimation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ublas::vector< AtomType > new_mean = distrib.mean();
|
||||
ublas::symmetric_matrix< AtomType, ublas::lower > new_varcovar = distrib.varcovar();
|
||||
|
||||
AtomType distance = 0;
|
||||
|
||||
for ( unsigned int d = 0; d < s_size; ++d )
|
||||
{
|
||||
distance += pow( mean[ d ] - new_mean[ d ], 2 );
|
||||
}
|
||||
|
||||
distance = sqrt( distance );
|
||||
|
||||
eo::log << r << " " << p_size << " " << s_size << " "
|
||||
<< mean(0) << " " << mean(1) << " "
|
||||
<< new_mean(0) << " " << new_mean(1) << " "
|
||||
<< distance << std::endl
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (6) estimation phase
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
doEstimator< Distrib >* estimator = new doEstimatorNormalMulti< EOT >();
|
||||
state.storeFunctor(estimator);
|
||||
|
||||
distrib = (*estimator)( pop );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (8) euclidianne distance estimation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ublas::vector< AtomType > new_mean = distrib.mean();
|
||||
ublas::symmetric_matrix< AtomType, ublas::lower > new_varcovar = distrib.varcovar();
|
||||
|
||||
AtomType distance = 0;
|
||||
|
||||
for ( unsigned int d = 0; d < s_size; ++d )
|
||||
{
|
||||
distance += pow( mean[ d ] - new_mean[ d ], 2 );
|
||||
}
|
||||
|
||||
distance = sqrt( distance );
|
||||
|
||||
eo::log << p_size << " " << s_size << " "
|
||||
<< mean(0) << " " << mean(1) << " "
|
||||
<< new_mean(0) << " " << new_mean(1) << " "
|
||||
<< distance << std::endl
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue