Auxiliary functions
Implementation of some auxiliary functions that are used to inspect and manipulate trees more generally.
Functions
GP_NLS.depth — MethodFunction that takes any node of a tree (AbstractNode) and recursively finds the depth of the tree, where the depth is the size of its largest branch. This depth function does not take into count the coefficients of weighted variables (which are, in fact, a subtree with depth 2). To find the depth of a tree considering weighted variables as a subtree (and not as a single node), use the function true_depth.
depth(node::AbstractNode)::Int64This function works by having a multiple dispatch for each subtype of AbstractNode.
GP_NLS.getstring — MethodFunction that takes any node of a tree (AbstractNode) and recursively builds a string representation of the tree. When creating the string representation for a function, if it is unary, then the string will be created with $node.func.str_rep(child)$, otherwise it will be created as: $(child1.str_rep node.func.str_rep child2.str_rep node.func.str_rep ...)$ (intercalating the children string representations with the function string representation).
getstring(node::AbstractNode)::StringThis function works by having a multiple dispatch for each subtype of AbstractNode.
GP_NLS.numberofnodes — MethodFunction that takes any node of a tree (AbstractNode) and recursively counts the total number of nodes of the tree. This function counts weighted variables as a single node. To find the number of nodes of a tree considering weighted variables as a subtree (and not as a single node), use the function true_numberofnodes.
numberofnodes(node::AbstractNode)::Int64This function works by having a multiple dispatch for each subtype of AbstractNode.
GP_NLS.true_depth — MethodFunction that takes any node of a tree (AbstractNode) and recursively finds the depth of the tree, where the depth is the size of its largest branch. This depth function returns a value that corresponds to the number of existing nodes in the tree, considering weighted variables as being a subtree of depth 2. This function is not used in implementations, and is available to users who want to get the real depth of GP-NLS trees.
true_depth(node::AbstractNode)::Int64This function works by having a multiple dispatch for each subtype of AbstractNode.
GP_NLS.true_numberofnodes — MethodFunction that takes any node of a tree (AbstractNode) and recursively counts the total number of nodes of the tree. This function counts weighted variables as three nodes. This function is only used in mutate, crossover, and initialize operations to avoid creating trees larger than the allowed.
true_numberofnodes(node::AbstractNode)::Int64This function works by having a multiple dispatch for each subtype of AbstractNode.