Différences entre les versions de « Environmental modeling and software paper supplementary material »
(Page créée avec « /*_________________________________________________________ This is a standard GP implementation on EASEA, aimed for regression. For running on CPU, compile w... ») |
|||
Ligne 184 : | Ligne 184 : | ||
Plot stats:true | Plot stats:true | ||
− | Remote island model: | + | Remote island model: false |
IP file: ip.txt //File containing all the remote island's IP | IP file: ip.txt //File containing all the remote island's IP | ||
Server port : 2929 | Server port : 2929 |
Version du 3 février 2024 à 15:55
/*_________________________________________________________
This is a standard GP implementation on EASEA, aimed for regression.
For running on CPU, compile with: $ make easeaclean ; easena -gp regression.ez ; make
Then run with: $ ./regression --seed 2 // for a nice result :-)
You can test the parallel version on several cores with: $ ./regression --seed 2 --nbCPUThreads 20
For running on GPU, compile with: $ make easeaclean ; easena -cuda_gp regression.ez ; make
__________________________________________________________*/
\User declarations :
- include<stdio.h>
- include<string.h>
// these 3 defines are mandatory here. Adjust as you like.
- define NO_FITNESS_CASES 18
- define VAR_LEN 1 // number of input variables
- define GROW_FULL_RATIO 0.5 // cf. Koza's book on Genetic Programming
- define NUMTHREAD 1024 // nb of threads in parallel on GPU cards.
// 1024 is the maximum on Fermi architectures. It is 512 on older cards
- define MAX_STACK 15
- define PI (3.141592653589793)
float x[NO_FITNESS_CASES] = {0.0833, 0.1667, 0.25, 0.3333, 0.4167, 0.5, 0.5833, 0.6667, 0.75, 0.8333, 0.9167, 1, 1.0833, 1.1667, 1.25, 1.3333, 1.4167, 1.5};
float y[NO_FITNESS_CASES] = { -0.457142857, -0.428571429, -0.285714286, -0.042857143, 0.142857143, 0.328571429, 0.457142857, 0.571428571, 0.742857143, 0.914285714, 1.128571429, 1.271428571, 1.171428571, 0.985714286, 0.714285714, 0.442857143, 0.2, 0.057142857};
\end
\User functions:
int initData(float*** inputs, float** outputs) {
int i=0; (*inputs) = new float*[NO_FITNESS_CASES]; (*outputs) = new float[NO_FITNESS_CASES]; for( i=0 ; i<NO_FITNESS_CASES ; i++ ){ (*inputs)[i]=new float[VAR_LEN]; (*inputs)[i][0] = x[i]; (*outputs)[i] = y[i]; }
return NO_FITNESS_CASES;
}
void free_data(){
for( int i=0 ; i<NO_FITNESS_CASES ;i++ ) delete[] inputs[i] ; delete[] outputs; delete[] inputs;
}
\end
\Before everything else function:
initData(&inputs,&outputs); // inputs, outputs requis par EASEA
\end
\After everything else function:
std::cout << "y=" << toString(((IndividualImpl*)EA->population->Best)->root) << std::endl; free_data();
\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 {
GPNode* root; // GPNode is a reserved name that must be used for GP
} \end
\GenomeClass::display: \end
\GenomeClass::initialiser :
Genome.root = ramped_hh(); // Initializer, cf. Koza GP
\end
\GenomeClass::crossover :
simpleCrossOver(parent1,parent2,child); // cf. Koza GP child.valid = false; // to force the evaluation of the child
\end
\GenomeClass::mutator :
simple_mutator(&Genome); // cf. Koza GP
\end
\begin operator description : // <symbole>, "<affichage dans l'arbre>", <arité de l'opérateur>, {RESULT=<resultat>}
OP_X, "x", 0, {RESULT=INPUT[0];};
OP_ERC, "ERC", 0, {RESULT=ERC;}; // ERC = valeur aléatoire entre 0 et 1
OP_ADD, "+", 2, {RESULT=OP1+OP2;};
OP_SUB, "-", 2, {RESULT=OP1-OP2;};
OP_MUL, "*", 2, {RESULT=OP1*OP2;};
OP_SIN, "sin", 1, {RESULT=sin(OP1);};
// you can add other operators if you wish \end
\GenomeClass::evaluator header: \end
\GenomeClass::evaluator for each fc : // How to compute error for one point float expected_value = OUTPUT; error = pow((expected_value-EVOLVED_VALUE),2); error/=(float)NO_FITNESS_CASES; error=sqrtf(error); \end
\GenomeClass::evaluator accumulator : // here, error is the sum of errors for each point
return error; \end
\User Makefile options:
CXXFLAGS+=-I/usr/local/cuda/common/inc/ -I/usr/local/cuda/include/
LDFLAGS+=
\end
\Default run parameters :
Number of generations : 500 // NB_GEN Time limit: 0 // In seconds, 0 to deactivate Population size : 50000 // POP_SIZE Offspring size : 50000 // can be a percentage such as 40% Mutation probability : 0.1 // Probability to call the mutation function Crossover probability : 1 // Probability to call the crossover function Evaluator goal : minimise // or Maximise Selection operator: Tournament 10 // to select parents Surviving parents: 100% // to select breeders Surviving offspring: 100% // to select among offspring for next generation Reduce parents operator: Tournament 2 // how to select the breeders Reduce offspring operator: Tournament 2 // how to select the offspring that will compete to access the next generation Final reduce operator: Tournament 2 // to select the individuals composing the next generation
Elitism: Strong // Strong = from parents pop, Weak = from parents + children Elite: 1 Print stats: true Generate csv stats file:false Generate gnuplot script:false Generate R script:false Plot stats:true
Remote island model: false IP file: ip.txt //File containing all the remote island's IP Server port : 2929 Migration probability: 0.33
Save population: false Start from file: false
// nouveaux paramètres max init tree depth : 4 min init tree depth : 2 max tree depth : 6
size of prog buffer : 200000000
\end