pyneat.graph_utils module

Utility functions for various graph operations.

pyneat.graph_utils.creates_cycle(connections, test)[source]

Checks to see if adding the test connection to the network would create a cycle.

Parameters:
  • connections (list) – A list of (node in key, node out key) pairs for each connection.
  • test (tuple) – A tuple of the form (node in key, node out key) that represents the connection trying to be added that needs to be tested.
Returns:

True if ‘test’ creates a cycle, False otherwise.

Return type:

bool

pyneat.graph_utils.find_path(sources, goals, connections)[source]

Try to find a path between the any of the start nodes and any of the goal nodes.

Parameters:
  • sources (list) – A list of node keys that the path may start from.
  • goals (list) – A list of node keys that the path may finish at.
  • connections (list) – A list of tuples that specify the input and output node keys of each enabled connection.
Returns:

A list of each node along the discovered path.

Return type:

list

pyneat.graph_utils.group_layers(inputs, outputs, biases, connections, nodes)[source]
Group nodes together into layers that can be evaluated in parallel by a
feed-forward neural network.

i.e. nodes in the same layer are independent conditional on the nodes in previous layers.

Parameters:
  • inputs (list) – The keys of the input nodes.
  • outputs (list) – The keys of the output nodes.
  • biases (list) – The keys of the bias nodes.
  • connections (list) – A list of (node in key, node out key) pairs for each expressed connection.
  • nodes (set) – The set of nodes required for calculating the output value.
Returns:

A list of sets that contain the node keys for the nodes in each

layer.

Return type:

list

pyneat.graph_utils.required_for_output(inputs, biases, outputs, connections, nodes)[source]

Check to see if a node is required for computing the output of the network.

A hidden node h in a NN is required if the following hold:
  1. there is a path from h to an output node
  2. there is a path from an input node to h

Shortcuts can be taken if there is a path from h1 to h2 and h1 has been marked as required.

Parameters:
  • inputs (list) – The keys of input nodes.
  • biases (list) – The keys of bias nodes.
  • outputs (list) – The keys of output nodes.
  • connections (list) – A list of tuples that specify the input and output node keys of each enabled connection.
  • nodes (list) – The keys of all nodes in the network.
Returns:

The set of nodes required for computing the output of the network.

Return type:

set