Readouts API Reference¶
This module contains readout layers that map reservoir states to outputs.
Readout Base Class¶
ReadoutBase ¶
Bases: Module, ABC
Base class dictating API for all implemented readout layers.
All readout layers should store their trained weight matrix as wout.
Attributes:
| Name | Type | Description |
|---|---|---|
out_dim |
int
|
Dimension of reservoir output. |
res_dim |
int
|
Reservoir dimension. |
chunks |
int
|
Number of parallel reservoirs. Default is 0 (no chunks dimension). |
dtype |
Float
|
Dtype of JAX arrays, jnp.float32 or jnp.float64. |
Methods:
| Name | Description |
|---|---|
readout |
Map from reservoir state to output state. |
batch_readout |
Map from reservoir states to output states. |
prepare_train |
Prepare reservoir states for ridge regression during training. |
prepare_target |
Prepare target sequence for ridge regression during training. |
set_wout |
Return a new readout with updated output weights. |
Ensure in dim, res dim, and dtype are correct type.
Source code in src/orc/readouts.py
readout
abstractmethod
¶
Readout from reservoir state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_state
|
Array
|
Reservoir state. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Output from reservoir state. |
Source code in src/orc/readouts.py
batch_readout ¶
Batch apply readout from reservoir states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_state
|
Array
|
Reservoir state. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Output from reservoir states. |
Source code in src/orc/readouts.py
__call__ ¶
Call either readout or batch_readout depending on dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_state
|
Array
|
Reservoir state, (shape=(chunks, res_dim) or shape=(seq_len, chunks, res_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Output state, (out_dim,) or shape=(seq_len, out_dim)). |
Source code in src/orc/readouts.py
prepare_train ¶
Prepare reservoir states for ridge regression during training.
By default, returns the reservoir states unchanged. Subclasses may override to apply nonlinear transforms or reshape for chunk structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_seq
|
Array
|
Sequence of reservoir states. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Prepared reservoir states for ridge regression. |
Source code in src/orc/readouts.py
prepare_target ¶
Prepare target sequence for ridge regression during training.
By default, returns the target sequence unchanged. Subclasses may override to reshape for chunk structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_seq
|
Array
|
Target sequence, (shape=(seq_len, out_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Prepared target sequence for ridge regression. |
Source code in src/orc/readouts.py
set_wout ¶
Return a new readout with updated output weights.
Override this method if your readout uses a different attribute name for the output weight matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmat
|
Array
|
New output weight matrix. |
required |
Returns:
| Type | Description |
|---|---|
ReadoutBase
|
New readout with updated weights. |
Source code in src/orc/readouts.py
Linear Readout¶
ParallelLinearReadout ¶
ParallelLinearReadout(out_dim: int, res_dim: int, chunks: int = 1, dtype: Float = float64, *, seed: int = 0)
Bases: ReadoutBase
Linear readout layer.
Attributes:
| Name | Type | Description |
|---|---|---|
out_dim |
int
|
Dimension of reservoir output. |
res_dim |
int
|
Reservoir dimension. |
chunks |
int
|
Number of parallel reservoirs. |
wout |
Array
|
Output matrix. |
dtype |
Float
|
Dtype, default jnp.float64. |
Methods:
| Name | Description |
|---|---|
readout |
Map from reservoir state to output state. |
Initialize readout layer to zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dim
|
int
|
Dimension of reservoir output. |
required |
res_dim
|
int
|
Reservoir dimension. |
required |
chunks
|
int
|
Number of parallel resrevoirs. |
1
|
dtype
|
Float
|
Dtype, default jnp.float64. |
float64
|
seed
|
int
|
Not used for ParallelLinearReadout, here to maintain consistent interface. |
0
|
Source code in src/orc/readouts.py
readout ¶
Readout from reservoir state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_state
|
Array
|
Reservoir state, (shape=(chunks, res_dim,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Output from reservoir, (shape=(out_dim,)). |
Source code in src/orc/readouts.py
prepare_target ¶
Reshape target for parallel chunk structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_seq
|
Array
|
Target sequence, (shape=(seq_len, out_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Reshaped target, (shape=(seq_len, chunks, out_dim/chunks)). |
Source code in src/orc/readouts.py
Nonlinear Readout¶
ParallelNonlinearReadout ¶
ParallelNonlinearReadout(out_dim: int, res_dim: int, nonlin_list: list[Callable], chunks: int = 1, dtype: Float = float64, *, seed: int = 0)
Bases: ReadoutBase
Readout layer with user specified nonlinearities.
Attributes:
| Name | Type | Description |
|---|---|---|
out_dim |
int
|
Dimension of reservoir output. |
res_dim |
int
|
Reservoir dimension. |
chunks |
int
|
Number of parallel reservoirs. |
wout |
Array
|
Output matrix. |
nonlin_list |
list
|
List containing user specified nonlinearities. |
dtype |
Float
|
Dtype, default jnp.float64. |
Methods:
| Name | Description |
|---|---|
nonlinear_transform |
Nonlinear transform that acts entrywise on reservoir state. |
readout |
Map from reservoir state to output state. |
__call__ |
Map from reservoir state to output state, handles batch and single outputs. |
Initialize readout layer to zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dim
|
int
|
Dimension of reservoir output. |
required |
res_dim
|
int
|
Reservoir dimension. |
required |
nonlin_list
|
list[Callable]
|
List containing user specified entrywise nonlinearities. Each entry should be a function mapping a scalar value to another scalar value, e.g. lambda x : x ** 2 or lambda x : jnp.sin(x). |
required |
chunks
|
int
|
Number of parallel reservoirs. |
1
|
dtype
|
Float
|
Dtype, default jnp.float64. |
float64
|
seed
|
int
|
Not used for ParallelNonlinearReadout, here to maintain consistent interface. |
0
|
Source code in src/orc/readouts.py
nonlinear_transform ¶
Perform nonlinear transformation on reservoir state.
Let tot_list be the list consisting of nonlin_list prepended by the identity mapping. Let n be the length of tot_list. Then, nonlinear_transform acts such that for all 0 <= k < chunks and 0 <= j < j * n: res_state[k, j * n] <- res_state[k, j*n] res_state[k, j * n + 1] <- f_0(res_state[k, j * n + 1]) ... res_state[k, j * n + n - 1] <- f_{n-1}(res_state[k, j * n + n - 1]) where f_i is the i-th entry of nonlin_list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_state
|
Array
|
Reservoir state, (shape=(..., res_dim,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Transformed reservoir state. |
Source code in src/orc/readouts.py
readout ¶
Readout from reservoir state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_state
|
Array
|
Reservoir state, (shape=(chunks, res_dim,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Output from reservoir, (shape=(out_dim,)). |
Source code in src/orc/readouts.py
prepare_train ¶
Apply nonlinear transform to reservoir states for ridge regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_seq
|
Array
|
Reservoir states, (shape=(seq_len, chunks, res_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Transformed states, (shape=(seq_len, chunks, res_dim)). |
Source code in src/orc/readouts.py
prepare_target ¶
Reshape target for parallel chunk structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_seq
|
Array
|
Target sequence, (shape=(seq_len, out_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Reshaped target, (shape=(seq_len, chunks, out_dim/chunks)). |
Source code in src/orc/readouts.py
Quadratic Readout¶
ParallelQuadraticReadout ¶
ParallelQuadraticReadout(out_dim: int, res_dim: int, chunks: int = 1, dtype: Float = float64, *, seed: int = 0)
Bases: ParallelNonlinearReadout
Quadratic readout layer.
Attributes:
| Name | Type | Description |
|---|---|---|
out_dim |
int
|
Dimension of reservoir output. |
res_dim |
int
|
Reservoir dimension. |
chunks |
int
|
Number of parallel reservoirs. |
wout |
Array
|
Output matrix. |
dtype |
Float
|
Dtype, default jnp.float64. |
Methods:
| Name | Description |
|---|---|
nonlinear_transform |
Quadratic transform that acts entrywise on reservoir state. |
readout |
Map from reservoir state to output state with quadratic nonlinearity. |
__call__ |
Map from reservoir state to output state with quadratic nonlinearity, handles batch and single outputs. |
Initialize readout layer to zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dim
|
int
|
Dimension of reservoir output. |
required |
res_dim
|
int
|
Reservoir dimension. |
required |
chunks
|
int
|
Number of parallel resrevoirs. |
1
|
dtype
|
Float
|
Dtype, default jnp.float64. |
float64
|
seed
|
int
|
Not used for ParallelQuadraticReadout, here to maintain consistent interface. |
0
|