Reference
Facade¶
A single object that owns the whole reservoir-computing workflow — build,
warmup, algebraic fit, autoregressive forecast — with numpy in and numpy out.
ESN is the estimator-shaped entry point for users who want
fit().forecast() without wiring the pytorch_symbolic graph themselves; its
.model attribute exposes the underlying ESNModel
the moment you outgrow it.
import numpy as np
from resdag import ESN
series = np.cumsum(np.random.randn(2000, 3), axis=0) # (time, features)
esn = ESN(reservoir_size=300, spectral_radius=0.9).fit(series)
prediction = esn.forecast(horizon=200) # numpy (200, 3)
full_model = esn.model # the composable ESNModel
See Start · The mental model
for how fit/forecast map onto ResDAG's warmup + ESNTrainer.fit / rollout
phases.
facade
¶
High-level, opinionated ESN facade — train + forecast in ~10 lines.
This module provides :class:ESN, a single object that owns the end-to-end
reservoir-computing workflow. It hides the symbolic-graph plumbing
(:func:~resdag.models.classic_esn), data slicing, and the
:class:~resdag.training.ESNTrainer ↔ :meth:~resdag.core.ESNModel.forecast
hand-off behind two chainable methods::
from resdag import ESN
esn = ESN(reservoir_size=400, spectral_radius=0.9).fit(series)
prediction = esn.forecast(horizon=500)
It is the friendly front door, not a replacement for the composable
pytorch_symbolic path. The underlying :class:~resdag.core.ESNModel is
always reachable via :attr:ESN.model, so advanced users can drop down to the
full building-block API at any time without rebuilding anything.
See Also
resdag.models.classic_esn : The builder this facade wraps. resdag.training.ESNTrainer : The trainer this facade drives. resdag.core.ESNModel.forecast : The autoregressive forecaster this facade calls.
ESN
¶
ESN(reservoir_size: int = 500, *, spectral_radius: float = 0.9, leak_rate: float = 1.0, washout: int = 100, alpha: float = 1e-06, topology: TopologySpec = None, feedback_initializer: InitializerSpec = None, activation: str = 'tanh', bias: bool = True, readout_bias: bool = True, seed: int | None = None, device: device | str | None = None, dtype: dtype | None = None, **reservoir_kwargs: Any)
Opinionated, end-to-end Echo State Network — fit().forecast().
A thin, friendly wrapper that owns the whole reservoir-computing workflow so
a researcher can train on a time series and roll out an autoregressive
forecast of a chaotic system in roughly ten lines, without touching the
pytorch_symbolic graph, data slicing, or the trainer/forecast hand-off
by hand.
Hyperparameters are stored at construction; the underlying
:class:~resdag.core.ESNModel is built lazily on the first :meth:fit call
(once the feature dimension is known from the data). :meth:fit slices off
the first washout steps for state synchronisation, builds the
one-step-ahead training target internally, and drives
:class:~resdag.training.ESNTrainer. :meth:forecast resets the reservoir,
re-synchronises on the tail of the training series, and runs
:meth:~resdag.core.ESNModel.forecast.
The wrapper is deliberately non-hiding: the composed model is exposed as
:attr:model, so the full building-block API (custom transforms, multiple
readouts, :meth:~resdag.core.ESNModel.save_full, ...) remains available.
| PARAMETER | DESCRIPTION |
|---|---|
reservoir_size
|
Number of reservoir units.
TYPE:
|
spectral_radius
|
Target spectral radius of the recurrent weights (memory / stability).
TYPE:
|
leak_rate
|
Leaky-integration rate (
TYPE:
|
washout
|
Number of initial steps used to synchronise the reservoir (the "warmup"
window). These steps teacher-force the state and are not used as
training targets. Also the length of the re-synchronisation window
used at the start of :meth:
TYPE:
|
alpha
|
Ridge-regression (L2) regularisation strength for the readout.
TYPE:
|
topology
|
Recurrent-weight topology. Accepts a registry name (
TYPE:
|
feedback_initializer
|
Initializer for the feedback (input) weights. Same three-way spec as
TYPE:
|
activation
|
Reservoir activation:
TYPE:
|
bias
|
Whether the reservoir uses a bias term.
TYPE:
|
readout_bias
|
Whether the readout uses a bias term.
TYPE:
|
seed
|
If given, seeds
TYPE:
|
device
|
Device the model and data live on. If |
dtype
|
Floating dtype for the model and data. If
TYPE:
|
**reservoir_kwargs
|
Extra keyword arguments forwarded to
:class:
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
model |
The composed model, available after :meth:
TYPE:
|
feature_size |
Number of features
TYPE:
|
readout_name |
Name of the internal readout layer (matches the trainer's targets key).
TYPE:
|
Examples:
Train and forecast a chaotic system in ~10 lines:
>>> import numpy as np
>>> from resdag import ESN
>>> rng = np.random.default_rng(0)
>>> series = np.cumsum(rng.standard_normal((2000, 3)), axis=0) # (T, D)
>>> esn = ESN(reservoir_size=300, spectral_radius=0.9, washout=100)
>>> prediction = esn.fit(series).forecast(horizon=200)
>>> prediction.shape # numpy in -> numpy out, shape (horizon, D)
(200, 3)
Drop down to the composed model for advanced use:
See Also
resdag.models.classic_esn : Lower-level builder this facade composes. resdag.training.ESNTrainer : Trainer this facade drives. resdag.core.ESNModel.forecast : Autoregressive forecaster this facade calls.
Notes
- Stateful reset. :meth:
forecastalways resets the reservoir and re-synchronises on the training tail, so back-to-back forecasts are independent and reproducible — no manualreset_reservoirs()needed. - Readout name. The internal readout is named consistently and the
trainer is fed a matching
{name: target}dict, so the "readout name must match the targets key" footgun is handled for you. - Slot-0 forecast. The first output dimension equals the feedback
dimension by construction, so :meth:
forecastis genuinely autoregressive from its first emitted step.
Source code in src/resdag/facade.py
fit
¶
fit(series: Any) -> 'ESN'
Build the model (if needed) and fit the readout on series.
The series is split into a washout synchronisation prefix and a
training window; the one-step-ahead target is built internally
(x[t] -> x[t + 1]) and :class:~resdag.training.ESNTrainer fits the
readout in a single forward pass.
| PARAMETER | DESCRIPTION |
|---|---|
series
|
Time series of shape |
| RETURNS | DESCRIPTION |
|---|---|
ESN
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Examples:
Source code in src/resdag/facade.py
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 | |
forecast
¶
Roll out an autoregressive forecast continuing the fitted series.
Resets the reservoir, re-synchronises it on the final washout steps
of the training series, then autoregressively generates horizon
steps via :meth:~resdag.core.ESNModel.forecast. Because the state is
always reset first, successive calls are independent.
| PARAMETER | DESCRIPTION |
|---|---|
horizon
|
Number of future steps to generate. Must be
TYPE:
|
return_warmup
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor or ndarray
|
Forecast of shape |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If called before :meth: |
ValueError
|
If |
Examples: