nn.layers.FFIAFBrianο
- class nn.layers.FFIAFBrian(*args, **kwargs)[source]ο
Bases:
LayerToTimedModuleA spiking feedforward layer with current inputs and spiking outputs
Attributes overview
Class name of
selfThe full name of this module (class plus module name)
The
TimeSeriesclass accepted by this moduleThe name of this module, or an empty string if
NoneThe
TimeSeriesclass returned by this moduleThe shape of this module
(DEPRECATED) The output size of this module
The input size of this module
The output size of this module
If
True, this module receives spiking input.If
True, this module sends spiking output.The current evolution time of this layer, in seconds
The simulation and input rasterisation timestep for this
TimedModuleMethods overview
__init__(*args,Β **kwargs)Construct a spiking feedforward layer with IAF neurons, with a Brian2 back-end.
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,Β ...])Function to evolve the states 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 the internal state and time of this module and all sub-modules
Reset all parameters in this module
Reset the internal state for this
TimedModuleReset the internal clock for this
TimedModuleset_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
TimedModuleis currently being initialised
- __init__(*args, **kwargs)ο
Construct a spiking feedforward layer with IAF neurons, with a Brian2 back-end. Inputs are continuous currents; outputs are spiking events
- Parameters:
weights (np.array) β Layer weight matrix [N_in, N]
bias (nparray) β Nx1 bias vector. Default:
10mAdt (float) β Time-step. Default:
0.1 msnoise_std (float) β Noise std. dev. per second. Default:`` 0.``
tau_mem (FloatVector) β Nx1 vector of neuron time constants. Default:
20msv_thresh (FloatVector) β Nx1 vector of neuron thresholds. Default:
-55mVv_reset (FloatVector) β Nx1 vector of neuron thresholds. Default:
-65mVv_rest (FloatVector) β Nx1 vector of neuron thresholds. Default:
-65mVrefractory (float) β Refractory period after each spike. Default:
0msneuron_eq (Union[Brian2.Equations, str]) β Set of neuron equations. Default: IAF equation set
integrator_name (str) β Integrator to use for simulation. Default:
'rk4'name (str) β Name for the layer. Default:
'unnamed'record (bool) β Record membrane potential during evolutions
- _abc_impl = <_abc._abc_data object>ο
- _determine_timesteps(ts_input: TimeSeries | None = None, duration: float | None = None, num_timesteps: int | None = 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_timestepsor the duration ofts_inputwill be used to determine evolution timenum_timesteps (Optional[int]) β Number of evolution time steps, in units of
dt. If not provided,durationor the duration ofts_inputwill 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[TimeSeries, Dict, Dict]ο
Wrap a call to
evolve()to update the internal time-steps countSee
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) ndarrayο
Generate a time trace starting at
t_start, of lengthnum_timestepswith time stepdt- 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: ndarray, **kwargs) TimeSeriesο
Wrap a clocked / rasterised output array into a
TimeSeriesobjectOutput
TimeSerieswill 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
outputwrapped into aTimeSeriesobject- Return type:
- _gen_tscontinuous(output: ndarray, dt: float | None = None, t_start: float | None = None, name: str | None = None, periodic: bool = False, interp_kind: str = 'previous') TSContinuousο
Wrap a rasterised output array as a
TSContinuousobject to present as output for this moduleOutput
TSContinuouss will be named nicely, with correct start times, durations, etc. Several attributes of theTSContinuousobject 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 moduledtwill be usedt_start (Optional[float]) β The start time of the output
TSContinuousobject, in seconds. If not provided, the module time before evolution will be usedname (Optional[str]) β The desired name of the
TSContinuousobject. If not provided, the object will be named nicely according to the module nameperiodic (bool) β Flag to indicate whether the returned
TSContinuousshould be periodic. Default:False, theTSContinuouswill not be periodicinterp_kind (str) β The style of interpolation to apply to the returned
TSContinuousobject. Default:"previous"
- Returns:
The wrapped output data as a
TSContinuousobject- Return type:
- _gen_tsevent(output: ndarray, dt: float | None = None, t_start: float | None = None, name: str | None = None, periodic: bool = False, num_channels: int | None = None, spikes_at_bin_start: bool = False) TSEventο
Wrap a rasterised output array as a
TSEventobject to present as output for this moduleOutput
TSEvents will be named nicely, with correct start timesm durations, etc. Several attributes of theTSEventobject 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 moduledtwill be usedt_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
TSEventobject. If not provided, the object will be named nicely according to the module nameperiodic (bool) β Flag to indicate whether the returned
TSEventshould be periodic. Default:False, theTSEventwill not be periodicnum_channels (Optional[int]) β The desired number of total channels for the output
TSEventobject. If not provided, the output sizesize_outof the current module will be usedspikes_at_bin_start (bool) β If
False(default), spike events will be considered to fall in the middle of the time bin they fall in. IfTrue, 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
TSEventobject- Return type:
- _get_attribute_family(type_name: str, family: Tuple | List | str | None = 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 ofParameterBasefamily (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_nameandfamily- 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:
Trueif the attributenameis in the attribute registry,Falseotherwise.- 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
- _name: strο
The name of the wrapped layer
- Type:
str
- _parent_dt_factor: floatο
The factor between the parentβs
dtand this moduleβsdt. Given byself.dt / parent.dt
- _prepare_input(ts_input: TimeSeries | None = None, duration: float | None = None, num_timesteps: int | None = None) Tuple[ndarray, 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]) β
TimeSeriesof TxM or Tx1 Input signals for this layerduration (Optional[float]) β Duration of the desired evolution, in seconds. If not provided, then either
num_timestepsor the duration ofts_inputwill define the evolution timenum_timesteps (Optional[int]) β Integer number of evolution time steps, in units of
dt. If not provided, thendurationor the duration ofts_inputwill 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: TSContinuous | None = None, duration: float | None = None, num_timesteps: int | None = None) Tuple[ndarray, 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]) β
TSContinuousof TxM or Tx1 Input signals for this layerduration (Optional[float]) β Duration of the desired evolution, in seconds. If not provided, then either
num_timestepsor the duration ofts_inputwill define the evolution timenum_timesteps (Optional[int]) β Integer number of evolution time steps, in units of
dt. If not provided, thendurationor the duration ofts_inputwill 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: TSEvent | None = None, duration: float | None = None, num_timesteps: int | None = None, add_events: bool = False) Tuple[ndarray, ndarray, int]ο
Sample input from a
TSEventtime series, set up evolution time baseThis 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_timestepsor the duration ofts_inputwill determine evolution itmenum_timesteps (Optional[int]) β Number of evolution time steps, in units of
dt. If not provided, then eitherdurationor the duration ofts_inputwill 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: ParameterBase)ο
Record an attribute in the attribute registry
- Parameters:
name (str) β The name of the attribute to register
val (ParameterBase) β The
ParameterBasesubclass object to register. e.g.Parameter,SimulationParameterorState.
- _register_module(name: str, mod: ModuleBase)ο
Register a sub-module in the module registry
- Parameters:
name (str) β The name of the module to register
mod (ModuleBase) β The
ModuleBaseobject to register
- _reset_attribute(name: str) 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
dts.
- _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
- _wrap_recorded_state(recorded_dict: dict, t_start: float) Dict[str, TimeSeries]ο
Convert a recorded dictionary to a
TimeSeriesrepresentationThis method is optional, and is provided to make the
timed()conversion to aTimedModulework better. You should override this method in your customModule, to wrap each element of your recorded state dictionary as aTimeSeries- 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
TimeSeriesobjects- Return type:
Dict[str, TimeSeries]
- as_graph() GraphModuleBaseο
Convert this module to a computational graph
- Returns:
The computational graph corresponding to this module
- Return type:
- Raises:
NotImplementedError β If
as_graph()is not implemented for this subclass
- attributes_named(name: 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: float | SimulationParameterο
The simulation and input rasterisation timestep for this
TimedModule- Type:
float
- evolve(ts_input: TimeSeries | None = None, duration: float | None = None, num_timesteps: int | None = None, kwargs_timeseries: dict | None = None, record: bool = False, *args, **kwargs) Tuple[TimeSeries, dict, dict]ο
Function to evolve the states of this layer given an input
- property full_name: strο
The full name of this module (class plus module name)
- Type:
str
- property input_type: typeο
The
TimeSeriesclass 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
TimeSeriesclass returned by this module- Type:
type
- parameters(family: Tuple | List | str | None = 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
familyallows you to search for Parameters in a particular family β for example"weights"for all weights of this module and nested submodules.Although the
familyargument 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:
- 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) 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: Tuple | List | str | None = 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
familyallows 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. IfFalse, this module expects continuous input.- Type:
bool
- property spiking_outputο
If
True, this module sends spiking output. IfFalse, this module sends continuous output.- Type:
bool
- state(family: Tuple | List | str | None = 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
familyallows 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