reservoirpy.nodes.LIF#

class reservoirpy.nodes.LIF(
units: int | None = None,
inhibitory: float = 0.0,
threshold: float = 1.0,
lr: float = 0.0,
sr: float = 1.0,
input_scaling: float | ~typing.Sequence = 1.0,
rc_connectivity: float = 0.1,
input_connectivity: float = 0.1,
Win: ~numpy.ndarray | ~scipy.sparse._base.sparray | ~typing.Callable = functools.partial(_uniform(),
low=0.0),
W: ~numpy.ndarray | ~scipy.sparse._base.sparray | ~typing.Callable = functools.partial(_uniform(),
low=0.0),
input_dim: int | None = None,
dtype: type = <class 'numpy.float64'>,
seed: int | ~numpy.random._generator.Generator | None = None,
name: str | None = None,
)[source]#

Pool of leaky integrate and fire (LIF) spiking neurons with random recurrent connexions.

This node is similar to a reservoir (large pool of recurrent, randomly connected neurons), but the neurons follows a leaky integrate and fire activity rule.

Parameters:
  • units (int, optional) – Number of reservoir units. If None, the number of units will be inferred from the W matrix shape.

  • inhibitory (float, defaults to 0.0) – Proportion of neurons that have an inhibitory behavior (i.e. negative outgoing connections). Must be in \([0, 1]\)

  • threshold (float, defaults to 1.0) – Limits above which the neurons spikes and returns to zero.

  • lr (float or array-like of shape (units,), default to 1.0) – Neurons leak rate. Must be in \([0, 1]\).

  • sr (float, defaults to 1.0) – Spectral radius of recurrent weight matrix.

  • input_scaling (float or array-like of shape (features,), default to 1.0.) – Input gain. An array of the same dimension as the inputs can be used to set up different input scaling for each feature.

  • rc_connectivity (float, defaults to 0.1) – Connectivity of recurrent weight matrix, i.e. ratio of reservoir neurons connected to other reservoir neurons, including themselves. Must be in \(]0, 1]\).

  • input_connectivity (float, default to 0.1) – Connectivity of input neurons, i.e. ratio of input neurons connected to reservoir neurons. Must be in \(]0, 1]\).

  • Win (callable or array-like of shape (units, features), default to uniform() with a) – lower bound of 0.0. Input weights matrix or initializer. If a callable (like a function) is used, then this function should accept any keywords parameters and at least two parameters that will be used to define the shape of the returned weight matrix.

  • W (callable or array-like of shape (units, units), defaults to uniform() with) – a lower bound of 0.0. Recurrent weights matrix or initializer. If a callable (like a function) is used, then this function should accept any keywords parameters and at least two parameters that will be used to define the shape of the returned weight matrix.

  • input_dim (int, optional) – Input dimension. Can be inferred at first call.

  • dtype (Numpy dtype, default to np.float64) – Numerical type for node parameters.

  • seed (int or numpy.random.Generator, optional) – A random state seed, for noise generation.

  • name (str, optional) – Node name.

Note

If W, Win, bias or Wfb are initialized with an array-like matrix, then all initializers parameters such as spectral radius (sr) or input scaling (input_scaling) are ignored. See mat_gen for more information.

Example

>>> from reservoirpy.nodes import LIF
>>> liquid = LIF(
...     units=100,
...     inhibitory=0.1,
...     sr=1.0,
...     lr=0.2,
...     input_scaling=0.5,
...     rc_connectivity=1.0,
...     input_connectivity=1.0,
...     seed=0,
... )

Using the mackey_glass() timeseries:

>>> from reservoirpy.datasets import mackey_glass
>>> x = mackey_glass(1000)
>>> spikes = liquid.run(x)
../../_images/reservoirpy-nodes-LIF-1.png

Methods

__init__([units, inhibitory, threshold, lr, ...])

initialize(x[, y])

Define input and output dimensions, and instantiate variables.

predict([x, iters, workers])

Alias for run()

reset()

Reset all Node state

run([x, iters, workers])

Run the Node on a sequence of data.

step([x])

Call the Node function on a single step of data and update the state of the Node.

Attributes

initialized

True if the Node has been initialized

input_dim

Expected dimension of the Node input.

name

Optional name of the Node.

output_dim

Expected dimension of the Node input.

units

Number of neuronal units in the reservoir.

inhibitory

Proportion of inhibitory neurons.

threshold

Spike threshold.

dtype

