-
Notifications
You must be signed in to change notification settings - Fork 0
/
gp_fly.cpp
68 lines (54 loc) · 1.79 KB
/
gp_fly.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <ga/ga.hpp>
#include <tree/generator.hpp>
#include <tree/crossover.hpp>
#include <tree/mutator.hpp>
#include <tree/functions.hpp>
#include <boost/lexical_cast.hpp>
const double target_value=8.0; // ГОСТ 10180-09
const double mtn_raiting=0.9;
const int resize_data=1; // для BOOTSTRAP
int psize=100;
int max_steps=100;
int max_depth=5;
double percent_to_learn=0.5;
double selection_percent=0.4;
bool print_only_best=false;
int main(int argc,char*argv[])
{
if(argc<2){
LOG("usage: "<<argv[0]<<" data.csv");
return -1;
}
if(argc==3)
print_only_best=true;
Concrete::CData cdata(argv[1]);
cdata.init();
Concrete::CData bt_cdata=cdata.bootstrap(resize_data,0.05);
Tree::FunctionDB* fdb=Tree::std_functions_db();
fdb->add_variables(bt_cdata.x_count());
// for(double i=-10.0;i<10.0;i+=0.5)
// fdb->add_constant(i);
Tree::Generator*gnrt=new Tree::Generator(fdb,max_depth,true);
Tree::Crossover*crossover=new Tree::Crossover;
Tree::Mutator mtr(gnrt,crossover);
GpGenerator *dg=new GpGenerator(gnrt);
selector *sel_r=new rnd_selector;
GpMutator *gp_mtn=new GpMutator(gnrt,crossover,fdb);
GpCrossover*c=new GpCrossover(fdb,crossover);
std_ga* sg=new std_ga(sel_r,gp_mtn,c,dg);
sg->addSuffix("-FlyGenerator");
// tester test;
// test.addTest(make_test(new GpFitness(percent_to_learn,&bt_cdata,fdb),
// make_params(mtn_raiting,0.4,psize),
// 0,0,
// target_value,max_steps));
// test.addGA(sg);
// test.run(10);
GpFitness*ftn=new GpFitness(percent_to_learn,&bt_cdata,fdb);
sg->set_params(make_params(mtn_raiting,0.4,psize));
sg->setFitness(ftn);
sg->init();
solution sln=sg->getSolution(max_steps,target_value,true,print_only_best);
LOG("results: "<<sln.first);
ftn->check_solution(sln.second,&cdata);
}