GP Primitives
- class Terminal(terminal, symbolic, ret_type)
Class that encapsulates a terminal primitive in an expression. Terminals can be either values or 0-arity functions.
- Parameters
terminal (TerminalTypes) – The terminal value or function.
symbolic (bool) – If True, the terminal is a string.
ret_type (type) – The return type of the terminal.
- class Ephemeral
Class that encapsulates a terminal which value is set when the object is created. This is an abstract base class. When subclassing, a staticmethod named ‘func’ must be defined.
- class Primitive(name, args, ret_type)
Class that encapsulates a primitive and when called with arguments it returns the Python code to call the primitive with the arguments.
- class PrimitiveTree(content)
Tree specifically formatted for the optimization of genetic programming operations. This class is a subclass of ‘list’, where the nodes are appended, or are assumed to have been appended, when creating an object of this class with a list of primitives and terminals. The nodes appended to the tree are required to have the ‘arity’ attribute, which defines the arity of the primitive.
- Parameters
content (Iterable) – List of primitives and terminals to be added to the tree.
- classmethod from_string(string, prim_set)
Converts a string expression into a PrimitiveTree given a PrimitiveSet p_set. The primitive set needs to contain every primitive present in the expression.
- Parameters
string (str) – String representation of a Python expression.
prim_set (PrimitiveSetTyped) – Primitive set from which primitives are selected.
- Returns
PrimitiveTree populated with the deserialized primitives.
- Return type
- search_subtree(begin)
Returns a slice object that corresponds to the range of values that defines the subtree which has the element with index ‘begin’ as its root.
- property height
The height of the tree or the depth of the deepest node.
- property root
The root of the tree (element 0 in the list).
- class PrimitiveSet(name, arity, prefix='ARG')
Subclass of ‘PrimitiveSetTyped’ without the type definition.
- Parameters
- add_primitive(primitive, arity, name=None, *_, **__)
Adds a primitive to the set.
- add_terminal(terminal, name=None, *_, **__)
Adds a terminal to the set.
- add_ephemeral_constant(name, ephemeral, *_, **__)
Adds an ephemeral constant to the set. An ephemeral constant is a function without arguments that returns a random value. The value is immutable, but unique for each Tree.
- class PrimitiveSetTyped(name, in_types, ret_type, prefix='ARG')
Class that contains the primitives which can be used to solve a Strongly Typed GP problem.
- Parameters
- add_primitive(primitive, in_types, ret_type, name=None)
Adds a primitive to the set.
- add_terminal(terminal, ret_type, name=None)
Adds a terminal to the set.
- add_ephemeral_constant(name, ephemeral, ret_type)
Adds an ephemeral constant to the set. An ephemeral constant is a function without arguments that returns a random value. The value is immutable, but unique for each Tree.
- add_adf(prim_set)
Adds an Automatically Defined Function (ADF) to the set.
- Parameters
prim_set (PrimitiveSetTyped) – PrimitiveSetTyped instance containing the primitives with which the ADF can be built.
- Returns
Nothing.
- Return type
None
- rename_arguments(**kwargs)
Renames the arguments in self with new names from kwargs.
- Parameters
kwargs – Dictionary of new names for the arguments.
- Returns
Nothing.
- Return type
None
- property terminal_ratio
The ratio between the quantity of terminals and the quantity of all the other kinds of primitives.