37 using namespace shark;
40 int main(
int argc,
char ** argv ) {
42 std::size_t numDimensions = 10;
43 std::size_t numTrials = 100;
44 std::size_t recordingInterval = 20;
45 std::size_t numIterations = 20*recordingInterval;
48 typedef boost::shared_ptr<SingleObjectiveFunction > Function;
49 std::vector<Function > functions;
50 functions.push_back(Function(
new Rosenbrock(numDimensions)));
51 functions.push_back(Function(
new Cigar(numDimensions)));
52 functions.push_back(Function(
new Discus(numDimensions)));
53 functions.push_back(Function(
new Ellipsoid(numDimensions)));
55 RealMatrix meanPerformance(functions.size(), numIterations/recordingInterval+1,0.0);
56 for(std::size_t f = 0; f != functions.size(); ++f){
57 for(std::size_t trial = 0; trial != numTrials; ++trial){
59 std::cout<<
"\r" <<functions[f]->name() <<
": "<<trial<<
"/"<<numTrials<<std::flush;
63 cma.
init( *functions[f] );
69 for(std::size_t i = 1; i <= numIterations; ++i){
70 cma.
step(*functions[f]);
71 if(i % recordingInterval == 0){
72 meanPerformance(f,i / recordingInterval) += cma.
solution().
value;
77 meanPerformance /= numTrials;
79 std::cout<<
"\r# Iteration ";
80 for(std::size_t f = 0; f != functions.size(); ++f)
81 std::cout<<functions[f]->name()<<
" ";
84 std::cout.precision( 7 );
85 for(std::size_t i = 0; i != meanPerformance.size2();++i){
86 std::cout<< i*recordingInterval<<
" ";
87 for(std::size_t f = 0; f != functions.size(); ++f){
88 std::cout<<meanPerformance(f,i)<<
" ";