Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Arnaud Kress
easea
Commits
80aa1535
Commit
80aa1535
authored
Oct 18, 2010
by
Ogier Maitre
Browse files
Merge de la branche GP et syntaxerror
parent
b90e4e08
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
EaseaLex.cpp
View file @
80aa1535
This diff is collapsed.
Click to expand it.
EaseaLex.l
View file @
80aa1535
...
...
@@ -5,7 +5,7 @@ Lexical analyser for the EASEA language (EAsy Specification for Evolutionary Alg
Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
Centre de Mathmatiques Appliques
Centre de Math
�
matiques Appliqu
�
es
91128 Palaiseau cedex
****************************************************************************/
#ifdef WIN32
...
...
@@ -327,6 +327,8 @@ exponent ([Ee][+-]?[0-9]+)
opDesc[iNoOp]->opcode = new string(yytext);
}
<GP_RULE_ANALYSIS>"//".*"\n" {}
<GP_RULE_ANALYSIS>"\""([a-zA-Z0-9]|\*|\+|\-|\/|\%)*"\"" {
if( iGP_OPCODE_FIELD != 1 ){
fprintf(stderr,"Error, op code real name must be given at the second place\n");
...
...
@@ -369,7 +371,7 @@ exponent ([Ee][+-]?[0-9]+)
if( bVERBOSE ) printf("begining of the code part\n");
accolade_counter=1;
printf("arity : %d\n",opDesc[iNoOp]->arity);
//
printf("arity : %d\n",opDesc[iNoOp]->arity);
if( opDesc[iNoOp]->arity>=2 )
opDesc[iNoOp]->gpuCodeStream << "OP2 = stack[--sp];\n ";
if( opDesc[iNoOp]->arity>=1 )
...
...
@@ -404,7 +406,7 @@ exponent ([Ee][+-]?[0-9]+)
<GP_COPY_OPCODE_CODE>"INPUT["[0-9]*"]" {
char* endptr;
unsigned no_input = strtol(yytext+strlen("INPUT["),&endptr,10);
printf("input no : %d\n",no_input);
//
printf("input no : %d\n",no_input);
opDesc[iNoOp]->cpuCodeStream << "input["<< no_input <<"]" ;
opDesc[iNoOp]->gpuCodeStream << "input["<< no_input << "]";
}
...
...
@@ -413,7 +415,7 @@ exponent ([Ee][+-]?[0-9]+)
opDesc[iNoOp]->isERC = true;
opDesc[iNoOp]->cpuCodeStream << "root->erc_value" ;
opDesc[iNoOp]->gpuCodeStream << "k_progs[start_prog++];" ;
printf("ERC matched\n");
//
printf("ERC matched\n");
}
<GP_COPY_OPCODE_CODE>\n {
...
...
@@ -446,9 +448,26 @@ exponent ([Ee][+-]?[0-9]+)
iCOPY_GP_EVAL_STATUS = EVAL_BDY;
if( bVERBOSE ) printf("Insert GP eval body\n");
fprintf(fpOutputFile," ");
bCOPY_GP_EVAL_GPU = false;
BEGIN COPY_GP_EVAL;
}
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_BDY_GPU" {
yyreset();
rewind(fpGenomeFile);
yyin = fpGenomeFile;
bIsCopyingGPEval = false;
iCOPY_GP_EVAL_STATUS = EVAL_BDY;
if( bVERBOSE ) printf("Insert GP eval body\n");
fprintf(fpOutputFile," ");
bCOPY_GP_EVAL_GPU = true;
BEGIN COPY_GP_EVAL;
}
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_FTR" {
yyreset();
rewind(fpGenomeFile);
...
...
@@ -523,7 +542,11 @@ exponent ([Ee][+-]?[0-9]+)
}
<COPY_GP_EVAL>"OUTPUT" {
if( bIsCopyingGPEval) fprintf(fpOutputFile, "outputs[i]" );
if( bIsCopyingGPEval)
if( bCOPY_GP_EVAL_GPU )
fprintf(fpOutputFile, "outputs[i*NUMTHREAD2+tid]" );
else fprintf(fpOutputFile, "outputs[i]" );
}
<COPY_GP_EVAL>"return " {
...
...
@@ -1308,7 +1331,7 @@ if(OPERATING_SYSTEM=WINDOWS)
bFunction=1; bInitFunction=1;
if( bLINE_NUM_EZ_FILE )
fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
BEGIN COPY;
}
<COPY_INITIALISATION_FUNCTION><<EOF>> {bInitFunction=0; // No before everything else function was found in the .ez file
...
...
@@ -1649,7 +1672,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<GENOME_ANALYSIS>"GPNode" {
yylval.pSymbol = new CSymbol("GPNode");
//yylval.pSymbol->ObjectType = oPointer;
printf("match gpnode\n");
//
printf("match gpnode\n");
return GPNODE;
}
...
...
@@ -2120,7 +2143,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<GET_PARAMETERS>"Evaluator"[ \t\n]+"goal"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tMinMax...\n");return MINIMAXI;}
<GET_PARAMETERS>"Number"[ \t\n]+"of"[ \t\n]+"optimisation"[ \t\n]+"iterations"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tNb of Optimisation It...\n");return NB_OPT_IT;}
<GET_PARAMETERS>"Baldwinism"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tBaldwinism...\n");return BALDWINISM;}
<GET_PARAMETERS>"Remote"[ \t\n]+"island"[ \t\n]+"model"[ \t\n]*":"[ \t\n]* {if(bVERBOSE) printf ("\tRemote Island Model...\n"); return REMOTE_ISLAND_MODEL;}
<GET_PARAMETERS>"IP"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if(bVERBOSE) printf("\tIP File...\n"); return IP_FILE;}
...
...
EaseaParse.h
View file @
80aa1535
...
...
@@ -123,7 +123,9 @@ public:
double
divide
(
double
dDividend
,
double
dDivisor
);
CSymbol
*
insert
()
const
;
#line 127 "EaseaParse.h"
virtual
void
yysyntaxerror
();
#line 129 "EaseaParse.h"
};
#ifndef YYPARSENAME
...
...
EaseaParse.y
View file @
80aa1535
...
...
@@ -5,7 +5,7 @@ Parser for the EASEA language (EAsy Specification for Evolutionary Algorithms)
Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
Centre de Math
m
atiques Applique
s
Centre de Math
�ma
tiques Appliqu�e
s
91128 Palaiseau cedex
****************************************************************************/
...
...
@@ -160,7 +160,7 @@ class CSymbol;
}
// parser name and class definition
%name CEASEAParser
%name CEASEAParser
{
protected:
CEASEALexer EASEALexer; // the lexical analyser
...
...
@@ -173,6 +173,8 @@ public:
double assign(CSymbol* pIdentifier, double dValue);
double divide(double dDividend, double dDivisor);
CSymbol* insert() const;
virtual void yysyntaxerror();
}
// constructor
...
...
@@ -317,8 +319,8 @@ Objects
| Objects ',' Object
;
// Attention : il reste
gre
r correctement les tableaux de pointeurs
// les indirections multiples et les tableaux
plusieurs dimensions.
// Attention : il reste
� g�rer
correctement les tableaux de pointeurs
// les indirections multiples et les tableaux
� p
lusieurs dimensions.
// Je sais, il faudrait aussi utiliser un peu de polymorphisme pour les symboles
Object
...
...
@@ -835,3 +837,10 @@ double CEASEAParser::divide(double a, double b)
return a / b;
}
}
void CEASEAParser::yysyntaxerror(){
printf("Syntax Error at line : %d\n",EASEALexer.yylineno);
}
Makefile
View file @
80aa1535
...
...
@@ -11,7 +11,7 @@ $(EXEC):EaseaSym.o EaseaParse.o EaseaLex.o alexyacc/libalex.a EaseaYTools.o boos
#else
#$(EXEC):EaseaSym.o EaseaParse.o EaseaLex.o alexyacc/libalex.a EaseaYTools.o libeasea/libeasea.a
#endif
$(CPPC)
$(CPPFLAGS)
$(LDFLAGS)
$^
-o
$@
$(CPPC)
$(CPPFLAGS)
$(LDFLAGS)
$^
-o
$@
#
# Congratulations ! It looks like you compiled EASEA successfully.
#
...
...
@@ -81,7 +81,7 @@ endif
EaseaParse.o
:
EaseaParse.cpp EaseaLex.cpp
$(CPPC)
$(CPPFLAGS)
$<
-o
$@
-c
$(CPPC)
$(CPPFLAGS)
$<
-o
$@
-c
2>/dev/null
%.o
:
%.cpp
$(CPPC)
$(CPPFLAGS)
-c
-o
$@
$<
...
...
dev/c4.5_geo/card.ez
View file @
80aa1535
...
...
@@ -8,6 +8,110 @@ __________________________________________________________*/
\User functions:
float evaluation_fonction(int k, IndividualImpl* Genome,struct base** k_tables,unsigned* packets_size){
struct base* k_tmp_tables[k];
unsigned error = 0;
unsigned tree_size = 0;
// generate tmp tables from genome, for every packets
float fitness_value = 0;
for( unsigned i=0 ; i<k ; i++ ){
k_tmp_tables[i] = table_from_genome(Genome->x,k_tables[i],t2,GENOME_SIZE,GENE_SIZE);
}
// cross validation
for( unsigned i=0 ; i<k ; i++ ){
struct base* tmp_learning_table= (struct base*)malloc(sizeof(*tmp_learning_table));
struct base* tmp_test_table = (struct base*)malloc(sizeof(*tmp_test_table));
tmp_learning_table->instances =
(float**)malloc(sizeof(*tmp_learning_table->instances)*t1->no_instances-k_tables[i]->no_instances);
tmp_learning_table->hdr = ba_partial_copy_hdr(k_tmp_tables[i]->hdr);
tmp_test_table->hdr = ba_partial_copy_hdr(k_tmp_tables[i]->hdr);
// create a learning set with k-1 packets
unsigned copied_instances = 0;
for( unsigned j=0 ; j<k ; j++ ){
if(j==i)continue;
memcpy( (tmp_learning_table->instances)+copied_instances,
k_tmp_tables[j]->instances,
sizeof(*tmp_learning_table->instances)*(k_tmp_tables[j]->no_instances));
copied_instances += k_tmp_tables[j]->no_instances;
}
tmp_learning_table->no_instances = copied_instances;
// create the test set with 1 packet
tmp_test_table->instances = (float**)malloc(sizeof(*tmp_test_table->instances)*k_tmp_tables[i]->no_instances);
memcpy(tmp_test_table->instances,k_tmp_tables[i]->instances,
sizeof(*tmp_test_table->instances)*k_tmp_tables[i]->no_instances);
tmp_test_table->no_instances = k_tmp_tables[i]->no_instances;
// set threshold, from t1 for standard attribute
for( unsigned j=0 ; j<t1->hdr->no_attributes ; j++ ){
tmp_test_table->hdr->attributes[j]->threshold = t1->hdr->attributes[j]->threshold;
tmp_test_table->hdr->attributes[j]->no_threshold = t1->hdr->attributes[j]->no_threshold;
}
// compute threshold for attribute generated by genome
ba_compute_threshold_from(tmp_test_table,t1->hdr->no_attributes);
// set threshold, from t1 for standard attribute
for( unsigned j=0 ; j<t1->hdr->no_attributes ; j++ ){
tmp_learning_table->hdr->attributes[j]->threshold = t1->hdr->attributes[j]->threshold;
tmp_learning_table->hdr->attributes[j]->no_threshold = t1->hdr->attributes[j]->no_threshold;
}
// compute threshold for attribute generated by genome
ba_compute_threshold_from(tmp_learning_table,t1->hdr->no_attributes);
cTreeNode* t = genereate_decision_tree(tmp_learning_table);
//show_tree(k_tmp_tables[0],t,0);
//DBG_print_instances(tmp_test_table->instances,tmp_test_table->no_instances,tmp_test_table->hdr->no_attributes);
for( unsigned j=0 ; j<tmp_test_table->no_instances ; j++ ){
unsigned predicted_class = t->classify_instance(tmp_test_table->instances[j]);
unsigned real_class = (unsigned)tmp_test_table->instances[j][t1->hdr->whichis_class];
//printf("%3.0f : %d, %d\n",tmp_test_table->instances[j][1],predicted_class,real_class);
// here compute classification error, or any quality measurment
if( predicted_class!=real_class ){
error++;
}
}
//printf("err : %f %d\n",fitness_value,t->tree_depth());
tree_size += t->tree_depth();
delete t;
// free current sets
// first un-assignate instances
for( unsigned i=0 ; i<tmp_learning_table->no_instances ; i++ ){tmp_learning_table->instances[i] = NULL;}
for( unsigned i=0 ; i<tmp_test_table->no_instances ; i++ ){tmp_test_table->instances[i] = NULL;}
tmp_learning_table->no_instances = 0;
tmp_test_table->no_instances = 0;
// then delete tmp tables
ba_partial_copy_delete(tmp_learning_table);
ba_partial_copy_delete(tmp_test_table);
printf("f at this packet %d\n",error);
}
fitness_value = (((float)error) / t1->no_instances)*100;// + (((float)tree_size)/k)
for( unsigned i=0 ; i<k ; i++ ){
ba_delete(k_tmp_tables[i]);
}
return fitness_value;
}
\end
\At the beginning of each generation function:
...
...
@@ -47,6 +151,7 @@ struct base* t1 = NULL;
struct base* t2 = NULL;
float* uniq_instances[2];
float* mutation_step;
unsigned uniq_cnt[2];
struct base* k_tables[K];
...
...
@@ -69,12 +174,11 @@ GenomeClass {
cout << "Seed : " << globalRandomGenerator->get_seed() << endl;
srand(globalRandomGenerator->get_seed());
t1 = ba_postgres_load_ilot(
1
);
t2 = ba_postgres_load_batiment(
1
);
t1 = ba_postgres_load_ilot(
4
);
t2 = ba_postgres_load_batiment(
4
);
ba_sort_instances(t1,0,0);
ba_set_links(t1,t2);
//ba_print_links(t1);
//printf("+ %d - %d\n",t1->class_repartition[1],t1->class_repartition[0]);
for( unsigned i=0 ; i<t1->hdr->attributes[t1->hdr->whichis_class]->no_values; i++ )
printf("%s : %d\n",t1->hdr->attributes[t1->hdr->whichis_class]->values[i],t1->class_repartition[i]);
...
...
@@ -107,6 +211,34 @@ GenomeClass {
#endif
//exit(-1);
// here we can compute the extremum of the annex table
float* mins = new float[t2->hdr->no_attributes-2];
float* maxs = new float[t2->hdr->no_attributes-2];
unsigned no_usefull_attributs = t2->hdr->no_attributes-2;
mutation_step = new float[no_usefull_attributs];
for( unsigned i=1 ; i<t2->hdr->no_attributes-1 ; i++ ){
mins[i-1] = INFINITY;
maxs[i-1] = -INFINITY;
for( unsigned j=0 ; j<t2->no_instances ; j++ ){
if( t2->instances[j][i] < mins[i-1] )
mins[i-1] = t2->instances[j][i];
if( t2->instances[j][i] > maxs[i-1] )
maxs[i-1] = t2->instances[j][i];
}
}
for( unsigned i=0 ; i< no_usefull_attributs ; i++ ){
mutation_step[i] = (maxs[i]-mins[i])/50;
printf("%d : M : %f m : %f ms %f\n",i,maxs[i],mins[i],mutation_step[i]);
}
delete mins;
delete maxs;
}
\end
...
...
@@ -146,6 +278,16 @@ GenomeClass {
printf(" error on the whole set : %d\n",error);
#endif
struct base* k_tables_f[10];
unsigned packets_size_f[10];
generate_k_fold(10,packets_size_f,t1,k_tables_f,t2);
//evaluation_fonction(10,
printf("validation on 10 folds %f\n",evaluation_fonction(10, best,k_tables_f,packets_size_f));
delete root;
ba_delete( tmp_table );
}
...
...
@@ -213,24 +355,10 @@ GenomeClass {
else{
float value;
if( __isinf(Genome.x[i+j]) ) Genome.x[i+j] = random(0,1000);
switch(j){
case 0:
value = random_gauss(Genome.x[i+j],100);
Genome.x[i+j] = roundf(value);
Genome.x[i+j] = ba_nearest_table_value(t2,j+1,value);
break;
case 1:
value = random_gauss(Genome.x[i+j],20);
Genome.x[i+j] = roundf(value);
Genome.x[i+j] = ba_nearest_table_value(t2,j+1,value);
break;
case 2:
value = random_gauss(Genome.x[i+j],10);
Genome.x[i+j] = roundf(value);
Genome.x[i+j] = ba_nearest_table_value(t2,j+1,value);
break;
}
//}
value = random_gauss(Genome.x[i+j],mutation_step[i]);
Genome.x[i+j] = roundf(value);
Genome.x[i+j] = ba_nearest_table_value(t2,j+1,value);
NbMut++;
}
}
...
...
@@ -359,14 +487,15 @@ GenomeClass {
\end
\User Makefile options:
LIBANTLR_DIR = ~/lib/libantlr3c-3.3-SNAPSHOT/
CXXFLAGS+=-I/home/maitre/sources/c4.5/include/ -fopenmp
LDFLAGS+= -lpq -lm -fopenmp ../c4.5_common/libc45.a
LDFLAGS+= -lpq -lm -fopenmp ../c4.5_common/libc45.a
$(LIBANTLR_DIR)/.libs/libantlr3c.a
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 200 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate
Population size :
1
00 //POP_SIZE
Population size :
2
00 //POP_SIZE
Offspring size : 100 // 40%
Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB
...
...
dev/c4.5_toy/card.ez
View file @
80aa1535
...
...
@@ -88,9 +88,9 @@ GenomeClass {
#if 1
// try the perfect solution
IndividualImpl* i = new IndividualImpl();
i->x[0] =
3
0;
i->x[1] =
39
;
i->x[GENE_SIZE-1] =
0
;
i->x[0] =
6
0;
i->x[1] =
60
;
i->x[GENE_SIZE-1] =
3
;
for( unsigned j=3 ; j<GENE_SIZE-1 ; j++ )
i->x[j] = INFINITY;
...
...
@@ -142,7 +142,7 @@ GenomeClass {
printf(" error on the whole set : %d\n",error);
#endif
ba_to_arff(tmp_table,"output_table.arff");
delete root;
ba_delete( tmp_table );
}
...
...
@@ -152,7 +152,7 @@ GenomeClass {
{
for( unsigned i=0; i<GENOME_SIZE ; i+=GENE_SIZE ) {
for( unsigned j=0 ; j<GENE_SIZE-1 ; j++ ){
Genome.x[i+j] = random(0,100);
Genome.x[i+j] =
t2->instances[random(0,t2->no_instances)][j+1]; //
random(0,100);
}
Genome.x[i+GENE_SIZE-1] = random(0,5);
}
...
...
@@ -162,7 +162,7 @@ GenomeClass {
\GenomeClass::crossover :
{
#if
0
#if
1
for (int i=0; i<GENOME_SIZE; i+=GENE_SIZE){
if( tossCoin(0.5) )
for( unsigned j=0 ; j<GENE_SIZE ; j++ )
...
...
@@ -339,8 +339,9 @@ GenomeClass {
\end
\User Makefile options:
LIBANTLR_DIR = ~/lib/libantlr3c-3.3-SNAPSHOT/
CXXFLAGS+=-I/home/maitre/sources/c4.5/include/ -fopenmp
LDFLAGS+= -lpq -lm -fopenmp ../c4.5_common/libc45.a
LDFLAGS+= -lpq -lm -fopenmp ../c4.5_common/libc45.a
$(LIBANTLR_DIR)/.libs/libantlr3c.a
\end
\Default run parameters : // Please let the parameters appear in this order
...
...
dev/c4.5_toy/run.sh
View file @
80aa1535
for
((
i
=
0
;
i<
1
;
i++
))
for
((
i
=
0
;
i<
20
;
i++
))
do
suf
=
`
date
+%s
`
echo
$suf
...
...
tpl/CUDA_GP.tpl
View file @
80aa1535
\TEMPLATE_START
#ifdef WIN32
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "libEasea.lib")
#pragma comment(lib, "libEasea.lib")
#endif
/**
This is program entry for TreeGP template for EASEA
...
...
@@ -84,7 +84,10 @@ int main(int argc, char** argv){
#include "CIndividual.h"
#include "CCuda.h"
#include "CGPNode.h"
#include
<iostream>
#include
<sstream>
unsigned aborded_crossover;
float* input_k;
float* output_k;
int* indexes_k;
...
...
@@ -95,7 +98,7 @@ int* hits_k;
using namespace std;
#include "EASEAIndividual.hpp"
bool INSTEAD_EVAL_STEP =
fals
e;
bool INSTEAD_EVAL_STEP =
tru
e;
int fitnessCasesSetLength;
...
...
@@ -112,6 +115,8 @@ extern CEvolutionaryAlgorithm* EA;
#define CUDA_GP_TPL
#define GROW_FULL_RATIO 0.5
struct gpu_argument* t_args;
unsigned evaluation_threads_status;
#define NUMTHREAD2 128
#define MAX_STACK 50
...
...
@@ -125,10 +130,10 @@ extern CEvolutionaryAlgorithm* EA;
/* Insert declarations about opcodes*/
\INSERT_GP_OPCODE_DECL
float recEval
eDrone
(GPNode* root, float* input) {
float recEval(GPNode* root, float* input) {
float OP1=0, OP2= 0, RESULT = 0;
if( opArity[root->opCode]>=1) OP1 = recEval
eDrone
(root->children[0],input);
if( opArity[root->opCode]>=2) OP2 = recEval
eDrone
(root->children[1],input);
if( opArity[root->opCode]>=1) OP1 = recEval(root->children[0],input);
if( opArity[root->opCode]>=2) OP2 = recEval(root->children[1],input);
switch( root->opCode ){
\INSERT_GP_CPU_SWITCH
default:
...
...
@@ -160,11 +165,29 @@ __device__ float eval_tree_gpu(unsigned fc_id, const float * k_progs, const floa
}
int flattening_tree_rpn( GPNode* root, float* buf, int* index){
int i;
for( i=0 ; i
<opArity
[(
int
)
root-
>
opCode] ; i++ ){
flattening_tree_rpn(root->children[i],buf,index);
}
if( (*index)+2>MAX_PROGS_SIZE )return 0;
buf[(*index)++] = root->opCode;
if( root->opCode == OP_ERC ) buf[(*index)++] = root->erc_value;
return 1;
}
/**
Send input and output data on the GPU memory.
Allocate
*/
void initialDataToGPU(float* input_f, int length_input, float* output_f, int length_output){
// allocate and copy input/output arrays
CUDA_SAFE_CALL(cudaMalloc((void**)(
&input_k),sizeof(float)*length_input));
CUDA_SAFE_CALL(cudaMalloc((void**)(
&output_k),sizeof(float)*length_output));
...
...
@@ -177,10 +200,12 @@ void initialDataToGPU(float* input_f, int length_input, float* output_f, int len
CUDA_SAFE_CALL( cudaMalloc((void**)
&progs_k,sizeof(*progs_k)*MAX_PROGS_SIZE));
// allocate hits and results arrays
CUDA_SAFE_CALL(cudaMalloc((void**)
&results_k,sizeof(*
indexe
s_k)*maxPopSize));
CUDA_SAFE_CALL(cudaMalloc((void**)
&hits_k,sizeof(*
indexe
s_k)*maxPopSize));
CUDA_SAFE_CALL(cudaMalloc((void**)
&results_k,sizeof(*
result
s_k)*maxPopSize));
CUDA_SAFE_CALL(cudaMalloc((void**)
&hits_k,sizeof(*
hit
s_k)*maxPopSize));
}
/**
Free gpu memory from the input and ouput arrays.
*/
...
...
@@ -193,12 +218,6 @@ void free_gpu(){
}
__global__
static
void
EvaluatePostFixIndividuals_128
(
const
float
*
k_progs
,
const
int
maxprogssize
,
...
...
@@ -222,7 +241,6 @@ EvaluatePostFixIndividuals_128(const float * k_progs,
float
sum =
0.0;
int
hits =
0
;
//
hits
number
float
currentOutput
;
float
ERROR
;
index =
bid;
//
one
program
per
block =
>
block
ID =
program
number
...
...
@@ -249,10 +267,10 @@ EvaluatePostFixIndividuals_128(const float * k_progs,
// are we on a busy thread?
if (i*NUMTHREAD2+tid >= trainingSetSize) // no!
continue;
currentOutput = outputs[i*NUMTHREAD2+tid];
float EVOLVED_VALUE = eval_tree_gpu(i, k_progs+k_indexes[index], k_inputs+(i*NUMTHREAD2+tid));
\INSERT_GENOME_EVAL_BDY
\INSERT_GENOME_EVAL_BDY_GPU
if (!(ERROR
<
BIG_NUMBER
))
...
...
@@ -279,26 +297,12 @@ EvaluatePostFixIndividuals_128(const float * k_progs,
}
ERROR =
tmpresult[0];
\
INSERT_GENOME_EVAL_FTR_GPU
k_results[index] =
sqrtf(tmpresult[0]/512);
k_hits[index] =
tmphits[0];
}
//
here
results
and
hits
have
been
stored
in
their
respective
array:
we
can
leave
}
int
flattening_tree_rpn
(
GPNode*
root
,
float*
buf
,
int*
index
){
int
i
;
for
(
i=
0
;
i
<
opArity
[(
int
)
root-
>
opCode] ; i++ ){
flattening_tree_rpn(root->children[i],buf,index);
}
if( (*index)+2>MAX_PROGS_SIZE )return 0;
buf[(*index)++] = root->opCode;
if( root->opCode == OP_ERC ) buf[(*index)++] = root->erc_value;
return 1;
}
GPNode*
pickNthNode
(
GPNode*
root
,
int
N
,
int*
childId
){
GPNode*
stack
[
TREE_DEPTH_MAX*MAX_ARITY
];
...
...
@@ -335,13 +339,14 @@ GPNode* pickNthNode(GPNode* root, int N, int* childId){
}
void simple_mutator(IndividualImpl* Genome){
// Cassical mutation
// select a node
int mutationPointChildId = 0;
int mutationPointDepth = 0;
//toDotFile( Genome.root[tree], "out/mutation/p", tree);
GPNode* mutationPointParent = selectNode(Genome->root,
&
mutationPointChildId,
&mutationPointDepth);
...
...
@@ -350,12 +355,62 @@ void simple_mutator(IndividualImpl* Genome){
mutationPointDepth = 0;
}
delete mutationPointParent->children[mutationPointChildId] ;
mutationPointParent->children[mutationPointChildId] = NULL;
mutationPointParent->children[mutationPointChildId] =
construction_method( VAR_LEN+1, OPCODE_SIZE , 1, TREE_DEPTH_MAX-mutationPointDepth ,0,opArity,OP_ERC);
}
/**
This function handles printing of tree.
Every node is identify by its address, in memory,
and labeled by the actual opCode.
On our architecture (64bits, ubuntu 8.04 and gcc-4.3.2)
the long int variable is sufficient to store the address
without any warning.
*/
void toDotFile_r(GPNode* root, FILE* outputFile){
if( root->opCode==OP_ERC )
fprintf(outputFile," %ld [label=\"%s : %f\"];\n", (long int)root, opCodeName[(int)root->opCode],
root->erc_value);
else