-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpdemo2_config.m
139 lines (97 loc) · 5.44 KB
/
gpdemo2_config.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
function [gp]=gpdemo2_config(gp);
%REGRESSMULTI GPTIPS configuration file demonstrating multiple gene symbolic
%regression on data (y) generated from a non-linear function of 4 inputs (x1, x2, x3, x4).
%
% [GP]=GPDEMO2_CONFIG(GP) returns a parameter structure GP containing the settings
% for GPDEMO2 (multigene symbolic regression using genetic programming).
%
% Remarks:
% There is one output y which is a non-linear
% function of the four inputs y=exp(2*x1*sin(pi*x4)) + sin(x2*x3).
% The objective of a GP run is to evolve a multiple gene symbolic
% function of x1, x2, x3 and x4 that closely approximates y.
%
% This function was described by:
% Cherkassky, V., Gehring, D., Mulier F, Comparison of adaptive methods for function
% estimation from samples, IEEE Transactions on Neural Networks, 7 (4), pp. 969-
% 984, 1996. (Function 10 in Appendix 1)
%
% Example:
% [GP]=RUNGP('gpdemo2_config') uses this configuration file to perform symbolic
% regression with multiple gene individuals on the data from the above function.
%
% (C) Dominic Searson 2009
%
% v1.0
%
% See also: GPDEMO2, GPDEMO3_CONFIG, GPDEMO4, GPDEM03, GPDEMO1, REGRESSMULTI_FITFUN
% Main run control parameters
% --------------------------
gp.runcontrol.pop_size=100; % Population size
gp.runcontrol.num_gen=100; % Number of generations to run for including generation zero
% (i.e. if set to 100, it'll finish after generation 99).
gp.runcontrol.verbose=10; % Set to n to display run information to screen every n generations
% Selection method options
% -------------------------
gp.selection.method='tour'; % Only tournament selection is currently supported.
gp.selection.tournament.size=3;
gp.selection.tournament.lex_pressure=true; % True to use Luke and Panait's plain lexicographic tournament selection
% Fitness function specification
% -------------------------------
gp.fitness.fitfun=@regressmulti_fitfun; % Function handle of the fitness function (filename with no .m extension).
gp.fitness.minimisation=true; % Set to true if you want to minimise the fitness function (if false it is maximised).
gp.fitness.terminate=true;
gp.fitness.terminate_value=0.01;
% Set up user data
% ----------------
%load in the raw x and y data
load demo2data
gp.userdata.xtrain=x(101:500,:); %training set (inputs)
gp.userdata.ytrain=y(101:500,1); %training set (output)
gp.userdata.xtest=x(1:100,:); %testing set (inputs)
gp.userdata.ytest=y(1:100,1); %testing set (output)
% Input configuration
% -------------------
gp.nodes.inputs.num_inp=size(gp.userdata.xtrain,2); % This sets the number of inputs (i.e. the size of the terminal set NOT including constants)
% Tree build options
% ----------------------
gp.treedef.max_depth=5; % Maximum depth of trees
% Multiple gene settings
% ----------------------
gp.genes.multigene=true; % True=use multigene individuals False=use ordinary single gene individuals.
gp.genes.max_genes=2; % The absolute maximum number of genes allowed in an individual.
% Define functions
% ----------------
% (Below are some definitions of functions that have been used for symbolic regression problems)
% Function name (must be an mfile or builtin function on the path).
gp.nodes.functions.name{1}='times' ;
gp.nodes.functions.name{2}='minus' ;
gp.nodes.functions.name{3}='plus' ;
gp.nodes.functions.name{4}='rdivide' ; % unprotected divide
gp.nodes.functions.name{5}='psqroot' ; % protected sqrt
gp.nodes.functions.name{6}='plog' ; % protected natural log
gp.nodes.functions.name{7}='square' ; % .^2 square
gp.nodes.functions.name{8}='tanh' ; % tanh function
gp.nodes.functions.name{9}='pdivide' ; % protected divide function
gp.nodes.functions.name{10}='iflte' ; % IF-THEN-ELSE function
gp.nodes.functions.name{11}='sin' ;
gp.nodes.functions.name{12}='cos' ;
gp.nodes.functions.name{13}='exp' ;
% Active functions
% ----------------
%
% Manually setting a function node to inactive allows you to exclude a function node in a
% particular run.
gp.nodes.functions.active(1)=1;
gp.nodes.functions.active(2)=1;
gp.nodes.functions.active(3)=1;
gp.nodes.functions.active(4)=0;
gp.nodes.functions.active(5)=0;
gp.nodes.functions.active(6)=0;
gp.nodes.functions.active(7)=0;
gp.nodes.functions.active(8)=0;
gp.nodes.functions.active(9)=0;
gp.nodes.functions.active(10)=0;
gp.nodes.functions.active(11)=0;
gp.nodes.functions.active(12)=0;
gp.nodes.functions.active(13)=0;