reservoirpy.nodes.Identity#

class reservoirpy.nodes.Identity(**kwargs)[source]#

Identity function.

\[f(x) = x\]

Provided for convenience.

Identity.hypers list

f

Activation function (reservoir.activationsfunc.identity()).

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

  • name (str, optional) – Node name.

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

Methods

__init__(**kwargs)

call(x[, from_state, stateful, reset])

Call the Node forward function on a single step of data.

clean_buffers()

Clean Node's buffer arrays.

copy([name, copy_feedback, shallow])

Returns a copy of the Node.

create_buffer(name[, shape, data, as_memmap])

Create a buffer array on disk, using numpy.memmap.

feedback()

State of the Nodes connected to this Node through feedback connections.

fit([X, Y, warmup])

Offline fitting method of a Node.

get_buffer(name)

Get data from a buffer array.

get_param(name)

Get one of the parameters or hyperparameters given its name.

initialize([x, y])

Call the Node initializers on some data points.

initialize_buffers()

Call the Node buffer initializer.

initialize_feedback()

Call the Node feedback initializer.

link_feedback(node[, inplace, name])

Create a feedback connection between the Node and another Node or Model.

partial_fit(X_batch[, Y_batch, warmup])

Partial offline fitting method of a Node.

reset([to_state])

Reset the last state saved to zero or to another state value to_state.

run(X[, from_state, stateful, reset])

Run the Node forward function on a sequence of data.

set_buffer(name, value)

Dump data in the buffer array.

set_feedback_dim(value)

Set the feedback dimension of the Node.

set_input_dim(value)

Set the input dimension of the Node.

set_output_dim(value)

Set the output dimension of the Node.

set_param(name, value)

Set the value of a parameter.

set_state_proxy([value])

Change the frozen state of the Node.

state()

Node current internal state.

state_proxy()

Returns the internal state frozen to be sent to other Nodes, connected through a feedback connection.

train(X[, Y, force_teachers, call, ...])

Train the Node parameters using an online learning rule, if available.

with_feedback([feedback, stateful, reset])

Modify the feedback received or sent by the Node using a context manager.

with_state([state, stateful, reset])

Modify the state of the Node using a context manager.

zero_feedback()

A null feedback vector.

zero_state()

A null state vector.

Attributes

dtype

Numpy numerical type of node parameters.

feedback_dim

Node feedback signal dimension.

fitted

Returns if the Node parameters have fitted already, using an offline learning rule.

has_feedback

Returns if the Node receives feedback or not.

hypers

Hyperparameters of the Node or Model.

input_dim

Node input dimension.

is_fb_initialized

Returns if the Node feedback initializer has been called already.

is_initialized

Returns if the Node is initialized or not.

is_trainable

Returns if the Node can be trained.

is_trained_offline

Returns if the Node can be fitted offline or not.

is_trained_online

Returns if the Node can be trained online or not.

name

Name of the Node or Model.

output_dim

Node output and internal state dimension.

params

Parameters of the Node or Model.

unsupervised

call(x, from_state=None, stateful=True, reset=False)[source]#

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

Parameters:
  • x (array of shape ([n_inputs], 1, input_dim)) – One single step of input data.

  • from_state (array of shape (1, output_dim), optional) – Node state value to use at beginning of computation.

  • stateful (bool, default to True) – If True, Node state will be updated by this operation.

  • reset (bool, default to False) – If True, Node state will be reset to zero before this operation.

Returns:

An output vector.

Return type:

array of shape (1, output_dim)

clean_buffers()[source]#

Clean Node’s buffer arrays.

copy(name=None, copy_feedback=False, shallow=False)[source]#

Returns a copy of the Node.

Parameters:
  • name (str) – Name of the Node copy.

  • copy_feedback (bool, default to False) – If True, also copy the Node feedback senders.

  • shallow (bool, default to False) – If False, performs a deep copy of the Node.

Returns:

A copy of the Node.

Return type:

Node

create_buffer(name, shape=None, data=None, as_memmap=True)[source]#

Create a buffer array on disk, using numpy.memmap. This can be used to store transient variables on disk. Typically, called inside a buffers_initializer function.

Parameters:
  • name (str) – Name of the buffer array.

  • shape (tuple of int, optional) – Shape of the buffer array.

  • data (array-like) – Data to store in the buffer array.

property dtype#

Numpy numerical type of node parameters.

feedback()[source]#