Type of matrices elements.

lr

Leaking rate (1.0 by default) (\(\mathrm{lr}\)).

sr

Spectral radius of W (optional).

input_scaling

Input scaling (float or array) (1.0 by default).

input_connectivity

Connectivity (or density) of Win (0.1 by default).

rc_connectivity

Connectivity (or density) of Wfb (0.1 by default).

Win

Input weights matrix (\(\mathbf{W}_{in}\)).

W

Recurrent weights matrix (\(\mathbf{W}\)).

rng

A random state generator.

state

Current state of the Node.

W: ndarray | sparray | Callable#

Recurrent weights matrix (\(\mathbf{W}\)).

Win: ndarray | sparray | Callable#

Input weights matrix (\(\mathbf{W}_{in}\)).

dtype: type#

Type of matrices elements. By default, np.float64.

inhibitory: float#

Proportion of inhibitory neurons. (0.0 by default)

initialize(
x: Array2D | Array3D | Sequence[Timeseries] | Array1D | None,
y: None = None,
)[source]#

Define input and output dimensions, and instantiate variables.

Only called once, before fitting or running the node.

Parameters:
  • x (array of shape (input_dim,) or (timestep, input_dim)) – Input data to the node.

  • y (None) – Training data to the node. As it is not a trainable node, y is expected to be None.

initialized: bool = False#

True if the Node has been initialized

input_connectivity: float#

Connectivity (or density) of Win (0.1 by default).

input_dim: int = None#

Expected dimension of the Node input. Can be None before initialization

input_scaling: float | Sequence#

Input scaling (float or array) (1.0 by default).

lr: float | ndarray#

Leaking rate (1.0 by default) (\(\mathrm{lr}\)).

name: str | None = None#

Optional name of the Node.

output_dim: int = None#

Expected dimension of the Node input. Can be None before initialization

predict(
x: array(t, d) | array(s, t, d) | ~typing.Sequence[array(t, d)] | None = None,
iters: int | None = None,
workers=1,
) array(t, d) | array(s, t, d) | ~typing.Sequence[array(t, d)][source]#

Alias for run()

Run the Node on a sequence of data. Can update the state of the Node several times.

Parameters:
  • x (array-like of shape ([n_inputs,] timesteps, input_dim) or list of) – arrays of shape (timesteps, input_dim), optional A sequence of data of shape (timesteps, features).

  • iters (int, optional) – If x is None, a dimensionless timeseries of length iters is used instead.

  • workers (int, default to 1) – Number of workers used for parallelization. If set to -1, all available workers (threads or processes) are used.

Returns:

A sequence of output vectors.

Return type:

array of shape ([n_inputs,] timesteps, output_dim) or list of arrays

rc_connectivity: float#

Connectivity (or density) of Wfb (0.1 by default).

reset() dict[str, ndarray][source]#

Reset all Node state

Returns:

dict[str, np.array]

Return type:

previous state of the Node.

rng: Generator#

A random state generator. Used for generating Win and W.

run(
x: array(t, d) | array(s, t, d) | ~typing.Sequence[array(t, d)] | None = None,
iters: int | None = None,
workers=1,
) array(t, d) | array(s, t, d) | ~typing.Sequence[array(t, d)][source]#

Run the Node on a sequence of data. Can update the state of the Node several times.

Parameters:
  • x (array-like of shape ([n_inputs,] timesteps, input_dim) or list of arrays of shape (timesteps, input_dim), optional) – A timeseries, array of shape (timesteps, features), or a sequence of timeseries. Input of the Node.

  • iters (int, optional) – If x is None, a dimensionless timeseries of length iters is used instead.

  • workers (int, default to 1) – Number of workers used for parallelization. If set to -1, all available workers (threads or processes) are used.

Returns:

A sequence of output vectors.

Return type:

array of shape ([n_inputs,] timesteps, output_dim) or list of arrays

sr: float#

Spectral radius of W (optional).

state: dict[str, ndarray]#

Current state of the Node. Must have “out” as one of the keys.

step(x: array(d) | None = None)[source]#

Call the Node function on a single step of data and update the state of the Node.

Parameters:

x (array of shape (input_dim,), optional) – One single step of input data. If None, an empty array is used instead and the Node is assumed to have an input_dim of 0

Returns:

An output vector.

Return type:

array of shape (output_dim,)

threshold: float#

Spike threshold. (1.0 by default)

units: int#

Number of neuronal units in the reservoir.