Connection¶
- class Connection(synapse: Synapse)[source]¶
-
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.
- property batched_outshape: tuple[int, ...]¶
Shape of outputs from the connection, including the batch dimension.
- property batchsz: int¶
Batch size of the connection.
Note
This calls the property
batchszonsynapse, 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:
NotImplementedError –
biasmust be implemented by the subclass.
- property biased: bool¶
If the connection has learnable biases.
- Returns:
if the connection has learnable biases.
- Return type:
- clear(**kwargs) None[source]¶
Resets the state of the connection.
Note
This calls the method
Synapse.clear()onsynapseandUpdater.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
Updaterwith the following trainable parameters:- Returns:
newly set updater.
- Return type:
- 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:
NotImplementedError –
delaymust be implemented by the subclass.
- property delayedby: float | None¶
Maximum valid learned delay, in milliseconds.
- Returns:
maximum valid learned delays.
- Return type:
Note
This calls the property
Synapse.delayonsynapseif the connections has delays, otherwise returns None.
- 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:
- Raises:
NotImplementedError –
forwardmust 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:
- Raises:
NotImplementedError –
inshapemust 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:
Caution
This is a cached property based on
inshape. When subclassing, if the computed value forinshapeis changed,insizemust 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:
NotImplementedError –
like_biasmust be implemented by the subclass.- Returns:
reshaped data.
- Return type:
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:
NotImplementedError –
like_inputmust be implemented by the subclass.- Returns:
reshaped data.
- Return type:
- 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:
NotImplementedError –
like_synapticmust be implemented by the subclass.- Returns:
reshaped data.
- Return type:
- abstract property outshape: tuple[int, ...]¶
Shape of outputs from the connection, excluding the batch dimension.
- Returns:
shape of outputs from the connection.
- Return type:
- Raises:
NotImplementedError –
outshapemust 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:
Caution
This is a cached property based on
outshape. When subclassing, if the computed value foroutshapeis changed,outsizemust 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:
NotImplementedError –
postsyn_receptivemust beimplemented by the subclass. –
- Returns:
reshaped data.
- Return type:
Shape
data:return:\(B \times\) broadcastable with
weighttimes \(\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:
NotImplementedError –
presyn_receptivemust beimplemented by the subclass. –
- Returns:
reshaped data.
- Return type:
Shape
data:like
syncurrentorsynspikereturn:\(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:
NotImplementedError –
selectormust be implemented by the subclass.
- property syncurrent: Tensor¶
Currents from the synapse at the time last used by the connection.
- Returns:
delay-offset synaptic currents.
- Return type:
- property synspike: Tensor¶
Spikes to the synapse at the time last used by the connection.
- Returns:
delay-offset synaptic spikes.
- Return type:
- abstract property weight: Parameter¶
Learnable connection weights.
- Parameters:
value (torch.Tensor | nn.Parameter) – new weights.
- Returns:
present weights.
- Return type:
nn.Parameter
- Raises:
NotImplementedError –
weightmust be implemented by the subclass.