Commit 4b013a30 authored by maitre's avatar maitre

Un-broken INSTEAD_EVAL CUDA.tpl

parent 2434f345
......@@ -27,6 +27,8 @@ Centre de Math
#define CUDA_FLAVOR_SO 0
#define CUDA_FLAVOR_MO 1
#define CUDA_FLAVOR_CMAES 2
#define CUDA_FLAVOR_GP 3
#define UNIX 1
#define WINDOWS 2
......
......@@ -1828,7 +1828,7 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
strcat(sTemp,"CUDA.tpl");
else if(TARGET_FLAVOR == CUDA_FLAVOR_CMAES )
strcat(sTemp,"CMAES_CUDA.tpl");
else
else
strcat(sTemp,"CUDA_MO.tpl");
if (!(yyin = fpTemplateFile = fopen(sTemp, "r"))){
......@@ -1842,6 +1842,8 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
strcat(sTemp,"STD.tpl");
else if (TARGET_FLAVOR == STD_FLAVOR_CMAES)
strcat(sTemp,"CMAES.tpl");
else if( TARGET_FLAVOR == CUDA_FLAVOR_GP )
strcat(sTemp,"CUDA_GP.tpl");
else
strcat(sTemp,"STD_MO.tpl");
if (!(yyin = fpTemplateFile = fopen(sTemp, "r"))){
......
......@@ -657,6 +657,10 @@ int main(int argc, char *argv[]){
TARGET=CUDA;
TARGET_FLAVOR = CUDA_FLAVOR_MO;
}
else if( !mystricmp(sTemp,"cuda_gp") ){
TARGET=STD;
TARGET_FLAVOR = CUDA_FLAVOR_GP;
}
else if (!mystricmp(sTemp,"std")) {
TARGET=STD;
......@@ -675,8 +679,12 @@ int main(int argc, char *argv[]){
TARGET_FLAVOR = CUDA_FLAVOR_CMAES;
}
else if (!mystricmp(sTemp,"v")) bVERBOSE=true;
else if (!mystricmp(sTemp,"tl")) bLINE_NUM_EZ_FILE=false;
else if (!mystricmp(sTemp,"tl")){
printf("yopyop true line\n");
bLINE_NUM_EZ_FILE=false;
}
else if (!mystricmp(sTemp,"path")) {
if (argv[++nParamNb][0]=='"') {
strcpy(sEZ_PATH,&(argv[nParamNb][1]));
......
77
0.05,0.61,0.3,5,27.2
0.05,0.61,0.3,15,44.9
0.05,0.61,0.3,30,59.3
0.05,0.61,0.3,45,68.7
0.05,0.61,0.3,75,80.1
0.05,0.61,0.3,120,87.2
0.05,0.61,0.3,180,94.2
0.05,0.86,0.61,5,27.2
0.05,0.86,0.61,15,41.6
0.05,0.86,0.61,30,56.4
0.05,0.86,0.61,45,64.7
0.05,0.86,0.61,75,74
0.05,0.86,0.61,120,81.4
0.05,0.86,0.61,180,86.2
0.05,0.76,0.76,5,8.7
0.05,0.76,0.76,15,21.3
0.05,0.76,0.76,30,33.9
0.05,0.76,0.76,45,42.9
0.05,0.76,0.76,75,57.3
0.05,0.76,0.76,120,65.5
0.05,0.76,0.76,180,69.2
0.06,0.86,0.61,5,17.7
0.06,0.86,0.61,15,30.1
0.06,0.86,0.61,30,43.9
0.06,0.86,0.61,45,52
0.06,0.86,0.61,75,64.7
0.06,0.86,0.61,120,74.6
0.06,0.86,0.61,180,82
0.25,0.86,0.61,5,8.5
0.25,0.86,0.61,15,20.9
0.25,0.86,0.61,30,33.6
0.25,0.86,0.61,45,44.6
0.25,0.86,0.61,75,56.6
0.25,0.86,0.61,120,68.2
0.25,0.86,0.61,180,76
0.35,0.76,0.76,5,5
0.35,0.76,0.76,15,14.9
0.35,0.76,0.76,30,28.6
0.35,0.76,0.76,45,37.3
0.35,0.76,0.76,75,51.3
0.35,0.76,0.76,120,63.6
0.35,0.76,0.76,180,72.1
0.5,0.86,0.61,5,5
0.5,0.86,0.61,15,14.5
0.5,0.86,0.61,30,27.6
0.5,0.86,0.61,45,36.4
0.5,0.86,0.61,75,52.3
0.5,0.86,0.61,120,64.3
0.5,0.86,0.61,180,72
0.5,1.52,0.76,5,10.5
0.5,1.52,0.76,15,20.4
0.5,1.52,0.76,30,34
0.5,1.52,0.76,45,46.4
0.5,1.52,0.76,75,61.2
0.5,1.52,0.76,120,76.2
0.5,1.52,0.76,180,80
0.5,1.07,0.76,5,10.5
0.5,1.07,0.76,15,19.7
0.5,1.07,0.76,30,32.3
0.5,1.07,0.76,45,42.3
0.5,1.07,0.76,75,57.1
0.5,1.07,0.76,120,70.8
0.5,1.07,0.76,180,76
0.5,0.94,0.76,5,9.1
0.5,0.94,0.76,15,18.4
0.5,0.94,0.76,30,31.7
0.5,0.94,0.76,45,40.3
0.5,0.94,0.76,75,54.1
0.5,0.94,0.76,120,67.8
0.5,0.94,0.76,180,74
0.5,0.76,0.76,5,9.5
0.5,0.76,0.76,15,17.3
0.5,0.76,0.76,30,28.3
0.5,0.76,0.76,45,37.2
0.5,0.76,0.76,75,49
0.5,0.76,0.76,120,61.7
0.5,0.76,0.76,180,66
......@@ -10,6 +10,11 @@ __________________________________________________________*/
#include <errno.h>
#include <sstream>
#include <math.h>
#include <cutil.h>
#define OPERAND 0
......@@ -191,7 +196,7 @@ void toDotFile(GPNode* root, const char* baseFileName, int treeId){
std::ostringstream oss;
oss << baseFileName << "-" << treeId << ".gv";
FILE* outputFile = fopen(oss.str().c_str(),"w");
FILE* outputFile = fopen(oss.str().c_str(),"a");
if( !outputFile ){
perror("Opening file for outputing dot representation ");
exit(-1);
......@@ -356,9 +361,15 @@ GPNode* selectNode( GPNode* root, int* childId, int* depth){
fitnessCasesSetLength = load_data(&inputs,&outputs,"quadra_reg_data.csv");
cout << "number of point in fitness cases set : " << fitnessCasesSetLength << endl;
INSTEAD_EVAL_STEP=true;
// Adding another stopping, as we are minimizing, the goal is 0
CGoalCriterion* gc = new CGoalCriterion(0,true);
EA->stoppingCriteria.push_back(gc);
// Here starts the CUDA parts
cudaSetDevice(1); // on GTX295 ;) we want to use the second card for computation
}
\end
......@@ -393,7 +404,11 @@ GPNode* selectNode( GPNode* root, int* childId, int* depth){
\end
\Instead evaluation function:
cout << "yopyop" << endl;
{
for( int i=0 ; i<popSize ; i++ ){
cout << population[i] << endl;
}
}
\end
\User classes :
......@@ -627,7 +642,6 @@ GenomeClass {
\end
\User Makefile options:
CPPFLAGS+=
\end
\Default run parameters : // Please let the parameters appear in this order
......
This diff is collapsed.
*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 22
#define X_MIN -1.
#define X_MAX 1.
#define ITER 50
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
float pMutPerGene=0.1;
struct gpuOptions initOptions;
\end
\User functions:
//fitness function
#include <math.h>
__device__ __host__ float SQR(float d)
{
return (d*d);
}
__device__ __host__ inline float rosenbrock( float const *x, int size)
{
float qualitaet;
int i;
int DIM = size;
qualitaet = 0.0;
for( i = DIM-2; i >= 0; --i)
qualitaet += 100.*SQR(SQR(x[i])-x[i+1]) + SQR(1.-x[i]);
return ( qualitaet);
} /* f_rosenbrock() */
__device__ __host__ inline float cigtab(float *x, int size)
{
int i;
float sum = 0.;
sum = x[0]*x[0] + 1e8*x[size-1]*x[size-1];
for (i = 1; i < size-1; ++i)
sum += 1e4*x[i]*x[i];
return sum;
}
\end
\GenomeClass::display:
for(int i=0; i<SIZE; i++){
cout << Genome.x[i] << "|";
}
\end
\Before everything else function:
\end
\After everything else function:
\end
\At the beginning of each generation function:
\end
\At the end of each generation function:
\end
\At each generation before reduce function:
\end
\User classes :
GenomeClass {
float x[SIZE];
}
\end
\GenomeClass::initialiser : // "initializer" is also accepted
\end
\GenomeClass::display:
\end
\GenomeClass::crossover :
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
return NbMut;
\end
\GenomeClass::evaluator : // Returns the score
float Score= 0.0;
Score= rosenbrock(Genome.x, SIZE);
return Score;
\end
\User Makefile options:
CPPFLAGS+=
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Time limit: 0 // In seconds, 0 to deactive
Population size : 1000 // POP_SIZE
Offspring size : 2000
Final reduce operator:Deterministic //Deterministic, Tournament, Random, Roulette(only Maximise)
Elitism: Strong //Weak or Strong
Elite: 5
Print stats:1 //Default: 1
Print stats to file:0
Plot stats:0 //Default: 0
\end
*_________________________________________________________
Test functions
__________________________________________________________*/
\User declarations :
#define SIZE 22
#define X_MIN -1.
#define X_MAX 1.
#define ITER 50
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
float pMutPerGene=0.1;
\end
\User functions:
//fitness function
#include <math.h>
static double SQR(double d)
{
return (d*d);
}
double rosenbrock( double const *x)
/*
Rosenbrock's Function, generalized.
*/
{
double qualitaet;
int i;
int DIM = SIZE;
qualitaet = 0.0;
for( i = DIM-2; i >= 0; --i)
qualitaet += 100.*SQR(SQR(x[i])-x[i+1]) + SQR(1.-x[i]);
return ( qualitaet);
} /* f_rosenbrock() */
double cigtab(double *x)
{
int i;
double sum = 0.;
sum = x[0]*x[0] + 1e8*x[SIZE-1]*x[SIZE-1];
for (i = 1; i < SIZE-1; ++i)
sum += 1e4*x[i]*x[i];
return sum;
}
\end
\GenomeClass::display:
for(int i=0; i<SIZE; i++){
cout << Genome.x[i] << "|";
}
\end
\Before everything else function:
\end
\After everything else function:
\end
\At the beginning of each generation function:
\end
\At the end of each generation function:
\end
\At each generation before reduce function:
\end
\User classes :
GenomeClass {
double x[SIZE];
}
\end
\GenomeClass::display:
\end
\GenomeClass::initialiser : // "initializer" is also accepted
\end
\GenomeClass::crossover :
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
return NbMut;
\end
\GenomeClass::evaluator : // Returns the score
float Score= 0.0;
Score= cigtab(Genome.x);
//Score= rosenbrock(Genome.x);
return Score;
\end
\User Makefile options:
CXXFLAGS+=
LIBS+=
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Time limit: 0 // In seconds, 0 to deactive
Population size : 7 // POP_SIZE
Offspring size : 13
Final reduce operator:Deterministic //Deterministic, Tournament, Random, Roulette(only Maximise)
Elitism: Strong //Weak or Strong
Elite: 5
Print stats:1 //Default: 1
Print stats to file:0
Plot stats:0 //Default: 0
\end
/*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 100
#define X_MIN -1.
#define X_MAX 1.
#define ITER 120
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
float pMutPerGene=0.1;
struct gpuOptions;
\end
\User functions:
//fitness function
#include <math.h>
__device__ __host__ inline float Weierstrass(float *x, int n) // Weierstrass multimidmensionnel h = 0.25
{
float res = 0.;
float val[SIZE];
float b=2.;
float h = 0.25;
for (int i = 0;i<n; i++) {
val[i] = 0.;
for (int k=0;k<ITER;k++)
val[i] += pow(b,-(float)k*h) * sin(pow(b,(float)k)*x[i]);
res += Abs(val[i]);
}
return (res);
}
float gauss()
/* Generates a normally distributed random value with variance 1 and 0 mean.
Algorithm based on "gasdev" from Numerical recipes' pg. 203. */
{
int iset = 0;
float gset = 0.0;
float v1 = 0.0, v2 = 0.0, r = 0.0;
float factor = 0.0;
if (iset) {
iset = 0;
return gset;
}
else {
do {
v1 = (float)random(0.,1.) * 2.0 - 1.0;
v2 = (float)random(0.,1.) * 2.0 - 1.0;
r = v1 * v1 + v2 * v2;
}
while (r > 1.0);
factor = sqrt (-2.0 * log (r) / r);
gset = v1 * factor;
iset = 1;
return (v2 * factor);
}
}
\end
\GenomeClass::display:
for(int i=0; i<SIZE; i++){
cout << Genome.x[i] << ":" << Genome.sigma[i] << "|";
}
\end
\Before everything else function:
\end
\After everything else function:
\end
\At the beginning of each generation function:
//cout << "At the beginning of each generation function called" << endl;
\end
\At the end of each generation function:
//cout << "At the end of each generation function called" << endl;
\end
\At each generation before reduce function:
//cout << "At each generation before replacement function called" << endl;
\end
\User classes :
GenomeClass {
float x[SIZE];
float sigma[SIZE]; // auto-adaptative mutation parameter
}
\end
\GenomeClass::initialiser : // "initializer" is also accepted
for(int i=0; i<SIZE; i++ ) {
Genome.x[i] = (float)random(X_MIN,X_MAX);
Genome.sigma[i]=(float)random(0.,0.5);
}
\end
\GenomeClass::crossover :
for (int i=0; i<SIZE; i++)
{
float alpha = (float)random(0.,1.); // barycentric crossover
child1.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i];
}
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
float pond = 1./sqrt((float)SIZE);
for (int i=0; i<SIZE; i++)
if (tossCoin(pMutPerGene)){
NbMut++;
Genome.sigma[i] = Genome.sigma[i] * exp(SIGMA*pond*(float)gauss());
Genome.sigma[i] = MIN(0.5,Genome.sigma[0]);
Genome.sigma[i] = MAX(0.,Genome.sigma[0]);
Genome.x[i] += Genome.sigma[i]*(float)gauss();
Genome.x[i] = MIN(X_MAX,Genome.x[i]); // pour eviter les depassements
Genome.x[i] = MAX(X_MIN,Genome.x[i]);
}
return NbMut;
\end
\GenomeClass::evaluator : // Returns the score
float Score= 0.0;
Score= Weierstrass(Genome.x, SIZE);
return Score;
\end
\User Makefile options:
CPPFLAGS+=
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate
Population size : 3840 //POP_SIZE
Offspring size : 3840 // 40%
Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB
Evaluator goal : minimise // Maximise
Selection operator: Tournament 2.0
Surviving parents: 3840//percentage or absolute
Surviving offspring: 3840
Reduce parents operator: Tournament 2.0
Reduce offspring operator: Tournament 2
Final reduce operator: Tournament 2
Elitism: Strong //Weak or Strong
Elite: 5
Print stats:1 //Default: 1
Plot stats:0 //Default: 0
Generate cvs stats file:0
Generate gnuplot script:0
Generate R script:0
\end
/*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 100
#define X_MIN -1.
#define X_MAX 1.
#define ITER 120
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
float pMutPerGene=0.1;
\end
\User functions:
//fitness function
#include <math.h>
__device__ __host__ inline float Weierstrass(float x[SIZE], int n) // Weierstrass multimidmensionnel h = 0.25
{
float res = 0.;
float val[SIZE];
float b=2.;
float h = 0.25;
for (int i = 0;i<n; i++) {
val[i] = 0.;
for (int k=0;k<ITER;k++)
val[i] += pow(b,-(float)k*h) * sin(pow(b,(float)k)*x[i]);
res += Abs(val[i]);
}
return (res);
}
float gauss()
/* Generates a normally distributed random value with variance 1 and 0 mean.
Algorithm based on "gasdev" from Numerical recipes' pg. 203. */
{
int iset = 0;
float gset = 0.0;
float v1 = 0.0, v2 = 0.0, r = 0.0;
float factor = 0.0;
if (iset) {
iset = 0;
return gset;
}
else {
do {
v1 = (float)random(0.,1.) * 2.0 - 1.0;
v2 = (float)random(0.,1.) * 2.0 - 1.0;
r = v1 * v1 + v2 * v2;
}
while (r > 1.0);
factor = sqrt (-2.0 * log (r) / r);
gset = v1 * factor;
iset = 1;
return (v2 * factor);
}
}
\end
\Before everything else function:
//cout<<"Before everything else function called "<<endl;
\end
\After everything else function:
//cout << "After everything else function called" << endl;
\end
\At the beginning of each generation function:
//cout << "At the beginning of each generation function called" << endl;
\end
\At the end of each generation function:
//cout << "At the end of each generation function called" << endl;
\end
\At each generation before reduce function:
//cout << "At each generation before replacement function called" << endl;
\end
\User classes :
GenomeClass {
float x[SIZE];
float sigma[SIZE]; // auto-adaptative mutation parameter
}
\end
\GenomeClass::display:
/* for( size_t i=0 ; i<SIZE ; i++){ */
/* // cout << Genome.x[i] << ":" << Genome.sigma[i] << "|"; */
/* printf("%.02f:%.02f|",Genome.x[i],Genome.sigma[i]); */
/* } */
\end
\GenomeClass::initialiser : // "initializer" is also accepted
for(int i=0; i<SIZE; i++ ) {
Genome.x[i] = (float)random(X_MIN,X_MAX);
Genome.sigma[i]=(float)random(0.,0.5);
}
\end
\GenomeClass::crossover :
for (int i=0; i<SIZE; i++)
{
float alpha = (float)random(0.,1.); // barycentric crossover
child1.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i];
}
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
float pond = 1./sqrt((float)SIZE);
for (int i=0; i<SIZE; i++)
if (tossCoin(pMutPerGene)){
NbMut++;
Genome.sigma[i] = Genome.sigma[i] * exp(SIGMA*pond*(float)gauss());
Genome.sigma[i] = MIN(0.5,Genome.sigma[0]);
Genome.sigma[i] = MAX(0.,Genome.sigma[0]);
Genome.x[i] += Genome.sigma[i]*(float)gauss();
Genome.x[i] = MIN(X_MAX,Genome.x[i]); // pour eviter les depassements
Genome.x[i] = MAX(X_MIN,Genome.x[i]);
}
return NbMut;
\end
\GenomeClass::evaluator : // Returns the score
float Score= 0.0;
Score= Weierstrass(Genome.x, SIZE);
return Score;
\end
\User Makefile options:
CPPFLAGS+=
\end