Nodes

Abstract Nodes

class cgp.node.Node(idx: int, addresses: List[int])[source]

Bases: object

Base class for input/output and hidden nodes.

activate() → None[source]

Set node to active.

property addresses
property arity
format_output_str(graph: CartesianGraph) → None[source]

Format output string of the node.

format_output_str_numpy(graph)[source]

Format output string for NumPy representation.

format_output_str_sympy(graph)[source]

Format output string for SymPy representation.

format_output_str_torch(graph)[source]

Format output string for PyTorch representation.

property idx
property max_arity
property output
property output_str
pretty_str(n: int) → str[source]
class cgp.node.OperatorNode(idx: int, addresses: List[int])[source]

Bases: cgp.node.Node

Base class of hidden nodes.

Subclasses provide the atomic operations of the computational graph.

format_output_str(graph: CartesianGraph) → None[source]

Format output string of the node.

format_output_str_numpy(graph: CartesianGraph) → None[source]

Format output string for NumPy representation.

format_output_str_sympy(graph: CartesianGraph) → None[source]

Format output string for SymPy representation.

format_output_str_torch(graph: CartesianGraph) → None[source]

Format output string for PyTorch representation.

format_parameter_str() → None[source]
classmethod initial_value(parameter_name: str) → float[source]
property parameter_str
cgp.node.register(cls: Type[Node]) → None[source]

Register a primitive in the global dictionary of primitives

clsType[Node]

Primitive to be registered.

None

Input/Output Nodes

class cgp.node_input_output.InputNode(idx: int, input_nodes: List[int])[source]

Bases: cgp.node.Node

An input node of the computational graph.

format_output_str(graph: CartesianGraph) → None[source]

Format output string of the node.

format_output_str_numpy(graph: CartesianGraph) → None[source]

Format output string for NumPy representation.

format_output_str_sympy(graph: CartesianGraph) → None[source]

Format output string for SymPy representation.

format_output_str_torch(graph: CartesianGraph) → None[source]

Format output string for PyTorch representation.

class cgp.node_input_output.OutputNode(idx: int, input_nodes: List[int])[source]

Bases: cgp.node.Node

An output node of the computational graph.

format_output_str(graph: CartesianGraph) → None[source]

Format output string of the node.

format_output_str_numpy(graph: CartesianGraph) → None[source]

Format output string for NumPy representation.

format_output_str_sympy(graph: CartesianGraph) → None[source]

Format output string for SymPy representation.

format_output_str_torch(graph: CartesianGraph) → None[source]

Format output string for PyTorch representation.

Operator Nodes

class cgp.node_impl.Add(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that adds its two inputs.

class cgp.node_impl.ConstantFloat(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node with a constant output.

class cgp.node_impl.Div(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that devides its first by its second input.

class cgp.node_impl.IfElse(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that outputs the value of its second input if its first input is non-negative, and the value of its third input otherwise.

class cgp.node_impl.Mul(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that multiplies its two inputs.

class cgp.node_impl.Parameter(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that provides a parametrized constant output.

The value of the parameter can be adapted via local search and is passed on from parents to their offspring.

class cgp.node_impl.Pow(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that raises its first to the power of its second input.

class cgp.node_impl.Sub(idx: int, addresses: List[int])[source]

Bases: cgp.node.OperatorNode

A node that substracts its second from its first input.