move edo stuff, that was in the wriong place after the merge, in the edo directory
This commit is contained in:
parent
d4765851d5
commit
cbb1771dd6
77 changed files with 0 additions and 0 deletions
50
edo/test/CMakeLists.txt
Normal file
50
edo/test/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
###############################################################################
|
||||
##
|
||||
## CMakeLists file for unit test
|
||||
##
|
||||
###############################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets and link the librairies
|
||||
######################################################################################
|
||||
|
||||
FIND_PACKAGE(Boost 1.33.0)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
||||
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/application/common)
|
||||
|
||||
SET(SOURCES
|
||||
t-edoEstimatorNormalMulti
|
||||
t-mean-distance
|
||||
t-bounderno
|
||||
t-uniform
|
||||
t-continue
|
||||
)
|
||||
|
||||
FOREACH(current ${SOURCES})
|
||||
ADD_EXECUTABLE(${current} ${current}.cpp)
|
||||
ADD_TEST(${current} ${current})
|
||||
TARGET_LINK_LIBRARIES(${current} edo edoutils ${EO_LIBRARIES} ${MO_LIBRARIES} ${Boost_LIBRARIES})
|
||||
INSTALL(TARGETS ${current} RUNTIME DESTINATION share/edo/test COMPONENT test)
|
||||
ENDFOREACH()
|
||||
|
||||
######################################################################################
|
||||
19
edo/test/boxplot.py
Executable file
19
edo/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()
|
||||
40
edo/test/t-bounderno.cpp
Normal file
40
edo/test/t-bounderno.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||
ANSI-C++ evolutionary computation library which helps you to write your
|
||||
own estimation of distribution algorithms.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2010 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <edo>
|
||||
|
||||
#include "Rosenbrock.h"
|
||||
|
||||
typedef eoReal< eoMinimizingFitness > EOT;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
edoBounderNo< EOT > bounder;
|
||||
|
||||
return 0;
|
||||
}
|
||||
44
edo/test/t-continue.cpp
Normal file
44
edo/test/t-continue.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||
ANSI-C++ evolutionary computation library which helps you to write your
|
||||
own estimation of distribution algorithms.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2010 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <edo>
|
||||
|
||||
#include "Rosenbrock.h"
|
||||
|
||||
typedef eoReal< eoMinimizingFitness > EOT;
|
||||
typedef edoUniform< EOT > Distrib;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
eoState state;
|
||||
|
||||
edoContinue< Distrib >* continuator = new edoDummyContinue< Distrib >();
|
||||
state.storeFunctor(continuator);
|
||||
|
||||
return 0;
|
||||
}
|
||||
267
edo/test/t-edoEstimatorNormalMulti.cpp
Normal file
267
edo/test/t-edoEstimatorNormalMulti.cpp
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
/*
|
||||
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||
ANSI-C++ evolutionary computation library which helps you to write your
|
||||
own estimation of distribution algorithms.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2010 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
|
||||
#include <utils/eoLogger.h>
|
||||
#include <utils/eoParserLogger.h>
|
||||
|
||||
#include <edo>
|
||||
|
||||
#include "Rosenbrock.h"
|
||||
#include "Sphere.h"
|
||||
|
||||
typedef eoReal< eoMinimizingFitness > EOT;
|
||||
typedef edoNormalMulti< EOT > Distrib;
|
||||
typedef EOT::AtomType AtomType;
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
//-----------------------------------------------------
|
||||
// (0) parser + eo routines
|
||||
//-----------------------------------------------------
|
||||
|
||||
eoParserLogger parser(ac, av);
|
||||
|
||||
std::string section("Algorithm parameters");
|
||||
|
||||
unsigned int p_size = parser.createParam((unsigned int)100, "popSize", "Population Size", 'P', section).value(); // P
|
||||
|
||||
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
|
||||
|
||||
AtomType covar1_value = parser.createParam((AtomType)1.0, "covar1", "Covar value 1", '1', section).value();
|
||||
AtomType covar2_value = parser.createParam((AtomType)0.5, "covar2", "Covar value 2", '2', section).value();
|
||||
AtomType covar3_value = parser.createParam((AtomType)1.0, "covar3", "Covar value 3", '3', section).value();
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << p_size << "_" << std::fixed << std::setprecision(1)
|
||||
<< mean_value << "_" << covar1_value << "_" << covar2_value << "_"
|
||||
<< covar3_value << "_gen";
|
||||
std::string gen_filename = ss.str();
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
make_verbose(parser);
|
||||
make_help(parser);
|
||||
|
||||
|
||||
assert(p_size > 0);
|
||||
assert(s_size > 0);
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
for (unsigned int i = 0; i < s_size; ++i) { mean( i ) = 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 );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (3a) distribution output preparation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoDummyContinue< Distrib >* distrib_dummy_continue = new edoDummyContinue< Distrib >();
|
||||
state.storeFunctor(distrib_dummy_continue);
|
||||
|
||||
edoCheckPoint< Distrib >* distrib_continue = new edoCheckPoint< Distrib >( *distrib_dummy_continue );
|
||||
state.storeFunctor(distrib_continue);
|
||||
|
||||
edoDistribStat< Distrib >* distrib_stat = new edoStatNormalMulti< EOT >();
|
||||
state.storeFunctor(distrib_stat);
|
||||
|
||||
distrib_continue->add( *distrib_stat );
|
||||
|
||||
edoFileSnapshot* distrib_file_snapshot = new edoFileSnapshot( "TestResDistrib", 1, gen_filename );
|
||||
state.storeFunctor(distrib_file_snapshot);
|
||||
distrib_file_snapshot->add(*distrib_stat);
|
||||
distrib_continue->add(*distrib_file_snapshot);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (3b) distribution output
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
(*distrib_continue)( distrib );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare bounder class to set bounds of sampling.
|
||||
// This is used by edoSampler.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoBounder< EOT >* bounder = new edoBounderRng< EOT >(EOT(pop[0].size(), -5),
|
||||
EOT(pop[0].size(), 5),
|
||||
*gen);
|
||||
state.storeFunctor(bounder);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare sampler class with a specific distribution
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< 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 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (5) population output
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
eoContinue< EOT >* pop_cont = new eoGenContinue< EOT >( 2 ); // never reached fitness
|
||||
state.storeFunctor(pop_cont);
|
||||
|
||||
eoCheckPoint< EOT >* pop_continue = new eoCheckPoint< EOT >( *pop_cont );
|
||||
state.storeFunctor(pop_continue);
|
||||
|
||||
edoPopStat< EOT >* pop_stat = new edoPopStat<EOT>;
|
||||
state.storeFunctor(pop_stat);
|
||||
pop_continue->add(*pop_stat);
|
||||
|
||||
edoFileSnapshot* pop_file_snapshot = new edoFileSnapshot( "TestResPop", 1, gen_filename );
|
||||
state.storeFunctor(pop_file_snapshot);
|
||||
pop_file_snapshot->add(*pop_stat);
|
||||
pop_continue->add(*pop_file_snapshot);
|
||||
|
||||
(*pop_continue)( pop );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (6) estimation phase
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >();
|
||||
state.storeFunctor(estimator);
|
||||
|
||||
distrib = (*estimator)( pop );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (7) distribution output
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
(*distrib_continue)( distrib );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (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 << eo::logging
|
||||
<< "mean: " << mean << std::endl
|
||||
<< "new mean: " << new_mean << std::endl
|
||||
<< "distance: " << distance << std::endl
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
231
edo/test/t-mean-distance.cpp
Normal file
231
edo/test/t-mean-distance.cpp
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||
ANSI-C++ evolutionary computation library which helps you to write your
|
||||
own estimation of distribution algorithms.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2010 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
|
||||
#include <utils/eoLogger.h>
|
||||
#include <utils/eoParserLogger.h>
|
||||
|
||||
#include <edo>
|
||||
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/symmetric_matrix.hpp>
|
||||
|
||||
#include "Rosenbrock.h"
|
||||
#include "Sphere.h"
|
||||
|
||||
typedef eoReal< eoMinimizingFitness > EOT;
|
||||
typedef edoNormalMulti< EOT > Distrib;
|
||||
typedef EOT::AtomType AtomType;
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
//-----------------------------------------------------
|
||||
// (0) parser + eo routines
|
||||
//-----------------------------------------------------
|
||||
|
||||
eoParserLogger parser(ac, 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)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
|
||||
AtomType covar1_value = parser.createParam((AtomType)1.0, "covar1", "Covar value 1", '1', section).value(); // 1
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
make_verbose(parser);
|
||||
make_help(parser);
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
assert(r_max >= 1);
|
||||
assert(s_size >= 2);
|
||||
|
||||
eo::log << eo::quiet;
|
||||
|
||||
::mkdir( results_directory.c_str(), 0755 );
|
||||
|
||||
for ( unsigned int p_size = p_min; p_size <= p_max; p_size += p_step )
|
||||
{
|
||||
assert(p_size >= p_min);
|
||||
|
||||
std::ostringstream desc_file;
|
||||
desc_file << results_directory << "/" << files_description;
|
||||
|
||||
std::ostringstream cur_file;
|
||||
cur_file << results_directory << "/pop_" << p_size << ".txt";
|
||||
|
||||
eo::log << eo::file( desc_file.str() ) << cur_file.str().c_str() << std::endl;
|
||||
|
||||
eo::log << eo::file( cur_file.str() );
|
||||
|
||||
eo::log << eo::logging << "run_number p_size s_size mean(0) mean(1) new-mean(0) new-mean(1) distance" << std::endl;
|
||||
|
||||
eo::log << eo::quiet;
|
||||
|
||||
for ( unsigned int r = 1; r <= r_max; ++r)
|
||||
{
|
||||
|
||||
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 edoSampler.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoBounder< EOT >* bounder = new edoBounderRng< EOT >(EOT(pop[0].size(), -5),
|
||||
EOT(pop[0].size(), 5),
|
||||
*gen);
|
||||
state.storeFunctor(bounder);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare sampler class with a specific distribution
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< 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
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< 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
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
43
edo/test/t-uniform.cpp
Normal file
43
edo/test/t-uniform.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||
ANSI-C++ evolutionary computation library which helps you to write your
|
||||
own estimation of distribution algorithms.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2010 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <edo>
|
||||
|
||||
#include "Rosenbrock.h"
|
||||
|
||||
typedef eoReal< eoMinimizingFitness > EOT;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
eoState state;
|
||||
|
||||
edoUniform< EOT >* distrib = new edoUniform< EOT >( EOT(3, -1), EOT(3, 1) );
|
||||
state.storeFunctor(distrib);
|
||||
|
||||
return 0;
|
||||
}
|
||||
18
edo/test/test_cov_parameters.py
Executable file
18
edo/test/test_cov_parameters.py
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
PSIZE = 10000
|
||||
MEAN = 0
|
||||
CMD = "./test/t-edoEstimatorNormalMulti -P=%s -m=%.1f -1=%.1f -2=%.1f -3=%.1f && ./gplot.py -r TestResPop -p -w 5 -u -g %s -G results_for_test_cov_parameters -f %s_gen1"
|
||||
|
||||
from os import system
|
||||
from numpy import arange
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
for p1 in list(arange(0.1, 1.1, 0.1)):
|
||||
for p2 in list(arange(-1., 0., 0.1)) + list(arange(0., 1.1, 0.1)):
|
||||
for p3 in list(arange(0.1, 1.1, 0.1)):
|
||||
gen = '%d_%.1f_%.1f_%.1f_%.1f' % (PSIZE, MEAN, p1, p2, p3)
|
||||
cmd = CMD % ( PSIZE, MEAN, p1, p2, p3, gen, gen )
|
||||
print cmd
|
||||
system( cmd )
|
||||
Reference in a new issue