superneuromat.Neuron#

class superneuromat.Neuron(snn, idx: int, check_index: bool = True)[source]#

Accessor Class for Neurons in SNNs

Warning

Instances of Neurons are created at access time and are not unique. Multiple instances of this class may be created for the same neuron on the SNN. To test for equality, use == instead of is.

Attributes:
child_ids

Returns a list of the IDs of the child neurons of this neuron.

children

Returns a list of the child neurons of this neuron.

incoming_synapses

Returns a list of the synapses that have this neuron as their post-synaptic neuron.

incoming_synaptic_ids

Returns a list of the synaptic ids of the synapses that have this neuron as their post-synaptic neuron.

leak

The amount by which the internal state of this neuron is pushed towards its reset state.

num_onmodel
outgoing_synapses

Returns a list of the synapses that have this neuron as their pre-synaptic neuron.

outgoing_synaptic_ids

Returns a list of the synaptic ids of the synapses that have this neuron as their pre-synaptic neuron.

parent_ids

Returns a list of the IDs of the parent neurons of this neuron.

parents

Returns a list of the parent neurons of this neuron.

refractory_period

The number of time steps for which this neuron should be in its refractory period.

refractory_state

The remaining number of time steps for which this neuron is in its refractory period.

reset_state

The charge state of this neuron immediately after spiking.

spikes

A vector of the spikes that have been emitted by this neuron.

state

The charge state of this neuron.

threshold

The > threshold value for this neuron to spike.

Methods

add_spike(time[, value])

Queue a spike to be sent to this Neuron.

add_spikes(spikes[, time_offset, exist])

Add a time-series of spikes to this neuron.

connect_child(child[, weight, delay, ...])

Connect this neuron to a child neuron.

connect_parent(parent[, weight, delay, ...])

Connect this neuron to a parent neuron.

get_synapse_from(neuron)

Returns the synapse connecting the given neuron to this neuron (directional).

get_synapse_to(neuron)

Returns the synapse connecting this neuron to the given neuron (directional).

get_synaptic_id_from(neuron)

Returns the synaptic id of the synapse connecting the given neuron to this neuron (directional).

get_synaptic_id_to(neuron)

Returns the synaptic id of the synapse connecting this neuron to the given neuron (directional).

info()

Returns a string containing information about this neuron.

info_row()

Returns a string containing information about this neuron for use in a table.

spikes_str([max_steps, use_unicode])

Returns a pretty string of the spikes that have been emitted by this neuron.

check_index

row_cont

row_header

add_spike(time: int, value: float = 1.0, **kwargs)[source]#

Queue a spike to be sent to this Neuron.

Parameters:
  • time (int) – The number of time_steps until the spike is sent.

  • value (float, default=1.0) – The value of the spike.

  • exist (str, default='error') – Action if a queued spike already exists at the given time step. Should be one of [‘error’, ‘overwrite’, ‘add’, ‘dontadd’].

add_spikes(spikes: list[float] | list[tuple[int, float]] | ~numpy.ndarray[(<class 'int'>,), ~numpy.dtype] | ~numpy.ndarray[(<class 'int'>, 2), ~numpy.dtype], time_offset: int = 0, exist: str = 'error')[source]#

Add a time-series of spikes to this neuron.

Parameters:
  • spikes (numpy.typing.ArrayLike)

  • time_offset (int, default=0) – The number of time steps to offset the spikes by.

  • exist (str, default='error') – Action if a queued spike already exists at the given time step. Should be one of [‘error’, ‘overwrite’, ‘add’, ‘dontadd’].

Examples

If the input is a list of floats, it will be interpreted as a time-series of spikes to be fed in, one after the other.

neuron.add_spikes([0.0, 1.0, 2.0, 3.0])
# is equivalent to
for i in range(4):
    neuron.add_spike(i, i)

However, 0.0-valued spikes are not added unless exist='overwrite'.

If you would like to send a set of spikes at particular times, you can use a list of tuples:

neuron.add_spikes([
    (1, 1.0),
    (3, 3.0),
])

Note

The times and values will be cast to SNN.default_dtype.

Changed in version v3.2.0: Returns the Synapse object created.

property child_ids: list[int][source]#

Returns a list of the IDs of the child neurons of this neuron.

property children: list[Neuron][source]#

Returns a list of the child neurons of this neuron.

connect_child(child, weight: float = 1.0, delay: int = 1, stdp_enabled: bool = False, exist='error') Synapse[source]#

Connect this neuron to a child neuron.

