Reference
Models & ensembles¶
Five factory functions that return ready-to-use ESNModel instances
(two of them — linear_esn and headless_esn — deliberately ship without
a readout), plus coupled_ensemble_esn, which builds a
CoupledEnsembleESNModel: the coupled-ensemble wrapper that runs N
sub-models against a shared feedback signal, with the aggregators that
merge their forecasts.
models
¶
Premade ESN Architectures¶
This module provides pre-configured ESN model architectures that can be used directly or customized for specific tasks.
| FUNCTION | DESCRIPTION |
|---|---|
classic_esn |
Traditional ESN with input concatenation. |
ott_esn |
Ott's ESN with state augmentation (squared even units). |
power_augmented |
Power Augmented ESN with state augmentation (exponentiated reservoir states). |
deep_esn |
Deep (hierarchical) ESN — a stack of reservoir layers whose readout sees the concatenation of every layer's state. |
hybrid_esn |
Hybrid physics-prior ESN (Pathak et al. 2018) — a reservoir combined with a knowledge-based expert wired in before the reservoir and before the readout. |
headless_esn |
Reservoir only (no readout) for analysis. |
linear_esn |
Linear reservoir for baseline comparison. |
lsm |
Spiking Liquid State Machine — leaky integrate-and-fire reservoir with a filtered-spike-trace readout (input-driven; not a chaos forecaster). |
coupled_ensemble_esn |
Build a :class: |
| CLASS | DESCRIPTION |
|---|---|
KnowledgeModel |
:class: |
Each architecture accepts individual parameters for full customization |
|
while providing sensible defaults for quick experimentation. |
|
Examples:
Quick start with Ott's ESN:
>>> from resdag.models import ott_esn
>>> model = ott_esn(reservoir_size=500, feedback_size=3, output_size=3)
>>> predictions = model.forecast(warmup_data, horizon=100)
Classic ESN with custom topology:
>>> from resdag.models import classic_esn
>>> from resdag.init.topology import get_topology
>>>
>>> model = classic_esn(
... reservoir_size=500,
... feedback_size=3,
... output_size=3,
... topology=get_topology("watts_strogatz", k=4, p=0.3),
... spectral_radius=0.95,
... )
See Also
resdag.core.ESNModel : Base ESN model class. resdag.layers.ESNLayer : ESN layer used by these models. resdag.training.ESNTrainer : Trainer for fitting readout layers.
classic_esn
¶
classic_esn(reservoir_size: int, feedback_size: int, output_size: int, input_size: int | None = None, input_initializer: InitializerSpec | None = None, topology: TopologySpec | None = None, spectral_radius: float = 0.9, leak_rate: float = 1.0, noise: float = 0.0, feedback_initializer: InitializerSpec | None = None, activation: str = 'tanh', bias: bool = True, trainable: bool = False, readout: ReadoutSpec = 'ridge', readout_alpha: float = 1e-06, readout_bias: bool = True, readout_name: str = 'output', **reservoir_kwargs: Any) -> ESNModel
Build a classic Echo State Network (ESN) model.
This architecture concatenates the input with the reservoir output before passing to the readout layer, following the traditional ESN design.
Architecture::
Input -> Reservoir -> Concatenate(Input, Reservoir) -> Readout
The readout sees both the raw input and the reservoir's nonlinear transformation, which can improve performance on many tasks.
| PARAMETER | DESCRIPTION |
|---|---|
reservoir_size
|
Number of units in the reservoir.
TYPE:
|
feedback_size
|
Number of feedback features (input dimension).
TYPE:
|
output_size
|
Number of output features.
TYPE:
|
input_size
|
Dimension of an optional driving (exogenous) input. When given, the
model takes two inputs
TYPE:
|
input_initializer
|
Initializer for the driving-input weights. Same accepted forms as
TYPE:
|
topology
|
Topology for recurrent weights. Accepts:
TYPE:
|
spectral_radius
|
Desired spectral radius for recurrent weights.
TYPE:
|
leak_rate
|
Leaky integration rate (1.0 = no leak).
TYPE:
|
noise
|
Standard deviation of additive Gaussian state noise injected into the
reservoir after the activation. Active only in training mode (a no-op
under :meth:
TYPE:
|
feedback_initializer
|
Initializer for feedback weights. Accepts:
TYPE:
|
activation
|
Activation function (
TYPE:
|
bias
|
Whether to use bias in the reservoir.
TYPE:
|
trainable
|
Whether reservoir weights are trainable.
TYPE:
|
readout
|
Which readout solver to attach. |
readout_alpha
|
Ridge regression regularization for readout.
TYPE:
|
readout_bias
|
Whether to use bias in the readout.
TYPE:
|
readout_name
|
Name for the readout layer (used in training targets).
TYPE:
|
**reservoir_kwargs
|
Additional keyword arguments passed to :class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
class:`~resdag.core.ESNModel`
|
Configured ESN model ready for training and inference. |
Examples:
Simple usage with defaults:
With custom topology and initializer:
>>> model = classic_esn(
... reservoir_size=400,
... feedback_size=1,
... output_size=1,
... topology=("watts_strogatz", {"k": 6, "p": 0.1}),
... feedback_initializer="pseudo_diagonal",
... spectral_radius=0.9,
... leak_rate=0.5,
... )
Forward pass:
See Also
:func:resdag.models.ott_esn : OTT ESN variant
:func:resdag.models.linear_esn : Linear ESN variant
:class:resdag.training.ESNTrainer : Trainer for fitting readouts
Source code in src/resdag/models/classic_esn.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 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 | |
ott_esn
¶
ott_esn(reservoir_size: int, feedback_size: int, output_size: int, input_size: int | None = None, input_initializer: InitializerSpec | None = None, topology: TopologySpec | None = None, spectral_radius: float = 0.9, leak_rate: float = 1.0, feedback_initializer: InitializerSpec | None = None, activation: str = 'tanh', bias: bool = True, trainable: bool = False, readout: ReadoutSpec = 'ridge', readout_alpha: float = 1e-06, readout_bias: bool = True, readout_name: str = 'output', **reservoir_kwargs: Any) -> ESNModel
Build Ott's ESN model with state augmentation.
This model follows the architecture proposed by Edward Ott, which augments reservoir states by squaring even-indexed units and concatenating with input. This augmentation helps capture higher-order dynamics in chaotic systems.
Architecture::
Input -> Reservoir -> SelectiveExponentiation -> Concatenate(Input, Augmented) -> Readout
| PARAMETER | DESCRIPTION |
|---|---|
reservoir_size
|
Number of units in the reservoir.
TYPE:
|
feedback_size
|
Dimension of feedback signal (input features).
TYPE:
|
output_size
|
Dimension of output signal.
TYPE:
|
input_size
|
Dimension of an optional driving (exogenous) input. When given, the
model takes two inputs
TYPE:
|
input_initializer
|
Initializer for the driving-input weights. Same format as
TYPE:
|
topology
|
Topology for recurrent weights. Accepts:
TYPE:
|
spectral_radius
|
Target spectral radius for recurrent weights.
TYPE:
|
leak_rate
|
Leaky integration rate. 1.0 = no leaking (standard ESN).
TYPE:
|
feedback_initializer
|
Initializer for feedback weights. Same format as
TYPE:
|
activation
|
Activation function for reservoir neurons.
TYPE:
|
bias
|
Whether to include bias in reservoir.
TYPE:
|
trainable
|
If True, reservoir weights are trainable via backpropagation.
TYPE:
|
readout
|
Which readout solver to attach. |
readout_alpha
|
L2 regularization strength for ridge regression in readout.
TYPE:
|
readout_bias
|
Whether to include bias in readout layer.
TYPE:
|
readout_name
|
Name for the readout layer. Used as target key in training.
TYPE:
|
**reservoir_kwargs
|
Additional keyword arguments passed to :class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ESNModel
|
Configured Ott ESN model ready for training and inference. |
Examples:
Basic usage:
>>> from resdag.models import ott_esn
>>> model = ott_esn(
... reservoir_size=500,
... feedback_size=3,
... output_size=3,
... )
>>> model.summary()
With custom topology:
>>> from resdag.init.topology import get_topology
>>> model = ott_esn(
... reservoir_size=500,
... feedback_size=3,
... output_size=3,
... topology=get_topology("watts_strogatz", k=4, p=0.3),
... spectral_radius=0.95,
... )
Training and forecasting:
>>> from resdag.training import ESNTrainer
>>> trainer = ESNTrainer(model)
>>> trainer.fit(
... warmup_inputs=(warmup,),
... train_inputs=(train,),
... targets={"output": target},
... )
>>> predictions = model.forecast(forecast_warmup, horizon=100)
See Also
classic_esn : Traditional ESN without state augmentation. resdag.training.ESNTrainer : Trainer for fitting readout. resdag.init.topology.get_topology : Get topology by name.
Source code in src/resdag/models/ott_esn.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 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 | |
power_augmented
¶
power_augmented(reservoir_size: int, feedback_size: int, output_size: int, exponent: float = 3.0, input_size: int | None = None, input_initializer: InitializerSpec | None = None, topology: TopologySpec | None = None, spectral_radius: float = 0.9, leak_rate: float = 1.0, feedback_initializer: InitializerSpec | None = None, activation: str = 'tanh', bias: bool = True, trainable: bool = False, readout: ReadoutSpec = 'ridge', readout_alpha: float = 1e-06, readout_bias: bool = True, readout_name: str = 'output', **reservoir_kwargs: Any) -> ESNModel
Build Power Augmented ESN model.
This model augments reservoir states by exponentiating to a power and concatenating with input. This augmentation helps capture higher-order dynamics in chaotic systems.
Architecture::
Input -> Reservoir -> Power -> Concatenate(Input, Augmented) -> Readout
| PARAMETER | DESCRIPTION |
|---|---|
reservoir_size
|
Number of units in the reservoir.
TYPE:
|
feedback_size
|
Dimension of feedback signal (input features).
TYPE:
|
output_size
|
Dimension of output signal.
TYPE:
|
exponent
|
Exponent applied to every reservoir state. Tanh reservoir states
live in
TYPE:
|
input_size
|
Dimension of an optional driving (exogenous) input. When given, the
model takes two inputs
TYPE:
|
input_initializer
|
Initializer for the driving-input weights. Same format as
TYPE:
|
topology
|
Topology for recurrent weights. Accepts:
TYPE:
|
spectral_radius
|
Target spectral radius for recurrent weights.
TYPE:
|
leak_rate
|
Leaky integration rate. 1.0 = no leaking (standard ESN).
TYPE:
|
feedback_initializer
|
Initializer for feedback weights. Same format as
TYPE:
|
activation
|
Activation function for reservoir neurons.
TYPE:
|
bias
|
Whether to include bias in reservoir.
TYPE:
|
trainable
|
If True, reservoir weights are trainable via backpropagation.
TYPE:
|
readout
|
Which readout solver to attach. |
readout_alpha
|
L2 regularization strength for ridge regression in readout.
TYPE:
|
readout_bias
|
Whether to include bias in readout layer.
TYPE:
|
readout_name
|
Name for the readout layer. Used as target key in training.
TYPE:
|
**reservoir_kwargs
|
Additional keyword arguments passed to :class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ESNModel
|
Configured Power Augmented ESN model ready for training and inference. |
Notes
The augmentation applies :class:~resdag.layers.Power to the raw reservoir
states, which for a tanh activation lie in [-1, 1] — negatives and
zeros included. Choose exponent accordingly:
- Even integers (
2.0,4.0, …) are always safe: every state maps to a non-negative value with nonan/inf. - Odd integers (
3.0,5.0, …) are safe and sign-preserving: negative states stay negative. - Non-integer exponents (e.g.
0.5,1.5) applied to a negative state producenanunder the default :func:torch.pow, silently corrupting the readout inputs. Negative exponents (e.g.-1.0) produceinfon the zeros thattanhstates pass through.
If you need a non-integer exponent on signed states, wire the model by hand
with Power(exponent, sign_preserving=True), which applies
sign(x) * abs(x) ** exponent and stays finite for negative bases. This
factory always uses the default (non-sign-preserving) Power to keep the
well-established integer-exponent behaviour unchanged.
Examples:
Basic usage:
>>> from resdag.models import power_augmented
>>> model = power_augmented(
... reservoir_size=500,
... feedback_size=3,
... output_size=3,
... exponent=3.0,
... )
>>> model.summary()
With custom topology:
>>> from resdag.init.topology import get_topology
>>> model = power_augmented(
... reservoir_size=500,
... feedback_size=3,
... output_size=3,
... topology=get_topology("watts_strogatz", k=4, p=0.3),
... spectral_radius=0.95,
... exponent=3.0,
... )
Training and forecasting:
>>> from resdag.training import ESNTrainer
>>> trainer = ESNTrainer(model)
>>> trainer.fit(
... warmup_inputs=(warmup,),
... train_inputs=(train,),
... targets={"output": target},
... )
>>> predictions = model.forecast(forecast_warmup, horizon=100)
See Also
classic_esn : Traditional ESN without state augmentation. resdag.training.ESNTrainer : Trainer for fitting readout. resdag.init.topology.get_topology : Get topology by name.
Source code in src/resdag/models/power_augmented.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 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 212 213 214 215 216 217 218 219 220 | |
linear_esn
¶
linear_esn(reservoir_size: int, feedback_size: int, topology: TopologySpec | None = None, spectral_radius: float = 0.9, leak_rate: float = 1.0, feedback_initializer: InitializerSpec | None = None, bias: bool = True, trainable: bool = False, **reservoir_kwargs: Any) -> ESNModel
Build an ESN model with no readout layer and a linear activation function.
This model uses a linear activation function in the reservoir, which can be useful for studying linear dynamics or as a baseline for comparison with nonlinear reservoirs.
Architecture: Input -> Reservoir(activation='identity') (output)
| PARAMETER | DESCRIPTION |
|---|---|
reservoir_size
|
Number of units in the reservoir.
TYPE:
|
feedback_size
|
Number of feedback features.
TYPE:
|
topology
|
Topology for recurrent weights. Accepts: - str: Registry name (e.g., "erdos_renyi") - tuple: (name, params) like ("watts_strogatz", {"k": 6, "p": 0.1}) - GraphTopology: Pre-configured object
TYPE:
|
spectral_radius
|
Desired spectral radius for recurrent weights.
TYPE:
|
leak_rate
|
Leaky integration rate (1.0 = no leak).
TYPE:
|
feedback_initializer
|
Initializer for feedback weights.
TYPE:
|
bias
|
Whether to use bias in the reservoir.
TYPE:
|
trainable
|
Whether reservoir weights are trainable.
TYPE:
|
**reservoir_kwargs
|
Additional keyword arguments passed to ESNLayer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ESNModel
|
ESN model with linear reservoir activation. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Examples:
>>> from resdag.models import linear_esn
>>> model = linear_esn(100, 1)
>>> linear_states = model(input_data)
Source code in src/resdag/models/linear_esn.py
headless_esn
¶
headless_esn(reservoir_size: int, feedback_size: int, topology: TopologySpec | None = None, spectral_radius: float = 0.9, leak_rate: float = 1.0, feedback_initializer: InitializerSpec | None = None, activation: str = 'tanh', bias: bool = True, trainable: bool = False, **reservoir_kwargs: Any) -> ESNModel
Build an ESN model with no readout layer.
This model can be used to study the dynamics of the reservoir by applying different transformations to the reservoir states without a readout layer. Useful for analyzing reservoir dynamics, state space properties, and feature extraction.
Architecture: Input -> Reservoir (output)
The reservoir is not connected to a readout layer, allowing direct access to reservoir states for analysis or custom processing.
| PARAMETER | DESCRIPTION |
|---|---|
reservoir_size
|
Number of units in the reservoir.
TYPE:
|
feedback_size
|
Number of feedback features.
TYPE:
|
topology
|
Topology for recurrent weights. Accepts: - str: Registry name (e.g., "erdos_renyi") - tuple: (name, params) like ("watts_strogatz", {"k": 6, "p": 0.1}) - GraphTopology: Pre-configured object
TYPE:
|
spectral_radius
|
Desired spectral radius for recurrent weights.
TYPE:
|
leak_rate
|
Leaky integration rate (1.0 = no leak).
TYPE:
|
feedback_initializer
|
Initializer for feedback weights.
TYPE:
|
activation
|
Activation function ("tanh", "relu", "sigmoid", "identity").
TYPE:
|
bias
|
Whether to use bias in the reservoir.
TYPE:
|
trainable
|
Whether reservoir weights are trainable.
TYPE:
|
**reservoir_kwargs
|
Additional keyword arguments passed to ESNLayer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ESNModel
|
ESN model with reservoir output only. |
Examples:
>>> from resdag.models import headless_esn
>>> model = headless_esn(100, 1)
>>> reservoir_states = model(input_data) # Direct reservoir output
Source code in src/resdag/models/headless_esn.py
coupled_ensemble_esn
¶
coupled_ensemble_esn(n_models: int, model_factory: Callable[..., ESNModel] = ott_esn, aggregate: str | Module = 'mean', seed: int | None = None, **model_kwargs: Any) -> CoupledEnsembleESNModel
Build a coupled ensemble of N independently-initialized ESN models.
Each sub-model is created by calling model_factory(**model_kwargs)
with an independent random reservoir initialization, providing the
diversity needed for ensemble averaging to be beneficial.
During autoregressive forecasting all N sub-models receive the same aggregated output (e.g. the mean across models) as their next feedback input — they are coupled through the shared signal.
| PARAMETER | DESCRIPTION |
|---|---|
n_models
|
Number of sub-models in the ensemble.
TYPE:
|
model_factory
|
Factory that creates one :class:
TYPE:
|
aggregate
|
Aggregation strategy applied to the N model outputs at each autoregressive step:
|
seed
|
Master seed for deterministic sub-model construction. Sub-model
The process-global default RNG is not clobbered: its state is
captured before the construction loop and restored on exit (even if a
factory raises), so building a seeded ensemble does not perturb a
subsequent global
TYPE:
|
**model_kwargs
|
All remaining keyword arguments are forwarded verbatim to each
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoupledEnsembleESNModel
|
Ensemble ready for training and forecasting. |
Examples:
Quick start with default Ott's ESN sub-models:
>>> import resdag as rd
>>>
>>> ensemble = rd.coupled_ensemble_esn(
... n_models=5,
... reservoir_size=300,
... feedback_size=3,
... output_size=3,
... )
>>> ensemble.fit((warmup,), (train,), {"output": targets})
>>> ensemble.reset_reservoirs()
>>> preds = ensemble.forecast(forecast_warmup, horizon=200)
>>> preds.shape
torch.Size([1, 200, 3])
Using classic_esn as the base architecture:
>>> from resdag.models import classic_esn
>>> ensemble = rd.coupled_ensemble_esn(
... n_models=8,
... model_factory=classic_esn,
... reservoir_size=500,
... feedback_size=3,
... output_size=3,
... spectral_radius=0.95,
... readout_alpha=1e-7,
... )
Outlier-robust aggregation:
>>> from resdag.ensemble.aggregators import OutliersFilteredMean
>>> ensemble = rd.coupled_ensemble_esn(
... n_models=10,
... reservoir_size=300,
... feedback_size=3,
... output_size=3,
... aggregate=OutliersFilteredMean(method="z_score", threshold=2.0),
... )
Recovering individual sub-model trajectories for post-hoc analysis:
>>> ensemble.reset_reservoirs()
>>> preds, individuals = ensemble.forecast(
... forecast_warmup, horizon=200, return_individuals=True
... )
>>> preds.shape # averaged forecast
torch.Size([1, 200, 3])
>>> len(individuals) # one tensor per sub-model
10
>>> individuals[0].shape
torch.Size([1, 200, 3])
See Also
CoupledEnsembleESNModel : The ensemble class with full API documentation. resdag.ensemble.aggregators.OutliersFilteredMean : Outlier-robust aggregation layer. resdag.models.ott_esn : Default sub-model factory.
Source code in src/resdag/models/coupled_ensemble_esn.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 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 | |
ensemble
¶
Ensemble Reservoir Computing Models¶
This module provides ensemble wrappers for groups of independently-trained
:class:~resdag.core.ESNModel instances.
| CLASS | DESCRIPTION |
|---|---|
CoupledEnsembleESNModel |
N independent ESN sub-models whose autoregressive forecasts are coupled through a shared averaged feedback signal at every timestep. |
See Also
resdag.models.coupled_ensemble_esn : Factory function for quick construction.
CoupledEnsembleESNModel
¶
Bases: Module
Ensemble of N independently-trained ESN models with coupled feedback.
Each sub-model is a complete :class:~resdag.core.ESNModel built
via the pytorch_symbolic API. The models are trained independently but
coupled during forecasting: at every autoregressive step every model
receives the same aggregated output (e.g. the mean across models) as
its next feedback input.
| PARAMETER | DESCRIPTION |
|---|---|
models
|
N pre-built ESN sub-models. Diversity comes from their independent random reservoir initialization.
TYPE:
|
aggregator
|
How to combine the N per-model outputs into a single feedback tensor.
|
Examples:
Typical use via the factory:
>>> from resdag.models import coupled_ensemble_esn
>>> ensemble = coupled_ensemble_esn(n_models=5, reservoir_size=300,
... feedback_size=3, output_size=3)
>>> ensemble.fit((warmup,), (train,), {"output": targets})
>>> ensemble.reset_reservoirs()
>>> preds = ensemble.forecast(forecast_warmup, horizon=200)
>>> preds.shape
torch.Size([1, 200, 3])
With a custom aggregator:
>>> from resdag.ensemble.aggregators import OutliersFilteredMean
>>> ensemble = coupled_ensemble_esn(
... n_models=10, reservoir_size=300, feedback_size=3, output_size=3,
... aggregate=OutliersFilteredMean(method="z_score", threshold=2.0),
... )
See Also
resdag.models.coupled_ensemble_esn : Convenience factory function. resdag.ensemble.aggregators.OutliersFilteredMean : Outlier-robust aggregation layer.
| PARAMETER | DESCRIPTION |
|---|---|
models
|
Sub-models. Must be non-empty.
TYPE:
|
aggregator
|
Aggregation strategy. See class docstring for options. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/resdag/ensemble/coupled.py
forward
¶
Run all sub-models on the same inputs and return the aggregated output.
| PARAMETER | DESCRIPTION |
|---|---|
*inputs
|
Same input tensors passed to every sub-model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Aggregated output of shape |
Source code in src/resdag/ensemble/coupled.py
warmup
¶
warmup(*inputs: Tensor) -> None
Teacher-forced warmup: synchronize every sub-model's reservoir state.
| PARAMETER | DESCRIPTION |
|---|---|
*inputs
|
Warmup sequences. Passed identically to each sub-model.
TYPE:
|
Source code in src/resdag/ensemble/coupled.py
reset_reservoirs
¶
get_reservoir_states
¶
Return reservoir states for all sub-models.
| RETURNS | DESCRIPTION |
|---|---|
list of dict
|
One dict per sub-model, mapping layer name to state tensor. |
Source code in src/resdag/ensemble/coupled.py
set_reservoir_states
¶
Restore reservoir states in all sub-models.
| PARAMETER | DESCRIPTION |
|---|---|
states
|
One dict per sub-model as returned by :meth:
TYPE:
|
strict
|
Forwarded to :meth:
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the number of dicts in |
Source code in src/resdag/ensemble/coupled.py
fit
¶
fit(warmup_inputs: tuple[Tensor, ...], train_inputs: tuple[Tensor, ...], targets: dict[str, Tensor], n_workers: int = 1, coerce: bool = False) -> None
Train all sub-models independently using :class:~resdag.training.ESNTrainer.
Each sub-model is trained separately on the same warmup/train data. Ensemble diversity comes from the different random reservoir initialisations of each sub-model.
Before dispatching to :class:~resdag.training.ESNTrainer, every
warmup_inputs / train_inputs tensor and every targets value
is checked against the ensemble's reference device/dtype (the first
sub-model's first floating-point parameter; see
:meth:_reference_device_dtype). A mismatch raises a clear, named
:class:ValueError — e.g. CPU targets fed to a GPU ensemble — instead
of a raw cross-device RuntimeError deep inside the readout solve.
Pass coerce=True to .to()-coerce the data to the reference
instead of raising.
| PARAMETER | DESCRIPTION |
|---|---|
warmup_inputs
|
Warmup sequences
TYPE:
|
train_inputs
|
Training sequences
TYPE:
|
targets
|
Mapping from readout name to target tensor.
Shape of each target:
TYPE:
|
n_workers
|
Number of worker threads used to fit sub-models concurrently.
TYPE:
|
coerce
|
If
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/resdag/ensemble/coupled.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 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 | |
forecast
¶
forecast(warmup_inputs: tuple[Tensor, ...] | Tensor, forecast_inputs: tuple[Tensor, ...] | None = None, *, horizon: int, return_warmup: bool = False, return_individuals: bool = False, reset: bool = True) -> Tensor | tuple[Tensor, list[Tensor]]
Coupled autoregressive forecast.
Phase 1 — Warmup: all sub-models are teacher-forced with the same warmup data, advancing their reservoir states independently.
Phase 2 — Coupled autoregression: at every timestep t every
sub-model receives the same current_feedback (the aggregation of
all models' outputs at t-1). The averaged output couples all models
through a shared feedback signal.
| PARAMETER | DESCRIPTION |
|---|---|
warmup_inputs
|
Warmup sequences
TYPE:
|
forecast_inputs
|
Exogenous driver inputs for the autoregressive phase (feedback is
generated by the ensemble itself). Autoregressive step
TYPE:
|
horizon
|
Number of autoregressive steps to generate. |
return_warmup
|
If
TYPE:
|
return_individuals
|
If
TYPE:
|
reset
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Aggregated forecast of shape |
tuple of (torch.Tensor, list of torch.Tensor)
|
When |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/resdag/ensemble/coupled.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
save
¶
Save ensemble weights (and optionally reservoir states) to a file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Destination file path.
TYPE:
|
include_states
|
If
TYPE:
|
**metadata
|
Arbitrary key-value pairs stored alongside the weights.
TYPE:
|
Source code in src/resdag/ensemble/coupled.py
load
¶
Load ensemble weights from a file created by :meth:save.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Source file path.
TYPE:
|
strict
|
Passed to
TYPE:
|
load_states
|
If
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the checkpoint contains a different number of sub-models. |
Source code in src/resdag/ensemble/coupled.py
save_full
¶
Serialize the entire ensemble — every sub-model's architecture, weights, and reservoir states — to a single file.
Unlike :meth:save (state dicts only, requires rebuilding the ensemble
before :meth:load), this pickles the whole ensemble object and is
restored with :meth:load_full without rebuilding anything. Relies on
the pickle support added in pytorch-symbolic 1.2.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Destination file path.
TYPE:
|
**metadata
|
Arbitrary key-value pairs stored alongside the ensemble.
TYPE:
|
Notes
Loaded back with weights_only=False (arbitrary unpickling), so only
open files you trust. Custom callable topology/initializer/activation
specs must be importable (module-level, not lambdas) to be picklable;
otherwise use the lighter state-dict :meth:save.
See Also
load_full : Reconstruct an ensemble saved with this method. save : Lighter, state-dict-only persistence (architecture not stored).
Source code in src/resdag/ensemble/coupled.py
load_full
classmethod
¶
load_full(path: str, return_metadata: bool = False, map_location: Any = None) -> CoupledEnsembleESNModel | tuple[CoupledEnsembleESNModel, dict[str, Any]]
Reconstruct a complete ensemble saved with :meth:save_full.
No pre-built ensemble is required — every sub-model is restored intact.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
File path written by :meth:
TYPE:
|
return_metadata
|
If
TYPE:
|
map_location
|
Passed to
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the file does not contain a whole ensemble (e.g. a state-dict
checkpoint from :meth: |
Warnings
Loads with weights_only=False, which unpickles arbitrary Python
objects. Only call this on files from a source you trust.
See Also
save_full : Serialize a complete ensemble.
Source code in src/resdag/ensemble/coupled.py
aggregators
¶
Ensemble Aggregators¶
This module hosts nn.Module layers that combine N per-sub-model outputs
into a single aggregated tensor. Aggregators expect a 4-D input of shape
(samples, batch, timesteps, features) (or a list of length samples
each of shape (batch, timesteps, features)) and return a 3-D tensor of
shape (batch, timesteps, features).
They plug into :class:~resdag.ensemble.CoupledEnsembleESNModel via the
aggregator argument.
| CLASS | DESCRIPTION |
|---|---|
OutliersFilteredMean |
Mean across the samples dimension after dropping outliers (Z-score or IQR). |
See Also
resdag.ensemble.CoupledEnsembleESNModel : Coupled ensemble that consumes these aggregators.
OutliersFilteredMean
¶
Bases: Module
Mean over ensemble members after removing outlier norms.
For each (batch, timestep) location, computes the L2 norm of each
member's feature vector, flags outliers via a robust modified Z-score or
the IQR rule, then averages the inlier members. If every member is an
outlier at a location, falls back to the plain mean.
The "z_score" method uses the modified Z-score
0.6745 * (x - median) / MAD (Iglewicz & Hoaglin, 1993), where MAD
is the median absolute deviation. Unlike the classic mean/standard-deviation
Z-score, the median and MAD are robust estimators: a single extreme member
does not inflate the location/scale used to judge it, so a genuine outlier
can be flagged even in small ensembles. (The classic non-robust Z-score
saturates at sqrt(N - 1) for a lone outlier among N members, so a
threshold=3.0 cutoff could never flag anything until N >= 11.)
| PARAMETER | DESCRIPTION |
|---|---|
method
|
Outlier detection rule applied to per-member norms.
TYPE:
|
threshold
|
Detection sensitivity. For
TYPE:
|
Examples:
>>> layer = OutliersFilteredMean(method="z_score")
>>> x = torch.randn(10, 3, 5, 4) # samples, batch, time, features
>>> layer(x).shape
torch.Size([3, 5, 4])
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If method is not |
References
Iglewicz, B. and Hoaglin, D. C. (1993). How to Detect and Handle Outliers. ASQC Quality Press.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
How to label outlier members along the samples axis.
TYPE:
|
threshold
|
Detection sensitivity (modified-Z-score bound or IQR factor). When
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If method is not supported. |
Source code in src/resdag/ensemble/aggregators/outliers_filtered_mean.py
forward
¶
Aggregate ensemble members with outlier filtering.
Outlier detection is norm-based and whole-member: each member's L2
feature-vector norm is scored at every (batch, timestep) location,
and a flagged member is dropped in its entirety (the whole feature
vector is excluded from that location's mean). A member that is an
outlier in only one feature but normal in norm is therefore not
caught, and one that is off in a single feature enough to inflate its
norm is dropped wholesale rather than per feature.
| PARAMETER | DESCRIPTION |
|---|---|
input
|
One of:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If input is a tensor whose rank is neither 3-D nor 4-D (for
example a 2-D |