Main function - gpols_mainloop.m

Syntax:

[newpopu,evnum] = gpols_mainloop(popu,X,Y,Q,opt);

This function execute one evolutionary-loop and generates the next generation of population.

The user should call this function iteratively.

The popu is the population variable, which contains the individuals of current generation.

The X, Y, and Q are the regression matrix, output vector and weighting vector, respectively (see gpols_evaluation).

The opt contains the options:

opt(1): ggap, generation gap (0-1)

opt(2): pc, probability of crossover (0-1)

opt(3): pm, probability of mutation (0-1)

opt(4): sels, selection mode (0: roulette wheel, 1: total random, 2,3,..: tournament selection (with tournament size = sels)

opt(5): rmode, mode of tree-recombination (1 or 2)

opt(6): a1, first penalty parameter (default = 0)

opt(7): a2, second penalty parameter (default = 0)

opt(8): OLS threshold value (default = 0)

opt(9): if 1: polynomial evaluation, else normal evaluation (default = 0)

opt(10): if 1: always evaluate all individuals, else evaluate only new individuals (default = 0)

Example:

%Regression matrix

ndata = 100;

nvar = 3;

X = rand(ndata,nvar);

%Output vector (y = 10*x1*x2+5*x3)

Y = 10*X(:,1).*X(:,2) + 5*X(:,3);

Y = Y + randn(size(Y))*0.01; %some 'measurement' noise

%GP equation symbols

symbols{1} = {'+','*'};

symbols{2} = {'x1','x2','x3'}; %length(symbols{2}) = size(X,2) !

%Initial population

popusize = 40;

maxtreedepth = 5;

popu = gpols_init(popusize,maxtreedepth,symbols);

%First evaluation

opt = [0.8 0.7 0.3 2 1 0.2 30 0.05 0 0];

popu = gpols_evaluate(popu,[1:popusize],X,Y,[],opt(6:9));

%info

disp(gpols_result([],0));

disp(gpols_result(popu,1));

%GP loops

for c = 2:20,

%iterate

popu = gpols_mainloop(popu,X,Y,[],opt);

%info

disp(gpols_result(popu,1));

end

%Result

[s,tree] = gpols_result(popu,2);

disp(s);