-
Notifications
You must be signed in to change notification settings - Fork 11
/
tree2evalstr.m
30 lines (28 loc) · 1.26 KB
/
tree2evalstr.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
function decodedArray = tree2evalstr(encodedArray,gp)
%TREE2EVALSTR Converts encoded tree expressions into math expressions that MATLAB can evaluate directly.
%
% DECODEDARRAY = TREE2EVALSTR(ENCODEDARRAY,GP) processes the encoded
% symbolic expressions in the cell array ENCODEDARRAY using the
% information in the GP data structure and creates a cell array
% DECODEDARRAY, each element of which is an evaluable Matlab string
% expression.
%
% Remarks:
%
% GPTIPS uses a encoded string representation of expressions which is not
% very human readable, but is fairly compact and makes events like
% crossover and mutation easier to handle. An example of such an
% expression is a(b(x1,a(x4,x3)),c(x2,x1)). Before an expression can be
% evaluated it is converted using TREE2EVALSTR to produce an evaluable
% math expression, e.g. times(minus(x1,times(x4,x3)),plus(x2,x1)).
%
% Copyright (c) 2009-2015 Dominic Searson
%
% GPTIPS 2
%
% See also EVALFITNESS, TREEGEN, GPREFORMAT
%loop through active function list and replace with function names
for j=1:gp.nodes.functions.num_active
encodedArray = strrep(encodedArray,gp.nodes.functions.afid(j),gp.nodes.functions.active_name_UC{j});
end
decodedArray = lower(encodedArray);