Skip to content

Latest commit

 

History

History
78 lines (63 loc) · 2.33 KB

2.8 GPModel.md

File metadata and controls

78 lines (63 loc) · 2.33 KB

Introduction

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.

options

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.

Quickstart

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);

Constructor

No argument is required.

Execution

See the introduction in GAModel.

Public Methods (specific to GPModel)

Signature Description
init(model, template, maxHeight) Initialize every individual in the population.
pseudocode(model, index) Print a parse tree in the model in pseudocode.

init(model, template, maxHeight)

Initialize every parse tree in the model.

Arguments

Argument Description
template A Template instance, which specifies how the parse tree is grown.
maxHeight The maximum height allowed for the parse tree.

pseudocode(model, index)

Print a parse tree in the model in pseudocode.

Arguments

Argument Description
index The sorted index of the GPMember. 1 is the best performing GPMember.

License

This project, including the documentation, is licensed under the MIT license. Copyright (c) 2022 Bohui WU.