Forecaster API Reference¶
The orc.forecaster subpackage provides reservoir computing models for time series forecasting.
Base Classes¶
RCForecasterBase ¶
RCForecasterBase(driver: DriverBase, readout: ReadoutBase, embedding: EmbedBase, chunks: int = 0, dtype: Float = float64, seed: int = 0)
Bases: Module, ABC
Base class for reservoir computer forecasters.
Defines the interface for the reservoir computer which includes the driver, readout and embedding layers.
Attributes:
| Name | Type | Description |
|---|---|---|
driver |
DriverBase
|
Driver layer of the reservoir computer. |
readout |
ReadoutBase
|
Readout layer of the reservoir computer. |
embedding |
EmbedBase
|
Embedding layer of the reservoir computer. |
in_dim |
int
|
Dimension of the input data. |
out_dim |
int
|
Dimension of the output data. |
res_dim |
int
|
Dimension of the reservoir. |
chunks |
int
|
Number of parallel reservoirs. |
dtype |
type
|
Data type of the reservoir computer (jnp.float64 is highly recommended). |
seed |
int
|
Random seed for generating the PRNG key for the reservoir computer. |
Methods:
| Name | Description |
|---|---|
force |
Teacher forces the reservoir with the input sequence. |
set_readout |
Replaces the readout layer of the reservoir computer. |
set_embedding |
Replaces the embedding layer of the reservoir computer. |
forecast |
Forecast from an initial reservoir state. |
forecast_from_IC |
Forecast from a sequence of spinup data. |
Initialize RCForecaster Base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
driver
|
DriverBase
|
Driver layer of the reservoir computer. |
required |
readout
|
ReadoutBase
|
Readout layer of the reservoir computer. |
required |
embedding
|
EmbedBase
|
Embedding layer of the reservoir computer. |
required |
chunks
|
int
|
Number of parallel reservoirs. |
0
|
dtype
|
type
|
Data type of the reservoir computer (jnp.float64 is highly recommended). |
float64
|
seed
|
int
|
Random seed for generating the PRNG key for the reservoir computer. |
0
|
Source code in src/orc/forecaster/base.py
force ¶
Teacher forces the reservoir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_seq
|
Array
|
Input sequence to force the reservoir, (shape=(seq_len, data_dim)). |
required |
res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forced reservoir sequence, (shape=(seq_len, chunks, res_dim)). |
Source code in src/orc/forecaster/base.py
__call__ ¶
Teacher forces the reservoir, wrapper for force method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_seq
|
Array
|
Input sequence to force the reservoir, (shape=(seq_len, data_dim)). |
required |
res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forced reservoir sequence, (shape=(seq_len, chunks, res_dim)). |
Source code in src/orc/forecaster/base.py
set_readout ¶
set_readout(readout: ReadoutBase)
Replace readout layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
readout
|
ReadoutBase
|
New readout layer. |
required |
Returns:
| Type | Description |
|---|---|
RCForecasterBase
|
Updated model with new readout layer. |
Source code in src/orc/forecaster/base.py
set_embedding ¶
set_embedding(embedding: EmbedBase)
Replace embedding layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
|
EmbedBase
|
New embedding layer. |
required |
Returns:
| Type | Description |
|---|---|
RCForecasterBase
|
Updated model with new embedding layer. |
Source code in src/orc/forecaster/base.py
forecast ¶
Forecast from an initial reservoir state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fcast_len
|
int
|
Steps to forecast. |
required |
res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forecasted states, (shape=(fcast_len, data_dim)) |
Source code in src/orc/forecaster/base.py
forecast_from_IC ¶
Forecast from a sequence of spinup data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fcast_len
|
int
|
Steps to forecast. |
required |
spinup_data
|
Array
|
Initial condition sequence, (shape=(seq_len, data_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forecasted states, (shape=(fcast_len, data_dim)). |
Source code in src/orc/forecaster/base.py
CRCForecasterBase ¶
CRCForecasterBase(driver: DriverBase, readout: ReadoutBase, embedding: EmbedBase, chunks: int = 0, dtype: Float = float64, seed: int = 0, solver: AbstractSolver = None, stepsize_controller: AbstractAdaptiveStepSizeController = None)
Bases: RCForecasterBase, ABC
Base class for continuous reservoir computer forecasters.
Override the force and forecast methods of RCForecasterBase to timestep the RC forward using a continuous time ODE solver.
Attributes:
| Name | Type | Description |
|---|---|---|
driver |
DriverBase
|
Driver layer of the reservoir computer. |
readout |
ReadoutBase
|
Readout layer of the reservoir computer. |
embedding |
EmbedBase
|
Embedding layer of the reservoir computer. |
in_dim |
int
|
Dimension of the input data. |
out_dim |
int
|
Dimension of the output data. |
res_dim |
int
|
Dimension of the reservoir. |
chunks |
int
|
Number of parallel reservoirs. |
dtype |
type
|
Data type of the reservoir computer (jnp.float64 is highly recommended). |
seed |
int
|
Random seed for generating the PRNG key for the reservoir computer. |
solver |
Solver
|
ODE solver to use for the reservoir computer. |
stepsize_controller |
StepsizeController
|
Stepsize controller to use for the ODE solver. |
Methods:
| Name | Description |
|---|---|
force |
Teacher forces the reservoir with the input sequence. |
set_readout |
Replaces the readout layer of the reservoir computer. |
set_embedding |
Replaces the embedding layer of the reservoir computer. |
forecast |
Forecast from an initial reservoir state. |
forecast_from_IC |
Forecast from a sequence of spinup data. |
Initialize the continuous reservoir computer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
driver
|
DriverBase
|
Driver layer of the reservoir computer. |
required |
readout
|
ReadoutBase
|
Readout layer of the reservoir computer. |
required |
embedding
|
EmbedBase
|
Embedding layer of the reservoir computer. |
required |
chunks
|
int
|
Number of parallel reservoirs. |
0
|
dtype
|
type
|
Data type of the reservoir computer (jnp.float64 is highly recommended). |
float64
|
seed
|
int
|
Random seed for generating the PRNG key for the reservoir computer. |
0
|
solver
|
AbstractSolver
|
ODE solver to use for the reservoir computer. |
None
|
stepsize_controller
|
AbstractAdaptiveStepSizeController
|
Stepsize controller to use for the ODE solver. |
None
|
Source code in src/orc/forecaster/base.py
force ¶
Teacher forces the reservoir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_seq
|
Array
|
Input sequence to force the reservoir, (shape=(seq_len, data_dim)). |
required |
res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
required |
ts
|
Array
|
Time steps for the input sequence, (shape=(seq_len,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forced reservoir sequence, (shape=(seq_len, chunks, res_dim)). |
Source code in src/orc/forecaster/base.py
__call__ ¶
Teacher forces the reservoir, wrapper for force method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_seq
|
Array
|
Input sequence to force the reservoir, (shape=(seq_len, data_dim)). |
required |
res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
required |
ts
|
Array
|
Time steps for the input sequence, (shape=(seq_len,)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forced reservoir sequence, (shape=(seq_len, chunks, res_dim)). |
Source code in src/orc/forecaster/base.py
forecast ¶
Forecast from an initial reservoir state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Array
|
Time steps for the forecast, (shape=(fcast_len,)). |
required |
res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim)). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Forecasted states, (shape=(fcast_len, data_dim)) |
Source code in src/orc/forecaster/base.py
forecast_from_IC ¶
Forecast from a sequence of spinup data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Array
|
Time steps for the forecast, (shape=(fcast_len,)). |
required |
spinup_data
|
Array
|
Initial condition sequence, (shape=(seq_len, data_dim)). |
required |
spinup_ts
|
Array
|
Time steps for the spinup data, (shape=(seq_len,)). If None, the spinup data is assumed to have the same dt as the forecast data. If not None, the spinup data Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Forecasted states, (shape=(fcast_len, data_dim)). |
Source code in src/orc/forecaster/base.py
Models¶
ESNForecaster ¶
ESNForecaster(data_dim: int, res_dim: int, leak_rate: float = 0.6, bias: float = 1.6, embedding_scaling: float = 0.08, Wr_density: float = 0.02, Wr_spectral_radius: float = 0.8, dtype: type = float64, seed: int = 0, chunks: int = 1, locality: int = 0, quadratic: bool = False, periodic: bool = True, use_sparse_eigs: bool = True)
Bases: RCForecasterBase
Basic implementation of ESN for forecasting.
Attributes:
| Name | Type | Description |
|---|---|---|
res_dim |
int
|
Reservoir dimension. |
data_dim |
int
|
Input/output dimension. |
driver |
ParallelESNDriver
|
Driver implmenting the Echo State Network dynamics. |
readout |
BaseReadout
|
Trainable linear readout layer. |
embedding |
ParallelLinearEmbedding
|
Untrainable linear embedding layer. |
Methods:
| Name | Description |
|---|---|
force |
Teacher forces the reservoir with sequence in_seq and init. cond. res_state. |
forecast |
Perform a forecast of fcast_len steps from res_state. |
forecast_from_IC |
Forecast from a sequence of spinup data. |
set_readout |
Replace readout layer. |
set_embedding |
Replace embedding layer. |
Initialize the ESN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dim
|
int
|
Dimension of the input data. |
required |
res_dim
|
int
|
Dimension of the reservoir adjacency matrix Wr. |
required |
leak_rate
|
float
|
Integration leak rate of the reservoir dynamics. |
0.6
|
bias
|
float
|
Bias term for the reservoir dynamics. |
1.6
|
embedding_scaling
|
float
|
Scaling factor for the embedding layer. |
0.08
|
Wr_density
|
float
|
Density of the reservoir adjacency matrix Wr. |
0.02
|
Wr_spectral_radius
|
float
|
Largest eigenvalue of the reservoir adjacency matrix Wr. |
0.8
|
dtype
|
type
|
Data type of the model (jnp.float64 is highly recommended). |
float64
|
seed
|
int
|
Random seed for generating the PRNG key for the reservoir computer. |
0
|
chunks
|
int
|
Number of parallel reservoirs, must evenly divide data_dim. |
1
|
locality
|
int
|
Overlap in adjacent parallel reservoirs. |
0
|
quadratic
|
bool
|
Use quadratic nonlinearity in output, default False. |
False
|
periodic
|
bool
|
Periodic BCs for embedding layer. |
True
|
use_sparse_eigs
|
bool
|
Whether to use sparse eigensolver for setting the spectral radius of wr. Default is True, which is recommended to save memory and compute time. If False, will use dense eigensolver which may be more accurate. |
True
|
Source code in src/orc/forecaster/models.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
CESNForecaster ¶
CESNForecaster(data_dim: int, res_dim: int, time_const: float = 50.0, bias: float = 1.6, embedding_scaling: float = 0.08, Wr_density: float = 0.02, Wr_spectral_radius: float = 0.8, dtype: type = float64, seed: int = 0, chunks: int = 1, locality: int = 0, quadratic: bool = False, periodic: bool = True, use_sparse_eigs: bool = True, solver: AbstractSolver = None, stepsize_controller: AbstractAdaptiveStepSizeController = None)
Bases: CRCForecasterBase
Basic implementation of a Continuous ESN for forecasting.
Attributes:
| Name | Type | Description |
|---|---|---|
res_dim |
int
|
Reservoir dimension. |
data_dim |
int
|
Input/output dimension. |
driver |
ParallelESNDriver
|
Driver implementing the Echo State Network dynamics in continuous time. |
readout |
BaseReadout
|
Trainable linear readout layer. |
embedding |
ParallelLinearEmbedding
|
Untrainable linear embedding layer. |
Methods:
| Name | Description |
|---|---|
force |
Teacher forces the reservoir with sequence in_seq and init. cond. res_state. |
forecast |
Perform a forecast of fcast_len steps from res_state. |
forecast_from_IC |
Forecast from a sequence of spinup data. |
set_readout |
Replace readout layer. |
set_embedding |
Replace embedding layer. |
Initialize the CESN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dim
|
int
|
Dimension of the input data. |
required |
res_dim
|
int
|
Dimension of the reservoir adjacency matrix Wr. |
required |
time_const
|
float
|
Time constant of the reservoir dynamics. |
50.0
|
bias
|
float
|
Bias term for the reservoir dynamics. |
1.6
|
embedding_scaling
|
float
|
Scaling factor for the embedding layer. |
0.08
|
Wr_density
|
float
|
Density of the reservoir adjacency matrix Wr. |
0.02
|
Wr_spectral_radius
|
float
|
Largest eigenvalue of the reservoir adjacency matrix Wr. |
0.8
|
dtype
|
type
|
Data type of the model (jnp.float64 is highly recommended). |
float64
|
seed
|
int
|
Random seed for generating the PRNG key for the reservoir computer. |
0
|
chunks
|
int
|
Number of parallel reservoirs, must evenly divide data_dim. |
1
|
locality
|
int
|
Overlap in adjacent parallel reservoirs. |
0
|
quadratic
|
bool
|
Use quadratic nonlinearity in output, default False. |
False
|
periodic
|
bool
|
Periodic BCs for embedding layer. |
True
|
use_sparse_eigs
|
bool
|
Whether to use sparse eigensolver for setting the spectral radius of wr. Default is True, which is recommended to save memory and compute time. If False, will use dense eigensolver which may be more accurate. |
True
|
Source code in src/orc/forecaster/models.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
EnsembleESNForecaster ¶
EnsembleESNForecaster(data_dim: int, res_dim: int, leak_rate: float = 0.6, bias: float = 1.6, embedding_scaling: float = 0.08, Wr_density: float = 0.02, Wr_spectral_radius: float = 0.8, dtype: type = float64, seed: int = 0, chunks: int = 1, use_sparse_eigs: bool = True)
Bases: RCForecasterBase
Ensembled ESNs for forecasting.
Attributes:
| Name | Type | Description |
|---|---|---|
res_dim |
int
|
Reservoir dimension. |
data_dim |
int
|
Input/output dimension. |
driver |
ParallelESNDriver
|
Driver implmenting the Echo State Network dynamics. |
readout |
EnsembleLinearReadout
|
Trainable linear readout layer. |
embedding |
EnsembleLinearEmbedding
|
Untrainable linear embedding layer. |
Methods:
| Name | Description |
|---|---|
force |
Teacher forces the reservoir with sequence in_seq and init. cond. res_state. |
forecast |
Perform a forecast of fcast_len steps from res_state. |
forecast_from_IC |
Forecast from a sequence of spinup data. |
set_readout |
Replace readout layer. |
set_embedding |
Replace embedding layer. |
Initialize the ESN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dim
|
int
|
Dimension of the input data. |
required |
res_dim
|
int
|
Dimension of the reservoir adjacency matrix Wr. |
required |
leak_rate
|
float
|
Integration leak rate of the reservoir dynamics. |
0.6
|
bias
|
float
|
Bias term for the reservoir dynamics. |
1.6
|
embedding_scaling
|
float
|
Scaling factor for the embedding layer. |
0.08
|
Wr_density
|
float
|
Density of the reservoir adjacency matrix Wr. |
0.02
|
Wr_spectral_radius
|
float
|
Largest eigenvalue of the reservoir adjacency matrix Wr. |
0.8
|
dtype
|
type
|
Data type of the model (jnp.float64 is highly recommended). |
float64
|
seed
|
int
|
Random seed for generating the PRNG key for the reservoir computer. |
0
|
chunks
|
int
|
Number of parallel reservoirs, must evenly divide data_dim. |
1
|
use_sparse_eigs
|
bool
|
Whether to use sparse eigensolver for setting the spectral radius of wr. Default is True, which is recommended to save memory and compute time. If False, will use dense eigensolver which may be more accurate. |
True
|
Source code in src/orc/forecaster/models.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
Training Functions¶
train_ESNForecaster ¶
train_ESNForecaster(model: ESNForecaster, train_seq: Array, target_seq: Array = None, spinup: int = 0, initial_res_state: Array = None, beta: float = 8e-08, batch_size: int = None) -> tuple[ESNForecaster, Array]
Training function for ESNForecaster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ESNForecaster
|
ESNForecaster model to train. |
required |
train_seq
|
Array
|
Training input sequence for reservoir, (shape=(seq_len, data_dim)). |
required |
target_seq
|
Array
|
Target sequence for training reservoir, (shape=(seq_len, data_dim)). |
None
|
initial_res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
None
|
spinup
|
int
|
Initial transient of reservoir states to discard. |
0
|
beta
|
float
|
Tikhonov regularization parameter. |
8e-08
|
batch_size
|
int
|
Number of parallel reservoirs to process in each batch for ridge regression. If None (default), processes all reservoirs at once. Use smaller values to reduce memory usage for large numbers of parallel reservoirs. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
model |
ESNForecaster
|
Trained ESN model. |
res_seq |
Array
|
Training sequence of reservoir states. |
Source code in src/orc/forecaster/train.py
train_CESNForecaster ¶
train_CESNForecaster(model: CESNForecaster, train_seq: Array, t_train: Array, target_seq: Array = None, spinup: int = 0, initial_res_state: Array = None, beta: float = 8e-08, batch_size: int = None) -> tuple[CESNForecaster, Array]
Training function for CESNForecaster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CESNForecaster
|
CESNForecaster model to train. |
required |
train_seq
|
Array
|
Training input sequence for reservoir, (shape=(seq_len, data_dim)). |
required |
t_train
|
Array
|
time vector corresponding to the training sequence, (shape=(seq_len,)). |
required |
target_seq
|
Array
|
Target sequence for training reservoir, (shape=(seq_len, data_dim)). |
None
|
initial_res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
None
|
spinup
|
int
|
Initial transient of reservoir states to discard. |
0
|
beta
|
float
|
Tikhonov regularization parameter. |
8e-08
|
batch_size
|
int
|
Number of parallel reservoirs to process in each batch for ridge regression. If None (default), processes all reservoirs at once. Use smaller values to reduce memory usage for large numbers of parallel reservoirs. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
model |
CESNForecaster
|
Trained CESN model. |
res_seq |
Array
|
Training sequence of reservoir states. |
Source code in src/orc/forecaster/train.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
train_EnsembleESNForecaster ¶
train_EnsembleESNForecaster(model: EnsembleESNForecaster, train_seq: Array, target_seq: Array | None = None, spinup: int = 0, initial_res_state: Array | None = None, beta: float = 8e-08, batch_size: int | None = None) -> tuple[ESNForecaster, Array]
Training function for ESNForecaster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ESNForecaster
|
ESNForecaster model to train. |
required |
train_seq
|
Array
|
Training input sequence for reservoir, (shape=(seq_len, data_dim)). |
required |
target_seq
|
Array
|
Target sequence for training reservoir, (shape=(seq_len, data_dim)). |
None
|
initial_res_state
|
Array
|
Initial reservoir state, (shape=(chunks, res_dim,)). |
None
|
spinup
|
int
|
Initial transient of reservoir states to discard. |
0
|
beta
|
float
|
Tikhonov regularization parameter. |
8e-08
|
batch_size
|
int
|
Number of parallel reservoirs to process in each batch for ridge regression. If None (default), processes all reservoirs at once. Use smaller values to reduce memory usage for large numbers of parallel reservoirs. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
model |
ESNForecaster
|
Trained ESN model. |
res_seq |
Array
|
Training sequence of reservoir states. |
Source code in src/orc/forecaster/train.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |