GAModel is an abstract class that implements the genetic algorithm. Developers only need extend the class to implement init, beforeRun, forEachGeneration, and the afterRun method.
A struct containing options about the model. Other than the options in GAModel, in GPModel, you can also specify the following parameters.
| Option | Description |
|---|---|
maxHeight |
The maximum height allowed for a tree. |
mutationProb |
The probability of mutating a node. |
terminalMutationProb |
The probability of mutating a terminal node. |
Here is an example of how to set up and optimize a model.
% Define the template
template = Template();
...
% Define the parameters for GP
opt.populationSize = 25;
opt.maxHeight = 6;
opt.generations = 20;
opt.selectionSchema = 'tournament';
opt.tournamentSize = 3;
opt.eliteSize = 8;
opt.crossoverFraction = 0.8;
opt.mutateAfterCrossover = true;
opt.reevaluateElites = false;
opt.mutationProb = 0.05;
opt.terminalMutationProb = 0.15;
% Instantiate the GP model
myGPModel = MyGPModel();
% Register the options
myGPModel.register(opt);
% Populate the GPModel with individuals
% GPModel's `populate` will call the constructor specified
myGPModel.populate();
% Initialize every individual in the population
myGPModel.init(template, opt.maxHeight);
% Optimize the model using genetic algorithm
myGPModel.run(trainingSet);No argument is required.
See the introduction in GAModel.
| Signature | Description |
|---|---|
init(model, template, maxHeight) |
Initialize every individual in the population. |
pseudocode(model, index) |
Print a parse tree in the model in pseudocode. |
Initialize every parse tree in the model.
| Argument | Description |
|---|---|
template |
A Template instance, which specifies how the parse tree is grown. |
maxHeight |
The maximum height allowed for the parse tree. |
Print a parse tree in the model in pseudocode.
| Argument | Description |
|---|---|
index |
The sorted index of the GPMember. 1 is the best performing GPMember. |
This project, including the documentation, is licensed under the MIT license. Copyright (c) 2022 Bohui WU.