GP Tools

compile_tree(expr, prim_set)

Evaluates the expression on the given primitive set.

Parameters
  • expr (Expression) – The expression to compile. It can be a string, a PrimitiveTree or any object which produces a valid Python expression when converted into a string.

  • prim_set (PrimitiveSetTyped) – The primitive set to evaluate the expression on.

Returns

A callable if the ‘p_set’ has 1 or more arguments, otherwise the result of the evaluation.

Return type

Any

compile_adf_tree(expr, prim_sets)

Compiles the expression represented by a list of trees. The first element of the list is the main tree, and the following elements are automatically defined functions that can be called by the first tree.

Parameters
  • expr (Expression) – The expression to compile. It can be a string, a PrimitiveTree or any object which produces a valid Python expression when converted into a string.

  • prim_sets (PrimSets) – List of primitive sets. The first element is the main tree and the others are automatically defined functions (ADF) that can be called by the first tree. The last element is associated with the ‘expr’ and should contain a reference to the preceding ADFs.

Returns

A callable if the main primitive set has 1 or more arguments, otherwise the result of the evaluation.

Return type

Any

build_tree_graph(expr)

Builds a graph representation of the given expression. The graph is a tuple of three elements: a list of nodes, a list of edges and a dictionary of node labels. The nodes are the leaves of the tree and the edges are the connections between the nodes. The dictionary contains the leaves values, where the keys are the leaves indices.

Parameters

expr (Expression) – A tree expression to convert into a graph.

Returns

A list of nodes, a list of edges and a dictionary of labels.

Return type

Graph

static_limit(limiter, max_value)

Provides a decorator to limit the production of offspring. It may be used to decorate both crossover and mutation operators. When an invalid child is generated, it is replaced by one of its parents, which is randomly selected.

Parameters
  • limiter (Callable) – The function which obtains the measurement from an individual.

  • max_value (Union[int, float]) – The maximum value allowed for the given measurement.

Returns

A decorator which can be applied to a GP operator in a Toolbox.

Return type

Callable