-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneExpress.cpp
More file actions
95 lines (66 loc) · 1.93 KB
/
GeneExpress.cpp
File metadata and controls
95 lines (66 loc) · 1.93 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// GeneExpress.cpp : Defines the entry point for the console application.
//
// stdafx is not included in the project files on SourceForge
#include "stdafx.h"
#include <Math.h>
#include "GEP.hh"
int _tmain(int argc, _TCHAR* argv[])
{
// GEP Parameters
unsigned gene_head_length = 7;
unsigned genes_per_chromosome = 1;
unsigned population_size = 200;
unsigned constants_per_chromosome = 1;
int max_epochs = 2000;
std::string functions = "QES";
double mutation_rate = 0.05;
double RIS_rate = 0.1;
double IS_rate = 0.1;
double One_Point_rate = 0.3;
double Two_Point_rate = 0.3;
double Whole_Gene_rate = 0.1;
double Constant_mutation = 0.1;
double Constant_swap = 0.1;
double Constant_range = 10.0;
double validation_fraction = 0.1; // not implemented
// Generate a training set of multivariate data.
std::vector<std::vector<double> > data;
std::vector<double> vals;
for(int i=0;i<50;i++) {
double a = randomOne();
double b = randomOne();
vals.push_back(a);
vals.push_back(b);
vals.push_back(5*sin(a)+b); // last variable is the function value
data.push_back(vals);
vals.clear();
}
// Create the Gene Expression Program (GEP)
GEP *gep = new GEP(
gene_head_length,
genes_per_chromosome,
constants_per_chromosome,
population_size,
validation_fraction,
max_epochs,
functions);
// Set the mutation rates etc.
gep->setRates(
mutation_rate,
RIS_rate,
IS_rate,
One_Point_rate,
Two_Point_rate,
Whole_Gene_rate,
Constant_mutation,
Constant_swap,
Constant_range);
// Tell the GEP about the data
gep->setData(&data);
// Request the GEP to create a population of chromosomes
gep->createPopulation();
int verbose = 1;
// Request the GEP to train the chromosomes to reproduce the data
gep->train(verbose);
return 0;
}