Connection

class Connection(synapse: Synapse)[source]

Bases: Updatable, Module, ABC

Base class for representing a weighted connection between two groups of neurons.

Parameters:

synapse (Synapse) – synapse used to generate currents from inputs.

property batched_inshape: tuple[int, ...]

Shape of inputs to the connection, including the batch dimension.

Returns:

shape of inputs to the connection.

Return type:

tuple[int]

property batched_outshape: tuple[int, ...]

Shape of outputs from the connection, including the batch dimension.

Returns:

shape of outputs from the connection.

Return type:

tuple[int]

property batchsz: int

Batch size of the connection.

Parameters:

value (int) – new batch size.

Returns:

current batch size.

Return type:

int

Note

This calls the property batchsz on synapse, assuming the connection has no batch size dependent state.

abstract property bias: Parameter | None

Learnable connection biases.

Parameters:

value (torch.Tensor | nn.Parameter) – new biases.

Returns:

present biases, if any.

Return type:

nn.Parameter | None

Raises:

NotImplementedErrorbias must be implemented by the subclass.

property biased: bool

If the connection has learnable biases.

Returns:

if the connection has learnable biases.

Return type:

bool

clear(**kwargs) None[source]

Resets the state of the connection.

Note

This calls the method Synapse.clear() on synapse and Updater.clear() on :py:attr`updater`, assuming the connection itself has no clearable state. Keyword arguments are passed through.

defaultupdater(*includes: str, exclude_weight: bool = False, exclude_bias: bool = False, exclude_delay: bool = False) Updater[source]

Default updater for this connection.

Parameters:
  • *includes (str) – additional instance-specific parameters to include.

  • exclude_weight (bool, optional) – if weight should not be an updatable parameter. Defaults to False.

  • exclude_bias (bool, optional) – if bias should not be an updatable parameter. Defaults to False.

  • exclude_delay (bool, optional) – if delay should not be an updatable parameter. Defaults to False.

This will set and return an Updater with the following trainable parameters:

Returns:

newly set updater.

Return type:

Updater

abstract property delay: Parameter | None

Learnable delays of the connection.

Parameters:

value (torch.Tensor | nn.Parameter) – new delays.

Returns:

current delays, if the connection has any.

Return type:

nn.Parameter | None

Raises:

NotImplementedErrordelay must be implemented by the subclass.

property delayedby: float | None

Maximum valid learned delay, in milliseconds.

Returns:

maximum valid learned delays.

Return type:

float

Note

This calls the property Synapse.delay on synapse if the connections has delays, otherwise returns None.

property dt: float

Length of the simulation time step, in milliseconds.

Parameters:

value (float) – new length of the simulation time step.

Returns:

current length of the simulation time step.

Return type:

float

Note

This calls the property dt on synapse, assuming the connection has no step time dependent state.

extra_repr() str[source]

Returns extra information on this module.

abstract forward(*inputs: Tensor, **kwargs) Tensor[source]

Runs a simulation step of the connection.

Parameters:

*inputs (torch.Tensor) – inputs which will be reshaped like the composed synapse and passed to its Synapse.forward() call.

Returns:

resulting postsynaptic currents.

Return type:

torch.Tensor

Raises:

NotImplementedErrorforward must be implemented by the subclass.

Note

When subclassing, keyword arguments should also be passed to the composed Synapse.

abstract property inshape: tuple[int, ...]

Shape of inputs to the connection, excluding the batch dimension.

Returns:

shape of inputs to the connection.

Return type:

tuple[int]

Raises:

NotImplementedErrorinshape must be implemented by the subclass.

insize() int[source]

Number of inputs to the connection, excluding the batch dimension.

Returns:

number of inputs to the connection.

Return type:

int

Caution

This is a cached property based on inshape. When subclassing, if the computed value for inshape is changed, insize must be deleted to refresh the cache.

abstract like_bias(data: Tensor) Tensor[source]

Reshapes data like reduced postsynaptic receptive spikes to connection bias.

Parameters:

data (torch.Tensor) – data shaped like reduced postsynaptic receptive spikes.

Raises:

NotImplementedErrorlike_bias must be implemented by the subclass.

Returns:

reshaped data.

Return type:

torch.Tensor

Shape

data:

like postsyn_receptive(), excluding the first (batch) and last (receptive field) dimension.

return:

like bias

abstract like_input(data: Tensor) Tensor[source]

Reshapes data like synapse input to connection input.

Parameters:

data (torch.Tensor) – data shaped like synapse input.

Raises:

NotImplementedErrorlike_input must be implemented by the subclass.

Returns:

reshaped data.

Return type:

torch.Tensor

Shape

data:

like syncurrent or synspike

return:

batched_inshape

abstract like_synaptic(data: Tensor) Tensor[source]

Reshapes data like connection input to synapse input.

Parameters:

data (torch.Tensor) – data shaped like connection input.

Raises:

NotImplementedErrorlike_synaptic must be implemented by the subclass.

Returns:

reshaped data.

Return type:

torch.Tensor

Shape

data:

batched_inshape

return:

like syncurrent or synspike

abstract property outshape: tuple[int, ...]

Shape of outputs from the connection, excluding the batch dimension.

Returns:

shape of outputs from the connection.

Return type:

tuple[int]

Raises:

NotImplementedErroroutshape must be implemented by the subclass.

outsize() int[source]

Number of outputs from the connection, excluding the batch dimension.

Returns:

number of outputs from the connection.

Return type:

int

Caution

This is a cached property based on outshape. When subclassing, if the computed value for outshape is changed, outsize must be deleted to refresh the cache.

abstract postsyn_receptive(data: Tensor) Tensor[source]

Reshapes data like connection output for pre-post learning methods.

Parameters:

data (torch.Tensor) – data shaped like output of forward().

Raises:
Returns:

reshaped data.

Return type:

torch.Tensor

Shape

data:

batched_outshape

return:

\(B \times\) broadcastable with weight times \(\times L\)

Where:
  • \(B\) is the batch size.

  • \(L\) is a connection-dependent value.

abstract presyn_receptive(data: Tensor) Tensor[source]

Reshapes data like the synapse state for pre-post learning methods.

Parameters:

data (torch.Tensor) – data shaped like output of like_synaptic().

Raises:
Returns:

reshaped data.

Return type:

torch.Tensor

Shape

data:

like syncurrent or synspike

return:

\(B \times\) broadcastable with weight \(\times L\)

Where:
  • \(B\) is the batch size.

  • \(L\) is a connection-dependent value.

abstract property selector: Tensor | None

Learned delays as a selector for synaptic currents and delays.

Returns:

delay selector if the connection has learnable delays.

Return type:

torch.Tensor | None

Raises:

NotImplementedErrorselector must be implemented by the subclass.

property synapse: Synapse

Synapse registered with this connection.

Parameters:

value (Synapse) – new synapse for this connection.

Returns:

registered synapse.

Return type:

Synapse

property syncurrent: Tensor

Currents from the synapse at the time last used by the connection.

Returns:

delay-offset synaptic currents.

Return type:

torch.Tensor

Note

If delayedby is None, this should return the most recent synaptic currents, otherwise it should return those indexed by delay.

property synspike: Tensor

Spikes to the synapse at the time last used by the connection.

Returns:

delay-offset synaptic spikes.

Return type:

torch.Tensor

abstract property weight: Parameter

Learnable connection weights.

Parameters:

value (torch.Tensor | nn.Parameter) – new weights.

Returns:

present weights.

Return type:

nn.Parameter

Raises:

NotImplementedErrorweight must be implemented by the subclass.