State of the Nodes connected to this Node through feedback connections.

Returns:

State of the feedback Nodes, i.e. the feedback signal.

Return type:

array-like of shape ([n_feedbacks], 1, feedback_dim), optional

property feedback_dim#

Node feedback signal dimension.

fit(X=None, Y=None, warmup=0)[source]#

Offline fitting method of a Node.

Parameters:
  • X (array-like of shape ([n_inputs], [series], timesteps, input_dim), optional) – Input sequences dataset. If None, the method will try to fit the parameters of the Node using the precomputed values returned by previous call of partial_fit().

  • Y (array-like of shape ([series], timesteps, output_dim), optional) – Teacher signals dataset. If None, the method will try to fit the parameters of the Node using the precomputed values returned by previous call of partial_fit(), or to fit the Node in an unsupervised way, if possible.

  • warmup (int, default to 0) – Number of timesteps to consider as warmup and discard at the beginning of each timeseries before training.

Returns:

Node trained offline.

Return type:

Node

property fitted#

Returns if the Node parameters have fitted already, using an offline learning rule. If the node is trained online, returns True.

get_buffer(name)[source]#

Get data from a buffer array.

Parameters:

name (str) – Name of the buffer array.

Returns:

Data as Numpy memory map.

Return type:

numpy.memmap

get_param(name)[source]#

Get one of the parameters or hyperparameters given its name.

property has_feedback#

Returns if the Node receives feedback or not.

property hypers#

Hyperparameters of the Node or Model.

initialize(x=None, y=None)[source]#

Call the Node initializers on some data points. Initializers are functions called at first run of the Node, defining the dimensions and values of its parameters based on the dimension of some input data and its hyperparameters.

Data point x is used to infer the input dimension of the Node. Data point y is used to infer the output dimension of the Node.

Parameters:
  • x (array-like of shape ([n_inputs], 1, input_dim)) – Input data.

  • y (array-like of shape (1, output_dim)) – Ground truth data. Used to infer output dimension of trainable nodes.

Returns:

Initialized Node.

Return type:

Node

initialize_buffers()[source]#

Call the Node buffer initializer. The buffer initializer will create buffer array on demand to store transient values of the parameters, typically during training.

Returns:

Initialized Node.

Return type:

Node

initialize_feedback()[source]#

Call the Node feedback initializer. The feedback initializer will determine feedback dimension given some feedback signal, and initialize all parameters related to the feedback connection.

Feedback sender Node must be initialized, as the feedback initializer will probably call the Node.feedback() method to get a sample of feedback signal.

Returns:

Initialized Node.

Return type:

Node

property input_dim#

Node input dimension.

property is_fb_initialized#

Returns if the Node feedback initializer has been called already.

property is_initialized#

Returns if the Node is initialized or not.

property is_trainable#

Returns if the Node can be trained.

property is_trained_offline#

Returns if the Node can be fitted offline or not.

property is_trained_online#

Returns if the Node can be trained online or not.

Create a feedback connection between the Node and another Node or Model.

Parameters:
  • node (Node or Model) – Feedback sender Node or Model.

  • inplace (bool, default to False) – If False, then this function returns a copy of the current Node with feedback enabled. If True, feedback is directly added to the current Node.

  • name (str, optional) – Name of the node copy, if inplace is False.

Returns:

A Node with a feedback connection.

Return type:

Node

property name#

Name of the Node or Model.

property output_dim#

Node output and internal state dimension.

property params#

Parameters of the Node or Model.

partial_fit(X_batch, Y_batch=None, warmup=0, **kwargs)[source]#

Partial offline fitting method of a Node. Can be used to perform batched fitting or to pre-compute some variables used by the fitting method.

Parameters:
  • X_batch (array-like of shape ([n_inputs], [series], timesteps, input_dim)) – A sequence or a batch of sequence of input data.

  • Y_batch (array-like of shape ([series], timesteps, output_dim), optional) – A sequence or a batch of sequence of teacher signals.

  • warmup (int, default to 0) – Number of timesteps to consider as warmup and discard at the beginning of each timeseries before training.

Returns:

Partially fitted Node.

Return type:

Node

reset(to_state=None)[source]#

Reset the last state saved to zero or to another state value to_state.

Parameters:

to_state (array of shape (1, output_dim), optional) – New state value.

Returns:

Reset Node.

Return type:

Node

run(X, from_state=None, stateful=True, reset=False)[source]#

