Node contents
All representation by trees starts here. These Structs are used as content of the nodes of the tree (and not as direct nodes).
Types
GP_NLS.Const — TypeStruct to be the content of an terminal node of an expression tree. This struct represents a Float64 constant value.
Const(v::Float64)Receives a Float64 value v which will be used as a constant.
The representation of the constant as string is obtained by rounding the value to 3 decimal places, and it is automatically obtained.
When using non-linear optimization, the nonlinear least squares optimization method looks for this struct specifically to optimize their values.
GP_NLS.ERC — TypeStruct to be the content of an terminal node of an expression tree. This struct keeps the range limits for creating a random constant with the ERC method.
ERC(lb::Float64, ub::Float64)This struct is used to create constants in the terminal nodes. When it is selected to be a terminal, a new terminal will be created with the struct Const with a random value drawn between [lb, ub) to take the place of the ERC (Ephemeral Random Constant) at the terminal node. The string representation of the created constant is as described in Const documentation.
GP_NLS.Func — TypeStruct to be the content of an internal node of an expression tree.
Func(f::Function, a::Int64)Takes a function f and the arity a of the function. The function must always work in vectorized form (will always receive $a$ arrays with $n$ values, where each value of the array is an observation). So the function input will have a rows and n columns when this node is being evaluated in other methods.
The function's representation as a string is inferred from the name of the function passed, and when this node is used to create a node of a tree, it will have $a$ children.
Optionally, you can give a name to the function by using the 3 parameters constructor:
Func(f::Function, a::Int64, str_rep::String)When creating new functions, protected operators must not be used. The non-linear optimization method uses autodiff to differentiate the tree, and complex functions can be problematic to automatically differentiate.
GP_NLS.Var — TypeStruct to be the content of a terminal node of an expression tree. This struct represents a variable of the data set.
Var(v::String, i::Int64)Receives a string v that will be used as the representation of the variable when printing the expression (you can use a placeholder if the database do not have column names) and a ì index that matches the column index of the corresponding variable in the observations.
GP_NLS.WeightedVar — TypeStruct to be the content of a terminal node of an expression tree. This struct represents a weighted variable, that have a coefficient associated with it at the time of creation.
WeightedVar(v::String, i::Int64)This struct represents a weighted variable, that can be adjusted with the non-linear least squares method.
The String representation is inferred as the same way when creating a $Var$ and the coefficient is inferred in the same way as a $Const$.
WeightedVar(v::String, i::Int64, w::Float64)Additionally, you can force a specific coefficient by passing the value as the third argument on the constructor. When no value is specified, the coefficient is set to 1.0.
This weighted variable is a subtree with 3 nodes and depth 2, but in practice it is treated as a single node, as it is not of interest to make the dissociation between the weight and the variable during the GP process. By treating the weighted variable as a single node, it is not necessary to modify the crossover or mutation implementations to prevent changing the subtree.