Wirings#

class ncps.wirings.Wiring(units)[source]#

Bases: object

property num_layers#
get_neurons_of_layer(layer_id)[source]#
is_built()[source]#
build(input_dim)[source]#
erev_initializer(shape=None, dtype=None)[source]#
sensory_erev_initializer(shape=None, dtype=None)[source]#
set_input_dim(input_dim)[source]#
set_output_dim(output_dim)[source]#
get_type_of_neuron(neuron_id)[source]#
add_synapse(src, dest, polarity)[source]#
add_sensory_synapse(src, dest, polarity)[source]#
get_config()[source]#
classmethod from_config(config)[source]#
get_graph(include_sensory_neurons=True)[source]#

Returns a networkx.DiGraph object of the wiring diagram :param include_sensory_neurons: Whether to include the sensory neurons as nodes in the graph

property synapse_count#

Counts the number of synapses between internal neurons of the model

property sensory_synapse_count#

Counts the number of synapses from the inputs (sensory neurons) to the internal neurons of the model

draw_graph(layout='shell', neuron_colors=None, synapse_colors=None, draw_labels=False)[source]#

Draws a matplotlib graph of the wiring structure Examples:

>>> import matplotlib.pyplot as plt
>>> plt.figure(figsize=(6, 4))
>>> legend_handles = wiring.draw_graph(draw_labels=True)
>>> plt.legend(handles=legend_handles, loc="upper center", bbox_to_anchor=(1, 1))
>>> plt.tight_layout()
>>> plt.show()
Parameters:
  • layout

  • neuron_colors

  • synapse_colors

  • draw_labels

Returns:

class ncps.wirings.AutoNCP(units, output_size, sparsity_level=0.5, seed=22222)[source]#

Bases: NCP

Instantiate an NCP wiring with only needing to specify the number of units and the number of outputs

Parameters:
  • units – The total number of neurons

  • output_size – The number of motor neurons (=output size). This value must be less than units-2 (typically good choices are 0.3 times the total number of units)

  • sparsity_level – A hyperparameter between 0.0 (very dense) and 0.9 (very sparse) NCP.

  • seed – Random seed for generating the wiring

class ncps.wirings.NCP(inter_neurons, command_neurons, motor_neurons, sensory_fanout, inter_fanout, recurrent_command_synapses, motor_fanin, seed=22222)[source]#

Bases: Wiring

Creates a Neural Circuit Policies wiring. The total number of neurons (= state size of the RNN) is given by the sum of inter, command, and motor neurons. For an easier way to generate a NCP wiring see the AutoNCP wiring class.

Parameters:
  • inter_neurons – The number of inter neurons (layer 2)

  • command_neurons – The number of command neurons (layer 3)

  • motor_neurons – The number of motor neurons (layer 4 = number of outputs)

  • sensory_fanout – The average number of outgoing synapses from the sensory to the inter neurons

  • inter_fanout – The average number of outgoing synapses from the inter to the command neurons

  • recurrent_command_synapses – The average number of recurrent connections in the command neuron layer

  • motor_fanin – The average number of incoming synapses of the motor neurons from the command neurons

  • seed – The random seed used to generate the wiring

property num_layers#
get_neurons_of_layer(layer_id)[source]#
get_type_of_neuron(neuron_id)[source]#
build(input_shape)[source]#
class ncps.wirings.FullyConnected(units, output_dim=None, erev_init_seed=1111, self_connections=True)[source]#

Bases: Wiring

build(input_shape)[source]#
class ncps.wirings.Random(units, output_dim=None, sparsity_level=0.0, random_seed=1111)[source]#

Bases: Wiring

build(input_shape)[source]#