Run the Node forward function 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)) – A sequence of data of shape (timesteps, features).

  • from_state (array of shape (1, output_dim), optional) – Node state value to use at beginning of computation.

  • stateful (bool, default to True) – If True, Node state will be updated by this operation.

  • reset (bool, default to False) – If True, Node state will be reset to zero before this operation.

Returns:

A sequence of output vectors.

Return type:

array of shape (timesteps, output_dim)

set_buffer(name, value)[source]#

Dump data in the buffer array.

Parameters:
  • name (str) – Name of the buffer array.

  • value (array-like) – Data to store in the buffer array.

set_feedback_dim(value)[source]#

Set the feedback dimension of the Node. Can only be called once, during Node initialization.

set_input_dim(value)[source]#

Set the input dimension of the Node. Can only be called once, during Node initialization.

set_output_dim(value)[source]#

Set the output dimension of the Node. Can only be called once, during Node initialization.

set_param(name, value)[source]#

Set the value of a parameter.

Parameters:
  • name (str) – Parameter name.

  • value (array-like) – Parameter new value.

set_state_proxy(value=None)[source]#

Change the frozen state of the Node. Used internally to send the current state to feedback receiver Nodes during the next call.

Parameters:

value (array of shape (1, output_dim)) – State to freeze, waiting to be sent to feedback receivers.

state()[source]#

Node current internal state.

Returns:

Internal state of the Node.

Return type:

array of shape (1, output_dim), optional

state_proxy()[source]#

Returns the internal state frozen to be sent to other Nodes, connected through a feedback connection. This prevents any change occurring on the Node before feedback have reached the other Node to propagate to the other Node to early.

Returns:

Internal state of the Node.

Return type:

array of shape (1, output_dim), optional

train(X, Y=None, force_teachers=True, call=True, learn_every=1, from_state=None, stateful=True, reset=False)[source]#

Train the Node parameters using an online learning rule, if available.

Parameters:
  • X (array-like of shape ([n_inputs], timesteps, input_dim)) – Input sequence of data.

  • Y (array-like of shape (timesteps, output_dim), optional.) – Target sequence of data. If None, the Node will search a feedback signal, or train in an unsupervised way, if possible.

  • force_teachers (bool, default to True) – If True, this Node will broadcast the available ground truth signal to all Nodes using this Node as a feedback sender. Otherwise, the real state of this Node will be sent to the feedback receivers.

  • call (bool, default to True) – It True, call the Node and update its state before applying the learning rule. Otherwise, use the train method on the current state.

  • learn_every (int, default to 1) – Time interval at which training must occur, when dealing with a sequence of input data. By default, the training method is called every time the Node receive an input.

  • from_state (array of shape (1, output_dim), optional) – Node state value to use at beginning of computation.

  • stateful (bool, default to True) – If True, Node state will be updated by this operation.

  • reset (bool, default to False) – If True, Node state will be reset to zero before this operation.

Returns:

All outputs computed during the training. If call is False, outputs will be the result of Node.zero_state().

Return type:

array of shape (timesteps, output_dim)

with_feedback(feedback=None, stateful=False, reset=False)#

Modify the feedback received or sent by the Node using a context manager. The modification will have effect only within the context defined, before the feedback returns to its previous state.

If the Node is receiving feedback, then this function will alter the state of the Node connected to it through feedback connections.

If the Node is sending feedback, then this function will alter the state (or state proxy, see Node.state_proxy()) of the Node.

Parameters:
  • feedback (array of shape (1, feedback_dim), optional) – New feedback signal.

  • stateful (bool, default to False) – If set to True, then all modifications made in the context manager will remain after leaving the context.

  • reset (bool, default to False) – If True, the feedback will be reset to zero.

Returns:

Modified Node.

Return type:

Node

with_state(state=None, stateful=False, reset=False)#

Modify the state of the Node using a context manager. The modification will have effect only within the context defined, before the state returns back to its previous value.

Parameters:
  • state (array of shape (1, output_dim), optional) – New state value.

  • stateful (bool, default to False) – If set to True, then all modifications made in the context manager will remain after leaving the context.

  • reset (bool, default to False) – If True, the Node will be reset using its Node.reset() method.

Returns:

Modified Node.

Return type:

Node

zero_feedback()[source]#

A null feedback vector. Returns None if the Node receives no feedback.

zero_state()[source]#

A null state vector.