Echo State Network model¶
ESN_model combines a discrete-time forecast model with the reservoir core provided by
echostatenetwork. The main configuration
parameters control the reservoir size, spectral radius, input scaling, and washout.
romda.models.data_driven.rnns.esn.ESN_model(dt, **kwargs)
¶
Bases: EchoStateNetwork, Model
Echo state network as a data-driven forecast model.
Wraps the EchoStateNetwork reservoir
with the Model interface (state history, discrete
integrator, observation operator), so a trained ESN can be used as the forecast
model of an Ensemble — or as the forecaster inside
ESN_bias. The model state is
\([\mathbf{u}; \mathbf{r}]\): the physical outputs and the reservoir state.
Training data is mandatory at construction (the network trains itself unless a
cached configuration is found).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Output time step (the internal ESN step is |
required |
**kwargs
|
Supported keys include:
|
{}
|
Source code in src/models/data_driven/rnns/esn.py
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 | |
t_transient
property
¶
float: Total time spanning training + validation + test, t_train + t_val + t_test.
dt_step
property
¶
float: Integrator time step, dt_ESN (the ESN advances in closed loop at
its own upsampled time step, not dt).
t_CR
property
¶
float: Characteristic response time used by the base Model, aliased to t_val.
Wout_U
property
writable
¶
np.ndarray: Left singular vectors of Wout (from
scipy.linalg.svd(Wout, full_matrices=False)), shape Wout.shape i.e.
(N_units + 1, N_dim). Only used/set when Wout_svd is True.
Wout_Vh
property
writable
¶
np.ndarray: Right singular vectors of Wout (transposed), shape
(N_dim, N_dim). Only used/set when Wout_svd is True.
Wout_Sigma
property
writable
¶
np.ndarray: Ensemble of diagonal singular-value matrices used to
reconstruct Wout as \(\mathbf{W}_\mathrm{out} \approx \mathbf{U}\,\boldsymbol{\Sigma}\,\mathbf{V}^\mathrm{h}\)
(see reservoir_to_physical), shape (m, N_dim, N_dim). If Wout_svd,
recomputed from the current svd_i ensemble parameters on every access
(via alpha_to_Sigma); otherwise held fixed at whatever was last set.
alpha_to_Sigma
property
¶
np.ndarray: Per-ensemble-member diagonal singular-value matrices built
from the current svd_i parameter estimates (get_alpha_matrix), falling
back to the corresponding Wout_Sigma0 singular value for any svd_i not
in est_alpha. Shape (m, N_dim, N_dim).
get_alpha_matrix
property
¶
np.ndarray: Current ensemble parameter estimates (est_alpha), shape
(len(est_alpha), m), read from get_alpha.
Wout_Sigma0
property
writable
¶
np.ndarray: Reference (initial) singular values of Wout, shape
(N_dim,), as computed by scipy.linalg.svd when Wout_svd is enabled.
N_ens
property
¶
int: Ensemble size, read from ensemble['m'] if an ensemble
configuration is set, otherwise the trailing dimension of current_state.
state_labels
property
¶
list of str: LaTeX labels for the state vector, \(u_1, \dots, u_{N_\mathrm{dim}}\) (physical outputs) followed by \(r_1, \dots, r_{N_\mathrm{units}}\) (reservoir units).
obs_labels
property
¶
list of str: LaTeX labels for the observed physical outputs (observed_idx).
reservoir_state
property
¶
np.ndarray: Reservoir-state block of current_state, shape (N_units, m).
modify_settings(**kwargs)
¶
Update existing attributes in place, switching to the SVD parametrization
of Wout (see Wout_svd) if 'Wout' is requested as an ensemble parameter
to estimate (est_alpha).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Attribute name/value pairs to set; each name must already exist on the instance. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
Updates attributes (and, if applicable, |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a key in |
Source code in src/models/data_driven/rnns/esn.py
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 | |
init_ensemble(m=10, est_alpha=[], std_alpha=0.001, distribution_alpha='uniform', regimes=None, seed=0, measured=None, ensemble_psi0=None, **kwargs)
¶
ESN override of Model.init_ensemble: members start from reservoir states
visited during training (initialize_from_val_data) — the generic transient +
multiplicative std_phi path pushes r outside the tanh range and the closed
loop blows up.
regimes ((N_param, L), parametric ESN): washes each member out on one
training segment and starts it from that segment's parameters, keeping state
and parameter consistent — paired independently, members leave the learned
attractor and diverge. 'Wout' in est_alpha estimates the read-out
singular values (one svd_i per output dimension); measured restricts
the observation operator to those state components.
Parameter perturbations draw from this instance's rng; an estimator
builds the ensemble on its own copy (EnsembleEstimator copies
parent_model first), so repeated builds from one parent network draw
identical perturbations — the parent's rng is deliberately untouched.
Source code in src/models/data_driven/rnns/esn.py
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 | |
initialize_from_val_data(N_ens=1, seed=0)
¶
Initialize the ESN state (physical output and reservoir) from an
open-loop washout over a random time window of validation_data, so a fresh
ensemble starts from an on-attractor reservoir state rather than zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N_ens
|
int
|
Number of ensemble members (random washout windows) to draw. Default 1. |
1
|
seed
|
int
|
Random seed for selecting the washout windows. Overridden by |
0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Initial full state (built via |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in src/models/data_driven/rnns/esn.py
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 | |
closed_loop(data, n_steps, input_parameters=None)
¶
Open-loop washout on data[:N_wash] (sampled at dt_ESN), then a closed-loop
forecast; returns (prediction, target), both (n_steps, N_dim).
The ESN maps u_t to u_{t+1}, so the last washout step already predicts
data[N_wash] — an off-by-one here costs a full dt_ESN of drift.
Source code in src/models/data_driven/rnns/esn.py
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 | |
reset_ESN(data, u0=None, plot_training=False, **kwargs)
¶
Reinitialize and retrain the underlying EchoStateNetwork from scratch
on new data, then reset the Model state/history around the freshly
trained network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
New training data, shape |
required |
u0
|
ndarray
|
Initial physical state for the new |
None
|
plot_training
|
bool
|
Whether to plot the (re-)training process. Default False. |
False
|
**kwargs
|
ESN hyperparameters (forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
Reinitializes |
Source code in src/models/data_driven/rnns/esn.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 | |
get_observables(Nt=1, **kwargs)
¶
Observables are the observed physical outputs, which need not be the
leading rows of psi (the base Model assumes psi[:Nq]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of trailing history steps to return. Default 1. |
1
|
**kwargs
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Observed outputs, shape |
Source code in src/models/data_driven/rnns/esn.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
reservoir_to_physical(r)
¶
Convert reservoir states to physical outputs via Wout (overrides
EchoStateNetwork.reservoir_to_physical to also support the SVD
parametrization of Wout, see Wout_svd).
When Wout_svd is False: \(\mathbf{u} = \mathbf{W}_\mathrm{out}^\mathrm{T}[\mathbf{r}; b_\mathrm{out}]\),
as in the base class. When True, \(\mathbf{W}_\mathrm{out}\) is reconstructed
(per ensemble member, if r has m members) from
\(\mathbf{U}\,\boldsymbol{\Sigma}\,\mathbf{V}^\mathrm{h}\) (Wout_U, Wout_Sigma,
Wout_Vh) before the same read-out is applied; if r does not have exactly
m members (e.g. a single averaged state), Wout_Sigma is averaged over the
ensemble first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
ndarray
|
Reservoir state, shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Physical output, shape |
Source code in src/models/data_driven/rnns/esn.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | |
time_step(Nt=10, averaged=False)
¶
Advance the ESN in closed loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps (in physical time steps, not |
10
|
averaged
|
bool
|
If True, the ensemble is forecast as its mean plus frozen deviations; otherwise each member is forecast individually. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/models/data_driven/rnns/esn.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
build_psi(u=None, r=None)
¶
Assemble the full model state from physical output u and reservoir
state r: concatenate([u, r, alpha]) along the state axis, keeping only
u or only r if update_state/update_reservoir is False, and appending
the ensemble parameter block (get_alpha_matrix) if Na > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Physical output, shape |
None
|
r
|
ndarray
|
Reservoir state, shape |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Full state |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/models/data_driven/rnns/esn.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | |
unbuild_psi(psi=None)
¶
Inverse of build_psi: split a full state vector into its physical
(u) and reservoir (r) blocks, assuming they occupy the leading
N_dim + N_units rows of psi (as build_psi lays them out when both
update_state and update_reservoir are True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
ndarray
|
Full state, shape |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
u |
ndarray
|
Physical state, shape |
r |
ndarray
|
Reservoir state, shape |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in src/models/data_driven/rnns/esn.py
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
plot_training_data(case, train_data, dt=None)
staticmethod
¶
Plot each dimension of train_data, shading the training/validation/test
windows (case.t_train/t_val/t_test).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
ESN_model
|
Instance providing |
required |
train_data
|
ndarray
|
Data to plot, shape |
required |
dt
|
float
|
Time step for the x-axis. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Displays the figure with |
Source code in src/models/data_driven/rnns/esn.py
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 | |
visualize_config()
¶
Plot the trained read-out matrix (plot_Wout).
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/models/data_driven/rnns/esn.py
1002 1003 1004 1005 1006 1007 1008 1009 | |
visualize_spatiotemporal_hist(y_hist=None, t=None, averaged=False, reference_y=1.0, reference_t=1.0, **kwargs)
¶
Plot the physical and reservoir state history as space-time heat-maps (one row per state component vs. time), either per ensemble member or as the ensemble mean and standard deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_hist
|
ndarray
|
State history to plot, shape |
None
|
t
|
ndarray
|
Time points for |
None
|
averaged
|
bool
|
If True, plot the ensemble mean and standard deviation (2 rows); otherwise plot up to 10 individual state components. Default False. |
False
|
reference_y
|
float
|
Value to normalize |
1.0
|
reference_t
|
float
|
Reference time used to normalize/label the time axis (see
|
1.0
|
**kwargs
|
|
{}
|
Returns:
| Type | Description |
|---|---|
None
|
Displays the figure(s) in place. |
Source code in src/models/data_driven/rnns/esn.py
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 | |
plot_Wout()
¶
Visualize the trained read-out matrix Wout (overrides
EchoStateNetwork.plot_Wout): a single heat-map if Wout_svd is False, or
the (ensemble-averaged) SVD factors Wout_U, Wout_Sigma, Wout_Vh and
their reconstruction if True.
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in src/models/data_driven/rnns/esn.py
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |