nn.layers.FFExpSynBrian

class nn.layers.FFExpSynBrian(*args, **kwargs)[source]

Bases: rockpool.nn.modules.timed_module.LayerToTimedModule

Define an exponential synapse layer (spiking input), with a Brian2 backend

__init__(*args, **kwargs)

Construct an exponential synapse layer (spiking input), with a Brian2 backend

Parameters
  • weights – np.array MxN weight matrix int Size of layer -> creates one-to-one conversion layer

  • dt – float Time step for state evolution. Default: 0.1 ms

  • noise_std – float Std. dev. of noise added to this layer. Default: 0

  • tau_syn – float Output synaptic time constants. Default: 5ms

  • synapse_eq – Brian2.Equations set of synapse equations for receiver. Default: exponential

  • integrator_name – str Integrator to use for simulation. Default: β€˜exact’

  • name – str Name for the layer. Default: β€˜unnamed’

Attributes overview

class_name

Class name of self

full_name

The full name of this module (class plus module name)

input_type

The TimeSeries class accepted by this module

name

The name of this module, or an empty string if None

output_type

The TimeSeries class returned by this module

shape

The shape of this module

size

(DEPRECATED) The output size of this module

size_in

The input size of this module

size_out

The output size of this module

spiking_input

If True, this module receives spiking input.

spiking_output

If True, this module sends spiking output.

t

The current evolution time of this layer, in seconds

Methods overview

__init__(*args,Β **kwargs)

Construct an exponential synapse layer (spiking input), with a Brian2 backend

as_graph()

Convert this module to a computational graph

attributes_named(name)

Search for attributes of this or submodules by time

evolve([ts_input,Β duration,Β num_timesteps,Β ...])

Evolve the state of this layer given an input

modules()

Return a dictionary of all sub-modules of this module

parameters([family])

Return a nested dictionary of module and submodule Parameters

reset_all()

Reset the internal state and time of this module and all sub-modules

reset_parameters()

Reset all parameters in this module

reset_state()

Reset the internal state for this TimedModule

reset_time()

Reset the internal clock for this TimedModule

set_attributes(new_attributes)

Set the attributes and sub-module attributes from a dictionary

simulation_parameters([family])

Return a nested dictionary of module and submodule SimulationParameters

state([family])

Return a nested dictionary of module and submodule States

__in_TimedModule_init: bool

A flag indicating that this TimedModule is currently being initialised

__init__(*args, **kwargs)

Construct an exponential synapse layer (spiking input), with a Brian2 backend

Parameters
  • weights – np.array MxN weight matrix int Size of layer -> creates one-to-one conversion layer

  • dt – float Time step for state evolution. Default: 0.1 ms

  • noise_std – float Std. dev. of noise added to this layer. Default: 0

  • tau_syn – float Output synaptic time constants. Default: 5ms

  • synapse_eq – Brian2.Equations set of synapse equations for receiver. Default: exponential

  • integrator_name – str Integrator to use for simulation. Default: β€˜exact’

  • name – str Name for the layer. Default: β€˜unnamed’

_abc_impl = <_abc_data object>
_determine_timesteps(ts_input: Optional[rockpool.timeseries.TimeSeries] = None, duration: Optional[float] = None, num_timesteps: Optional[int] = None) int

Determine how many time steps to evolve with the given input specification

Parameters
  • ts_input (Optional[TimeSeries]) – TxM or Tx1 time series of input signals for this layer

  • duration (Optional[float]) – Duration of the desired evolution, in seconds. If not provided, num_timesteps or the duration of ts_input will be used to determine evolution time

  • num_timesteps (Optional[int]) – Number of evolution time steps, in units of dt. If not provided, duration or the duration of ts_input will be used to determine evolution time

Return int

num_timesteps: Number of evolution time steps

_evolve_wrapper(ts_input=None, duration=None, num_timesteps=None, kwargs_timeseries=None, record: bool = False, *args, **kwargs) Tuple[rockpool.timeseries.TimeSeries, Dict, Dict]

Wrap a call to evolve() to update the internal time-steps count

See evolve() for calling syntax.

_force_set_attributes

(bool) If True, do not sanity-check attributes when setting.

_gen_time_trace(t_start: float, num_timesteps: int) numpy.ndarray

Generate a time trace starting at t_start, of length num_timesteps with time step dt

Parameters
  • t_start (float) – Start time, in seconds

  • num_timesteps (int) – Number of time steps to generate, in units of dt

Return ndarray

Generated time trace

_gen_timeseries(output: numpy.ndarray, **kwargs) rockpool.timeseries.TimeSeries

Wrap a clocked / rasterised output array into a TimeSeries object

Output TimeSeries will be of the appropriate subclass, and will be named nicely.

Parameters
  • output (np.ndarray) – The clocked or rasterised output data (T, N)

  • **kwargs – Additional keyword arguments to TimeSeries

Returns

The data in output wrapped into a TimeSeries object

Return type

TimeSeries

_gen_tscontinuous(output: numpy.ndarray, dt: Optional[float] = None, t_start: Optional[float] = None, name: Optional[str] = None, periodic: bool = False, interp_kind: str = 'previous') rockpool.timeseries.TSContinuous

Wrap a rasterised output array as a TSContinuous object to present as output for this module

Output TSContinuous s will be named nicely, with correct start times, durations, etc. Several attributes of the TSContinuous object can be set as arguments here.

Parameters
  • output (np.ndarray) – A clocked time series data array (T, N)

  • dt (Optional[float]) – The time-step of the clocked array output. If not provided, the module dt will be used

  • t_start (Optional[float]) – The start time of the output TSContinuous object, in seconds. If not provided, the module time before evolution will be used

  • name (Optional[str]) – The desired name of the TSContinuous object. If not provided, the object will be named nicely according to the module name

  • periodic (bool) – Flag to indicate whether the returned TSContinuous should be periodic. Default: False, the TSContinuous will not be periodic

  • interp_kind (str) – The style of interpolation to apply to the returned TSContinuous object. Default: "previous"

Returns

The wrapped output data as a TSContinuous object

Return type

TSContinuous

_gen_tsevent(output: numpy.ndarray, dt: Optional[float] = None, t_start: Optional[float] = None, name: Optional[str] = None, periodic: bool = False, num_channels: Optional[int] = None, spikes_at_bin_start: bool = False) rockpool.timeseries.TSEvent

Wrap a rasterised output array as a TSEvent object to present as output for this module

Output TSEvent s will be named nicely, with correct start timesm durations, etc. Several attributes of the TSEvent object can be set as arguments here.

Parameters
  • output (np.ndarray) – A rasterised event array (T, N)

  • dt (Optional[float]) – The time-step of the rasterised array output. If not provided, the module dt will be used

  • t_start (Optional[float]) – The start time of the output series, in seconds. If not provided, the module time before evolution will be used

  • name (Optional[str]) – The desired name of the TSEvent object. If not provided, the object will be named nicely according to the module name

  • periodic (bool) – Flag to indicate whether the returned TSEvent should be periodic. Default: False, the TSEvent will not be periodic

  • num_channels (Optional[int]) – The desired number of total channels for the output TSEvent object. If not provided, the output size size_out of the current module will be used

  • spikes_at_bin_start (bool) – If False (default), spike events will be considered to fall in the middle of the time bin they fall in. If True, all spike events will be considered to occur at the start of the time bin they fall in.

Returns

The wrapped output raster as a TSEvent object

Return type

TSEvent

_get_attribute_family(type_name: str, family: Optional[Union[Tuple, List, str]] = None) dict

Search for attributes of this module and submodules that match a given family

This method can be used to conveniently get all weights for a network; or all time constants; or any other family of parameters. Parameter families are defined simply by a string: "weights" for weights; "taus" for time constants, etc. These strings are arbitrary, but if you follow the conventions then future developers will thank you (that includes you in six month’s time).

Parameters
  • type_name (str) – The class of parameters to search for. Must be one of ["Parameter", "SimulationParameter", "State"] or another future subclass of ParameterBase

  • family (Union[str, Tuple[str]]) – A string or list or tuple of strings, that define one or more attribute families to search for

Returns

A nested dictionary of attributes that match the provided type_name and family

Return type

dict

_get_attribute_registry() Tuple[Dict, Dict]

Return or initialise the attribute registry for this module

Returns

registered_attributes, registered_modules

Return type

(tuple)

_has_registered_attribute(name: str) bool

Check if the module has a registered attribute

Parameters

name (str) – The name of the attribute to check

Returns

True if the attribute name is in the attribute registry, False otherwise.

Return type

bool

_in_Module_init

(bool) If exists and True, indicates that the module is in the __init__ chain.

_is_child: bool

Flag indicating that this is a child module

_module: Layer

The wrapped layer object

Type

Layer

_name: str

The name of the wrapped layer

Type

str

_parent_dt_factor: float

The factor between the parent’s dt and this module’s dt. Given by self.dt / parent.dt

_prepare_input(ts_input: Optional[rockpool.timeseries.TimeSeries] = None, duration: Optional[float] = None, num_timesteps: Optional[int] = None) Tuple[numpy.ndarray, numpy.ndarray, int]

Sample input, set up time base

This function checks an input signal, and prepares a discretised time base according to the time step of the current module

Parameters
  • ts_input (Optional[TimeSeries]) – TimeSeries of TxM or Tx1 Input signals for this layer

  • duration (Optional[float]) – Duration of the desired evolution, in seconds. If not provided, then either num_timesteps or the duration of ts_input will define the evolution time

  • num_timesteps (Optional[int]) – Integer number of evolution time steps, in units of dt. If not provided, then duration or the duration of ts_input will define the evolution time

Return (ndarray, ndarray, int)

(time_base, input_steps, num_timesteps) time_base: T1 Discretised time base for evolution input_raster (T1xN) Discretised input signal for layer num_timesteps: Actual number of evolution time steps, in units of dt

_prepare_input_continuous(ts_input: Optional[rockpool.timeseries.TSContinuous] = None, duration: Optional[float] = None, num_timesteps: Optional[int] = None) Tuple[numpy.ndarray, numpy.ndarray, int]

Sample input, set up time base

This function checks an input signal, and prepares a discretised time base according to the time step of the current module

Parameters
  • ts_input (Optional[TSContinuous]) – TSContinuous of TxM or Tx1 Input signals for this layer

  • duration (Optional[float]) – Duration of the desired evolution, in seconds. If not provided, then either num_timesteps or the duration of ts_input will define the evolution time

  • num_timesteps (Optional[int]) – Integer number of evolution time steps, in units of dt. If not provided, then duration or the duration of ts_input will define the evolution time

Return (ndarray, ndarray, int)

(time_base, input_raster, num_timesteps) time_base: T1 Discretised time base for evolution input_raster: (T1xN) Discretised input signal for layer num_timesteps: Actual number of evolution time steps, in units of dt

_prepare_input_events(ts_input: Optional[rockpool.timeseries.TSEvent] = None, duration: Optional[float] = None, num_timesteps: Optional[int] = None, add_events: bool = False) Tuple[numpy.ndarray, numpy.ndarray, int]

Sample input from a TSEvent time series, set up evolution time base

This function checks an input signal, and prepares a discretised time base according to the time step of the current module

Parameters
  • ts_input (Optional[TSEvent]) – TimeSeries of TxM or Tx1 Input signals for this layer

  • duration (Optional[float]) – Duration of the desired evolution, in seconds. If not provided, then either num_timesteps or the duration of ts_input will determine evolution itme

  • num_timesteps (Optional[int]) – Number of evolution time steps, in units of dt. If not provided, then either duration or the duration of ts_input will determine evolution time

Return (ndarray, ndarray, int)

time_base: T1X1 vector of time points – time base for the rasterisation spike_raster: Boolean or integer raster containing spike information. T1xM array num_timesteps: Actual number of evolution time steps, in units of dt

_register_attribute(name: str, val: rockpool.parameters.ParameterBase)

Record an attribute in the attribute registry

Parameters
  • name (str) – The name of the attribute to register

  • val (ParameterBase) – The ParameterBase subclass object to register. e.g. Parameter, SimulationParameter or State.

_register_module(name: str, mod: rockpool.nn.modules.module.ModuleBase)

Register a sub-module in the module registry

Parameters
  • name (str) – The name of the module to register

  • mod (ModuleBase) – The ModuleBase object to register

_reset_attribute(name: str) rockpool.nn.modules.module.ModuleBase

Reset an attribute to its initialisation value

Parameters

name (str) – The name of the attribute to reset

Returns

For compatibility with the functional API

Return type

self (Module)

_set_dt(max_factor: float = 100) None

Set a time step size for the network which is the lowest common multiple of all sub-module’s dt s.

Parameters

max_factor (float) – Factor by which the module dt may exceed the largest sub-module dt before an error is raised. Default: 100.

Raises

ValueError – If a sensible dt cannot be found

_shape

The shape of this module

_spiking_input: bool

Whether this module receives spiking input

_spiking_output: bool

Whether this module produces spiking output

_submodulenames: List[str]

Registry of sub-module names

_timestep: int

The current time-step count in units of dt

_wrap_recorded_state(recorded_dict: dict, t_start: float) Dict[str, rockpool.timeseries.TimeSeries]

Convert a recorded dictionary to a TimeSeries representation

This method is optional, and is provided to make the timed() conversion to a TimedModule work better. You should override this method in your custom Module, to wrap each element of your recorded state dictionary as a TimeSeries

Parameters
  • state_dict (dict) – A recorded state dictionary as returned by evolve()

  • t_start (float) – The initial time of the recorded state, to use as the starting point of the time series

Returns

The mapped recorded state dictionary, wrapped as TimeSeries objects

Return type

Dict[str, TimeSeries]

as_graph() rockpool.graph.graph_base.GraphModuleBase

Convert this module to a computational graph

Returns

The computational graph corresponding to this module

Return type

GraphModuleBase

Raises

NotImplementedError – If as_graph() is not implemented for this subclass

attributes_named(name: Union[Tuple[str], List[str], str]) dict

Search for attributes of this or submodules by time

Parameters

name (Union[str, Tuple[str]) – The name of the attribute to search for

Returns

A nested dictionary of attributes that match name

Return type

dict

property class_name: str

Class name of self

Type

str

dt: Union[float, SimulationParameter]

The simulation and input rasterisation timestep for this TimedModule

Type

float

evolve(ts_input: Optional[rockpool.timeseries.TimeSeries] = None, duration: Optional[float] = None, num_timesteps: Optional[int] = None, kwargs_timeseries: Optional[dict] = None, record: bool = False, *args, **kwargs) Tuple[rockpool.timeseries.TimeSeries, dict, dict]

Evolve the state of this layer given an input

Parameters
  • ts_input (Optional[TSEvent]) – Input spike train

  • duration (Optional[float]) – Simulation/Evolution duration in seconds

  • num_timesteps (Optional[int]) – Number of evolution time steps

  • ids_in (Optional[ArrayLike[int]]) – Array with IDs of input channels corresponding to the channels in ts_input. If None (default), will use channel IDs from ts_input.

  • ids_out (Optional[ArrayLike[int]]) – Array with IDs of neurons whose spiking activity should be recorded and returned. If None (default), return activity of all neurons.

  • remap_out_channels (Optional[bool]) – If True, IDs of recorded spikes in the returned timeseries will be mapped to a continuous sequence of integers starting from 0 (e.g. [1,6,3] -> [0,2,1]). If False (default), channels will correspond to actual neuron IDs.

  • verbose (Optional[bool]) – Currently no effect, just for conformity

Return TSEvent

Spike events generated within the layer during this evolution period

property full_name: str

The full name of this module (class plus module name)

Type

str

property input_type: type

The TimeSeries class accepted by this module

Type

type

modules() Dict

Return a dictionary of all sub-modules of this module

Returns

A dictionary containing all sub-modules. Each item will be named with the sub-module name.

Return type

dict

property name: str

The name of this module, or an empty string if None

Type

str

property output_type: type

The TimeSeries class returned by this module

Type

type

parameters(family: Optional[Union[Tuple, List, str]] = None) Dict

Return a nested dictionary of module and submodule Parameters

Use this method to inspect the Parameters from this and all submodules. The optional argument family allows you to search for Parameters in a particular family β€” for example "weights" for all weights of this module and nested submodules.

Although the family argument is an arbitrary string, reasonable choises are "weights", "taus" for time constants, "biases" for biases…

Examples

Obtain a dictionary of all Parameters for this module (including submodules):

>>> mod.parameters()
dict{ ... }

Obtain a dictionary of Parameters from a particular family:

>>> mod.parameters("weights")
dict{ ... }
Parameters

family (str) – The family of Parameters to search for. Default: None; return all parameters.

Returns

A nested dictionary of Parameters of this module and all submodules

Return type

dict

reset_all() None

Reset the internal state and time of this module and all sub-modules

reset_parameters()

Reset all parameters in this module

Returns

The updated module is returned for compatibility with the functional API

Return type

Module

reset_state() None

Reset the internal state for this TimedModule

reset_time() None

Reset the internal clock for this TimedModule

set_attributes(new_attributes: dict) rockpool.nn.modules.module.ModuleBase

Set the attributes and sub-module attributes from a dictionary

This method can be used with the dictionary returned from module evolution to set the new state of the module. It can also be used to set multiple parameters of a module and submodules.

Examples

Use the functional API to evolve, obtain new states, and set those states:

>>> _, new_state, _ = mod(input)
>>> mod = mod.set_attributes(new_state)

Obtain a parameter dictionary, modify it, then set the parameters back:

>>> params = mod.parameters()
>>> params['w_input'] *= 0.
>>> mod.set_attributes(params)
Parameters

new_attributes (dict) – A nested dictionary containing parameters of this module and sub-modules.

property shape: tuple

The shape of this module

Type

tuple

simulation_parameters(family: Optional[Union[Tuple, List, str]] = None) Dict

Return a nested dictionary of module and submodule SimulationParameters

Use this method to inspect the SimulationParameters from this and all submodules. The optional argument family allows you to search for SimulationParameters in a particular family.

Examples

Obtain a dictionary of all SimulationParameters for this module (including submodules):

>>> mod.simulation_parameters()
dict{ ... }
Parameters

family (str) – The family of SimulationParameters to search for. Default: None; return all SimulationParameter attributes.

Returns

A nested dictionary of SimulationParameters of this module and all submodules

Return type

dict

property size: int

(DEPRECATED) The output size of this module

Type

int

property size_in: int

The input size of this module

Type

int

property size_out: int

The output size of this module

Type

int

property spiking_input: bool

If True, this module receives spiking input. If False, this module expects continuous input.

Type

bool

property spiking_output

If True, this module sends spiking output. If False, this module sends continuous output.

Type

bool

state(family: Optional[Union[Tuple, List, str]] = None) Dict

Return a nested dictionary of module and submodule States

Use this method to inspect the States from this and all submodules. The optional argument family allows you to search for States in a particular family.

Examples

Obtain a dictionary of all States for this module (including submodules):

>>> mod.state()
dict{ ... }
Parameters

family (str) – The family of States to search for. Default: None; return all State attributes.

Returns

A nested dictionary of States of this module and all submodules

Return type

dict

property t: float

The current evolution time of this layer, in seconds

Type

float