Parameters:
  • child (Neuron | int) – The child neuron that will receive the spikes from this neuron.

  • weight (float, default=1.0) – The weight of the synapse connecting this neuron to the child.

  • delay (int, default=1) – The delay of the synapse connecting this neuron to the child.

  • stdp_enabled (bool, default=False) – If True, enable STDP learning on the synapse connecting this neuron to the child.

Returns:

connect_parent(parent, weight: float = 1.0, delay: int = 1, stdp_enabled: bool = False, exist='error') Synapse[source]#

Connect this neuron to a parent neuron.

Parameters:
  • parent (Neuron | int) – The parent neuron that will send spikes to this neuron.

  • weight (float, default=1.0) – The weight of the synapse connecting the parent to this neuron.

  • delay (int, default=1) – The delay of the synapse connecting the parent to this neuron.

  • stdp_enabled (bool, default=False) – If True, enable STDP learning on the synapse connecting the parent to this neuron.

Returns:

get_synapse_from(neuron: int | Neuron) Synapse[source]#

Returns the synapse connecting the given neuron to this neuron (directional).

Parameters:

neuron (Neuron | int) – The neuron which sends spikes to this neuron.

Returns:

The synapse connecting the given neuron to this neuron.

Return type:

Synapse

Raises:
  • TypeError – If neuron is not a Neuron or neuron ID (int).

  • IndexError – If no matching synapse is found.

get_synapse_to(neuron: int | Neuron) Synapse[source]#

Returns the synapse connecting this neuron to the given neuron (directional).

Parameters:

neuron (Neuron | int) – The neuron to which this neuron is connected.

Returns:

The synapse connecting this neuron to the given neuron.

Return type:

Synapse

Raises:
  • TypeError – If neuron is not a Neuron or neuron ID (int).

  • IndexError – If no matching synapse is found.

get_synaptic_id_from(neuron: int | Neuron) int | None[source]#

Returns the synaptic id of the synapse connecting the given neuron to this neuron (directional).

Parameters:

neuron (Neuron | int) – The neuron which sends spikes to this neuron.

Returns:

The synaptic id of the synapse connecting the given neuron to this neuron.

Return type:

int | None

Raises:

TypeError – If neuron is not a Neuron or neuron ID (int).

get_synaptic_id_to(neuron: int | Neuron) int | None[source]#

Returns the synaptic id of the synapse connecting this neuron to the given neuron (directional).

Parameters:

neuron (Neuron | int) – The neuron to which this neuron is connected.

Returns:

The synaptic id of the synapse connecting this neuron to the given neuron.

Return type:

int | None

Raises:
  • TypeError – If neuron is not a Neuron or neuron ID (int).

  • IndexError – If no matching synapse is found.

property incoming_synapses: list[Synapse][source]#

Returns a list of the synapses that have this neuron as their post-synaptic neuron.

property incoming_synaptic_ids: list[int][source]#

Returns a list of the synaptic ids of the synapses that have this neuron as their post-synaptic neuron.

info()[source]#

Returns a string containing information about this neuron.

The order of the fields is the same as in SNN.neuron_info() but without the spikes column.

info_row()[source]#

Returns a string containing information about this neuron for use in a table.

This function is used to generate rows for SNN.neuron_info().

property leak: float[source]#

The amount by which the internal state of this neuron is pushed towards its reset state.

property outgoing_synapses: list[Synapse][source]#

Returns a list of the synapses that have this neuron as their pre-synaptic neuron.

property outgoing_synaptic_ids: list[int][source]#

Returns a list of the synaptic ids of the synapses that have this neuron as their pre-synaptic neuron.

property parent_ids: list[int][source]#

Returns a list of the IDs of the parent neurons of this neuron.

property parents: list[Neuron][source]#

Returns a list of the parent neurons of this neuron.

property refractory_period: int[source]#

The number of time steps for which this neuron should be in its refractory period.

property refractory_state: float[source]#

The remaining number of time steps for which this neuron is in its refractory period.

property reset_state: float[source]#

The charge state of this neuron immediately after spiking.

property spikes: bool]] | list[source]#

A vector of the spikes that have been emitted by this neuron.

spikes_str(max_steps=10, use_unicode=True)[source]#

Returns a pretty string of the spikes that have been emitted by this neuron.

Parameters:
  • max_steps (int | None, default=10) – Limits the number of steps which will be included. If limited, only a total of max_steps first and last steps will be included.

  • use_unicode (bool, default=True) – If True, use unicode characters to represent spikes. Otherwise fallback to ascii characters.

property state: float[source]#

The charge state of this neuron.

property threshold: float[source]#

The > threshold value for this neuron to spike.