reservoirpy.nodes.Input#

class reservoirpy.nodes.Input(name: str | None = None)[source]#

Node feeding input data to other nodes in the models.

Allow creating an input source and connecting it to several nodes at once.

This node has no parameters and no hyperparameters.

Parameters:

name (str, optional) – Node name.

Example

An input source feeding three different nodes in parallel.

>>> from reservoirpy.nodes import Reservoir, Input
>>> source = Input()
>>> res1, res2, res3 = Reservoir(100), Reservoir(100), Reservoir(100)
>>> model = source >> [res1, res2, res3]

A model with different input sources. Use names to identify each source at runtime.

>>> import numpy as np
>>> from reservoirpy.nodes import Reservoir, Input
>>> source1, source2 = Input(name="s1"), Input(name="s2")
>>> res1, res2 = Reservoir(100, name="res1"), Reservoir(100, name="res2)
>>> model = source1 >> [res1, res2] & source2 >> [res1, res2]
>>> outputs = model.run({"s1": np.ones((10, 5)), "s2": np.ones((10, 3))})

Methods

__init__([name])

initialize(x)

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

input_dim

Expected dimension of the Node input.

name

Optional name of the Node.

output_dim

Expected dimension of the Node input.

initialized

True if the Node has been initialized

state

Current state of the Node.

initialize(
x: array(t, d) | array(s, t, d) | ~typing.Sequence[array(t, d)] | array(d),
)[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#

True if the Node has been initialized

input_dim: int = None#

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

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.

Returns:

A sequence of output vectors.

Return type:

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

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

Reset all Node state

Returns:

dict[str, np.array]

Return type:

previous state of the Node.

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

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,)