Data-driven models¶
Summary¶
File: src/models/data_driven/. All use DiscreteIntegrator. ESN_model mixes in
EchoStateNetwork — the reservoir core from the external
echostatenetwork package (re-exported by
romda.models.data_driven for convenience; see its own documentation for the reservoir API) —
and POD_ESN mixes in ESN_model and POD.
| Class | Key parameters | Notes |
|---|---|---|
ESN_model |
N_units, rho, sigma_in, N_wash |
Inherits EchoStateNetwork; requires training data at init |
POD_ESN |
N_modes, sensor_locations |
Inherits ESN_model + POD; sensor placement via QR |
LinearModel |
F (transition matrix), Q_noise |
\(\boldsymbol{\psi}_{t+1} = \mathbf{F}\boldsymbol{\psi}_t + \boldsymbol{\eta}_t\) |
The Projector hierarchy (POD/SPOD) and the standalone decomposition functions
(pod_utils.py) live in the autoencoders/ subpackage and are documented
below. Import everything from romda.models.data_driven
(or its autoencoders subpackage).
Forecast models¶
romda.models.data_driven.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/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/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/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/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/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/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/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/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/esn.py
767 768 769 770 771 772 773 774 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 | |
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/esn.py
833 834 835 836 837 838 839 840 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 | |
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/esn.py
891 892 893 894 895 896 897 898 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 | |
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/esn.py
936 937 938 939 940 941 942 943 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 | |
visualize_config()
¶
Plot the trained read-out matrix (plot_Wout).
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/models/data_driven/esn.py
994 995 996 997 998 999 1000 1001 | |
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/esn.py
1054 1055 1056 1057 1058 1059 1060 1061 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 | |
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/esn.py
1177 1178 1179 1180 1181 1182 1183 1184 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 | |
romda.models.data_driven.pod_esn.POD_ESN(data, dt, plot_case=False, pdf_file=None, skip_sensor_placement=False, train_ESN=True, domain_of_measurement=None, down_sample_measurement=None, **kwargs)
¶
POD-projected echo state network: a POD
decomposition reduces the (spatial) field to a handful of temporal
coefficients, and an ESN_model is
trained to forecast those coefficients in time.
Following the POD convention (see its
docstring), writing \(\mathbf{Q} = \mathbf{X} - \bar{\mathbf{Q}}\) for the
zero-mean data, the field is approximated as
with \(\boldsymbol{\Psi}\) (Psi) the orthonormal spatial modes and
\(\boldsymbol{\Phi}\) (Phi) the temporal coefficients
(\(\boldsymbol{\Phi} = \boldsymbol{\Psi}^\mathrm{T}\mathbf{Q}\), already scaled by the
singular values Sigma). POD_ESN.__init__ runs the POD decomposition first,
then trains the ESN on \(\boldsymbol{\Phi}\) (transposed to the
(L, Nt, N_modes) layout ESN_model expects) to forecast the temporal
coefficients forward in time; get_observables maps the ESN's closed-loop
Phi forecast back to physical sensor readings (decode) or returns the modal
coefficients directly if measure_modes.
Run the POD decomposition, train the ESN on the resulting temporal coefficients, and select sensor locations for observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data for the POD decomposition and ESN training, shape
|
required |
dt
|
float
|
Time step of |
required |
plot_case
|
bool
|
Whether to plot the POD modes/spectrum/reconstruction (and the ESN
training process, if |
False
|
pdf_file
|
str
|
If given (and |
None
|
skip_sensor_placement
|
bool
|
If True, skip sensor placement and observe the POD modes directly
(equivalent to |
False
|
train_ESN
|
bool
|
Whether to train the ESN on the POD temporal coefficients. Default True. |
True
|
domain_of_measurement
|
list
|
Sub-domain |
None
|
down_sample_measurement
|
int or (int, int)
|
Grid down-sampling factor(s) applied to the measurement domain before sensor selection. |
None
|
**kwargs
|
Additional keyword arguments to configure the parent Model/ESN/POD
classes, e.g. |
{}
|
Source code in src/models/data_driven/pod_esn.py
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 | |
obs_labels
property
¶
list of str: LaTeX labels for the observed quantities -- POD coefficients
\(\Phi_1, \dots, \Phi_{N_\mathrm{modes}}\) if measure_modes, otherwise the
sensor readings' \(u_x\)/\(u_y\) components.
state_labels
property
¶
list of str: LaTeX labels for the state vector, \(\Phi_1, \dots,
\Phi_{N_\mathrm{modes}}\) (POD temporal coefficients, if update_state)
followed by \(r_1, \dots, r_{N_\mathrm{units}}\) (reservoir units, if
update_reservoir).
N_sensors
property
¶
int: Number of sensor locations per velocity component (\(u_x\) or \(u_y\)),
i.e. Nq // 2 (each location contributes 2 observables); 0 if
measure_modes.
sensor_rows
property
¶
np.ndarray or None: Rows of Psi/Q_mean corresponding to
sensor_locations (cached after first access; invalidated by
select_sensors). sensor_locations are raw-grid indices
(var * Nx * Ny + g), whereas the POD basis rows follow the masked flat
ordering -- this property maps between the two, via
grid_index_to_flat_rows. None if sensor_locations is None.
domain_of_measurement
property
writable
¶
list: Sub-domain [x0, x1, y0, y1] sensors may be placed in. Defaults
to the full domain if never set.
down_sample_measurement
property
writable
¶
list of int or None: Grid down-sampling factors [step_x, step_y]
applied to the measurement grid before sensor placement. None (no
down-sampling) if never set.
grid_of_measurement
property
¶
np.ndarray: Flat-grid indices (fluid cells only, all velocity
components) eligible for sensor placement, i.e. domain_of_measurement
down-sampled by down_sample_measurement and intersected with
fluid_mask_flat.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
get_POD_coefficients(Nt=1)
¶
Read the forecasted POD temporal coefficients off the state history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of trailing history steps to return. Default 1. |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
\(\boldsymbol{\Phi}\)-block of |
Source code in src/models/data_driven/pod_esn.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
get_observables(Nt=1, Phi=None, **kwargs)
¶
Map the (forecasted) POD coefficients to observables: the coefficients
themselves if measure_modes, otherwise physical-space sensor readings
obtained via decode at sensor_rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of trailing history steps to return. Default 1. |
1
|
Phi
|
ndarray
|
POD coefficients to decode, shape |
None
|
**kwargs
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Observables, shape |
Source code in src/models/data_driven/pod_esn.py
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 | |
reset_case(reset_POD=False, reset_ESN=False, Phi0=None, **kwargs)
¶
Optionally rerun the POD decomposition and/or reset (retrain) the ESN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_POD
|
bool
|
If True, rerun the POD decomposition ( |
False
|
reset_ESN
|
bool
|
If True, reset the |
False
|
Phi0
|
ndarray
|
Passed to |
None
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/models/data_driven/pod_esn.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
select_sensors(measure_modes=False, domain_of_measurement=None, down_sample_measurement=None, N_sensors=None, qr_selection=False)
¶
(Re)configure how the model is observed: either the raw POD coefficients
(measure_modes) or physical-space point sensors placed by define_sensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure_modes
|
bool
|
If True, observe the POD coefficients directly ( |
False
|
domain_of_measurement
|
list
|
Sub-domain |
None
|
down_sample_measurement
|
int or (int, int)
|
Grid down-sampling factor(s) for the measurement domain. |
None
|
N_sensors
|
int
|
Number of sensor locations to place. Defaults to |
None
|
qr_selection
|
bool
|
Whether to use QR-pivoting sensor placement ( |
False
|
Returns:
| Type | Description |
|---|---|
None
|
Sets |
Source code in src/models/data_driven/pod_esn.py
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 | |
define_sensors(N_sensors=None, plot=False)
¶
Choose sensor grid locations within grid_of_measurement.
If qr_selection, uses column-pivoted QR on the (physical-grid) spatial
modes Psi restricted to the candidate locations, so the chosen sensors
best condition the mode-reconstruction problem (a greedy, deterministic
sensor-placement heuristic); otherwise picks N_sensors random locations
(rng).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N_sensors
|
int
|
Number of sensor locations to place. Defaults to |
None
|
plot
|
bool
|
Show the debug scatter of grid/measurement domain/sensors (blocks in interactive backends). Default False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Flat-grid sensor indices, one block per velocity component, shape
|
Source code in src/models/data_driven/pod_esn.py
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 | |
plot_case(case, datasets=None, num_modes=None)
staticmethod
¶
Plot the POD modes, temporal coefficients, spectrum and (if datasets
is given) flow/reconstruction/error fields with sensor locations overlaid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
POD_ESN
|
Instance to plot. |
required |
datasets
|
dict
|
Named fields to pass to |
None
|
num_modes
|
int
|
Number of POD modes to show. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/models/data_driven/pod_esn.py
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 | |
romda.models.data_driven.linear_model.LinearModel(F, M_obs=None, psi0=None, dt=1.0, Q=None, **model_dict)
¶
Bases: Model
Simple linear state-space forecast model.
where \(\mathbf{F}\) is the \((N_\phi \times N_\phi)\) state transition matrix and
\(\boldsymbol{\eta}_t \sim \mathcal{N}(\mathbf{0}, \mathbf{Q})\) is optional
zero-mean Gaussian process noise with covariance \(\mathbf{Q}\) (Q_noise).
Uses DiscreteIntegrator (a fixed-step map), so it only requires a time_step
method instead of a continuous time_derivative.
Build a LinearModel from a fixed state transition matrix F.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray
|
State transition matrix, shape |
required |
M_obs
|
ndarray
|
Observation (measurement) operator, shape |
None
|
psi0
|
ndarray
|
Initial state, shape |
None
|
dt
|
float
|
Time step. Default 1.0. |
1.0
|
Q
|
ndarray
|
Process noise covariance |
None
|
**model_dict
|
Additional |
{}
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in src/models/data_driven/linear_model.py
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 | |
state_labels
property
¶
list of str: LaTeX labels for the state vector, \(x_0, \dots, x_{N_\phi-1}\).
obs_labels
property
¶
list of str: LaTeX labels for the observed outputs, \(y_0, \dots, y_{N_q-1}\).
time_step(Nt)
¶
Propagate the state forward Nt steps,
\(\boldsymbol{\psi}_{k+1} = \mathbf{F}\boldsymbol{\psi}_k + \boldsymbol{\eta}_k\)
with \(\boldsymbol{\eta}_k \sim \mathcal{N}(\mathbf{0}, \mathbf{Q})\) added if
Q_noise is non-zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of steps to propagate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
psi_out |
ndarray
|
State trajectory, shape |
t_out |
ndarray
|
Corresponding time points, shape |
Source code in src/models/data_driven/linear_model.py
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 | |
get_observables(Nt=1, **kwargs)
¶
Map the trailing states to observables, \(\mathbf{y} = \mathbf{M}_\mathrm{obs}\boldsymbol{\psi}\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of trailing time steps to return (same convention as
|
1
|
**kwargs
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Observed outputs, shape |
Source code in src/models/data_driven/linear_model.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
Modal decompositions (projectors)¶
romda.models.data_driven.autoencoders.Projector
¶
Bases: ABC
Abstract base for all dimensionality-reduction building blocks, linear
(POD, SPOD) or nonlinear (autoencoders).
Every projector shares the same sklearn-style interface: fit learns the
representation from data, encode maps state space to the latent space,
and decode maps back. reconstruct and score are provided as
concrete methods built on top of encode/decode.
Attributes:
| Name | Type | Description |
|---|---|---|
N_latent |
int
|
Size of the latent (bottleneck) space. For |
fitted |
bool
|
Whether |
Q_mean |
ndarray
|
Temporal mean removed from the data during preprocessing, shape
\((N_x, 1)\). Raises |
fit(X)
abstractmethod
¶
Learn the projection from data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Snapshot data, shape \((N_x, N_t)\). |
required |
Returns:
| Type | Description |
|---|---|
Projector
|
The fitted instance ( |
Source code in src/models/data_driven/autoencoders/__init__.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
encode(X)
abstractmethod
¶
Map snapshot data to the latent representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Snapshot data, shape \((N_x, N_t)\). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Latent coefficients \(\mathbf{Z}\), shape \((N_\mathrm{latent}, N_t)\). |
Source code in src/models/data_driven/autoencoders/__init__.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
decode(Z)
abstractmethod
¶
Map latent coefficients back to state space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
ndarray
|
Latent coefficients, shape \((N_\mathrm{latent}, N_t)\). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Reconstructed state \(\hat{\mathbf{X}}\), shape \((N_x, N_t)\). |
Source code in src/models/data_driven/autoencoders/__init__.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
reconstruct(X)
¶
Full round-trip: encode then decode.
Source code in src/models/data_driven/autoencoders/__init__.py
131 132 133 | |
score(X)
¶
Mean squared reconstruction error in the flat, zero-mean space,
where \(\mathbf{Q} = \mathrm{preprocess}(X)\) and
\(\hat{\mathbf{Q}} = \mathrm{decode}(\mathrm{encode}(X)) - \bar{\mathbf{Q}}\)
(with \(\bar{\mathbf{Q}}\) the stored Q_mean).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Snapshot data, shape \((N_x, N_t)\). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean squared reconstruction error. |
Source code in src/models/data_driven/autoencoders/__init__.py
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 | |
grid_index_to_flat_rows(grid_idx)
¶
Map raw-grid indices to rows of the masked flat representation (Psi / Q_mean rows).
Both the raw grid and the flat representation use variable-block ordering: raw index = var * Nx * Ny + g (g = flattened (x, y) position), flat row = var * N_fluid + fluid_pos (position of g among the fluid points).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_idx
|
array-like of int
|
Raw-grid indices (e.g., sensor locations). Must correspond to fluid points. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray of int
|
Row indices into Psi / Q_mean corresponding to the requested grid points. |
Source code in src/models/data_driven/autoencoders/__init__.py
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 | |
preprocess_snapshot(X, subtract_mean=True)
¶
Build the zero-mean data matrix from raw snapshot fields, automatically detecting and removing NaN-masked solid-body points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Raw snapshot data, either a single field \((N_t, N_x, N_y)\) or a stack of fields \((N_u, N_t, N_x, N_y)\). |
required |
subtract_mean
|
bool
|
If True (default), subtract the temporal mean row-wise. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Zero-mean data matrix \(\mathbf{Q}\), shape \((N_\mathrm{fluid} \cdot n_\mathrm{fields}, N_t)\), ready for decomposition. |
Source code in src/models/data_driven/autoencoders/__init__.py
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 302 303 304 305 306 307 308 309 310 311 312 313 | |
romda.models.data_driven.autoencoders.POD(n_modes=20, method='randomized', n_iter=4, random_state=None, grid_shape=None, domain=None, **kwargs)
¶
Bases: Projector
Snapshot POD.
Inherits the shared interface from Projector (fit/encode/decode/
reconstruct/score/N_latent) and adds linear-specific attributes,
geometry helpers, and plotting utilities.
Two solvers are available via method:
'exact'— full eigendecomposition of the temporal correlation matrix \(\mathbf{C} = \mathbf{Q}^\mathrm{T}\mathbf{Q} / N_t\) (Sirovich 1987, snapshot method: seesnapshot_pod). Exact but \(\mathcal{O}(N_t^3)\).'randomized'(default) — randomized SVD of \(\mathbf{Q}\) (Halko, Martinsson & Tropp 2011: seesnapshot_pod_randomized). Returns only the leadingn_modesmodes; fast and memory-efficient.
Either way, writing \(\mathbf{Q} = \mathbf{X} - \bar{\mathbf{Q}}\) for the zero-mean
data matrix, fit(X) stores the orthonormal spatial modes \(\boldsymbol{\Psi}\)
and singular values \(\boldsymbol{\Sigma}\) of \(\mathbf{Q}\), together with the
temporal coefficients \(\boldsymbol{\Phi} = \boldsymbol{\Psi}^\mathrm{T}\mathbf{Q}\),
so that
with equality when all \(N_t\) modes are retained (n_modes >= N_t, method='exact').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_modes
|
int
|
Number of modes retained (the latent-space size). Default 20. |
20
|
method
|
str
|
|
'randomized'
|
n_iter
|
int
|
Power-iteration steps for the randomized solver. Default 4. |
4
|
random_state
|
int
|
Seed for reproducibility of the randomized solver. |
None
|
grid_shape
|
tuple
|
Grid shape |
None
|
domain
|
list
|
Physical domain |
None
|
**kwargs
|
Pre-set any instance attribute (e.g. pre-computed |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
Sigma |
ndarray
|
Singular values (descending), shape \((N_\mathrm{latent},)\). |
Psi |
ndarray
|
Spatial modes with orthonormal columns, shape \((N_x, N_\mathrm{latent})\). |
Phi |
ndarray
|
Temporal coefficients, shape \((N_\mathrm{latent}, N_t)\). |
Q_mean |
ndarray
|
Temporal mean \(\bar{\mathbf{Q}}\), shape \((N_x, 1)\). |
References
Sirovich (1987). Turbulence and the dynamics of coherent structures. Quart. Appl. Math., XLV(3), 561-590.
Halko, Martinsson & Tropp (2011). Finding structure with randomness. SIAM Review, 53(2), 217-288.
Source code in src/models/data_driven/autoencoders/pod.py
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 | |
N_modes
property
writable
¶
Backward-compatible alias for N_latent.
domain_mesh
property
¶
Meshgrid for the spatial domain.
Returns:
| Name | Type | Description |
|---|---|---|
X1 |
ndarray
|
First coordinate array, shape |
X2 |
ndarray
|
Second coordinate array, shape |
fit(X)
¶
Fit the POD to data X.
Accepts a flat matrix \((N_x, N_t)\) or a raw grid array \((N_u, N_t, N_x, N_y)\) / \((N_t, N_x, N_y)\). For raw grid input the NaN solid-body mask is detected and stored automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Snapshot data, flat or raw grid (see above). |
required |
Returns:
| Type | Description |
|---|---|
POD
|
The fitted instance ( |
Source code in src/models/data_driven/autoencoders/pod.py
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 | |
encode(X)
¶
Project X onto the spatial modes,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Snapshot data, shape \((N_x, N_t)\). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Latent (POD) coefficients \(\mathbf{Z}\), shape \((N_\mathrm{latent}, N_t)\). |
Source code in src/models/data_driven/autoencoders/pod.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
decode(Z, idx=None)
¶
Reconstruct the state in the original space from latent coefficients,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
ndarray
|
Latent coefficients, shape \((N_\mathrm{latent}, N_t)\). |
required |
idx
|
ndarray
|
Indices selecting a subset of rows of |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Reconstructed state, shape \((N_x, N_t)\), or |
Source code in src/models/data_driven/autoencoders/pod.py
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 | |
reconstruct(X=None, n_modes=None, Phi=None)
¶
Full round-trip: encode, decode, then map back to the physical grid (when a grid mask is available).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Raw input, grid or flat. If None, the stored |
None
|
n_modes
|
int
|
Retain only the first |
None
|
Phi
|
ndarray
|
Pre-computed latent coefficients, shape \((N_\mathrm{latent}, N_t)\);
skips the |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Reconstructed state, on the physical grid if |
Source code in src/models/data_driven/autoencoders/pod.py
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 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
energy_fraction()
¶
Relative and cumulative energy per mode, from the eigenvalues \(\lambda_j = \Sigma_j^2\) of the temporal correlation matrix \(\mathbf{C}\):
Returns:
| Name | Type | Description |
|---|---|---|
rel |
ndarray
|
Relative energy per mode, shape \((N_\mathrm{latent},)\). |
cum |
ndarray
|
Cumulative energy fraction captured by the first \(j\) modes, shape \((N_\mathrm{latent},)\). |
Source code in src/models/data_driven/autoencoders/pod.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
truncate(n_modes)
¶
Truncate to the first n_modes modes in-place.
Source code in src/models/data_driven/autoencoders/pod.py
343 344 345 346 347 348 349 350 351 352 | |
original_data_to_domain_of_interest(original_data)
¶
Crop original-grid data to the fitted domain of interest.
Source code in src/models/data_driven/autoencoders/pod.py
373 374 375 376 377 378 379 380 381 382 383 384 385 | |
compute_MSE(ROM_data, original_data, time_evolution=False)
staticmethod
¶
Mean Squared Error between ROM reconstruction and original data.
Source code in src/models/data_driven/autoencoders/pod.py
390 391 392 393 394 395 396 397 398 | |
compute_RMS(ROM_data, original_data)
staticmethod
¶
Root Mean Square error (field).
Source code in src/models/data_driven/autoencoders/pod.py
400 401 402 403 404 | |
flatten(*args)
staticmethod
¶
Flatten multi-dimensional arrays to 2-D (space × time).
Source code in src/models/data_driven/autoencoders/pod.py
406 407 408 409 410 | |
romda.models.data_driven.autoencoders.SPOD(Nf=0, filter_kind='gaussian', n_modes=20, grid_shape=None, domain=None, **kwargs)
¶
Bases: POD
Spectral POD via the filtered correlation matrix (Sieber, Paschereit & Oberleithner, 2016).
Inherits the full POD interface (fit/encode/decode/reconstruct);
only _decompose is overridden, delegating to spod_sieber. The snapshot
correlation matrix \(\mathbf{C} = \mathbf{Q}^\mathrm{T}\mathbf{Q}/N_t\) is
replaced by a low-pass filtered version before the eigensolve,
where \(\mathbf{G}\) is a banded symmetric Toeplitz filter matrix built from a
normalised 1-D kernel of half-width Nf (filter_kind selects
'gaussian', 'box' or 'hann'). The eigendecomposition of
\(\tilde{\mathbf{C}}\) then follows exactly as in snapshot_pod, giving
orthonormal spatial modes \(\boldsymbol{\Psi}\), temporal coefficients
\(\boldsymbol{\Phi} = \boldsymbol{\Psi}^\mathrm{T}\mathbf{Q}\) and singular
values \(\boldsymbol{\Sigma}\). Setting Nf=0 skips the filtering step and
exactly recovers snapshot POD; per Sieber et al. (2016), as Nf grows
towards \(N_t/2\) the SPOD modes are reported to approach Fourier (DFT) modes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nf
|
int
|
Filter half-width (0 recovers POD; \(N_t/2\) approaches the DFT limit). |
0
|
filter_kind
|
str
|
|
'gaussian'
|
n_modes
|
int
|
Number of modes to retain. Default 20. |
20
|
grid_shape
|
tuple
|
Grid shape |
None
|
domain
|
list
|
Physical domain |
None
|
**kwargs
|
Forwarded to |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
C_tilde |
ndarray
|
Filtered correlation matrix \(\tilde{\mathbf{C}}\), shape \((N_t, N_t)\)
(stored after |
References
Sieber, Paschereit & Oberleithner (2016). Spectral proper orthogonal decomposition. J. Fluid Mech., 792, 798–828.
Source code in src/models/data_driven/autoencoders/pod.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
romda.models.data_driven.autoencoders.pod_utils.snapshot_pod(Q)
¶
Snapshot POD — exact solver.
Solves the eigenvalue problem of the temporal correlation matrix,
and reconstructs the (large) spatial modes from the eigenvectors \(\mathbf{A}\) of the (small, \(N_t \times N_t\)) matrix \(\mathbf{C}\) — the "method of snapshots" of Sirovich (1987):
\(\boldsymbol{\Psi}\) has orthonormal columns and, for the modes with \(\lambda_j > 0\), \(\mathbf{Q} = \boldsymbol{\Psi}\boldsymbol{\Phi}\) exactly. Modes with \(\lambda_j \le 0\) (numerical noise) are set to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
ndarray
|
Zero-mean data matrix, shape \((N_x, N_t)\). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Sigma |
ndarray
|
Singular values (descending), shape \((N_t,)\). |
Psi |
ndarray
|
Spatial modes with orthonormal columns, shape \((N_x, N_t)\). |
Phi |
ndarray
|
Temporal coefficients, shape \((N_t, N_t)\). |
C |
ndarray
|
Temporal correlation matrix, shape \((N_t, N_t)\). |
References
Sirovich (1987). Turbulence and the dynamics of coherent structures. Quart. Appl. Math., XLV(3), 561–590.
Source code in src/models/data_driven/autoencoders/pod_utils.py
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 | |
romda.models.data_driven.autoencoders.pod_utils.snapshot_pod_randomized(Q, n_modes=20, n_iter=4, random_state=None)
¶
Randomized snapshot POD.
Computes a truncated randomized SVD of \(\mathbf{Q}\) (via
sklearn.utils.extmath.randomized_svd, falling back to a full
numpy.linalg.svd if scikit-learn is unavailable),
and returns
The \(\boldsymbol{\Sigma} = \mathbf{S}/\sqrt{N_t}\) scaling matches the
eigenvalue-based normalisation of snapshot_pod, since
\(\mathbf{Q}^\mathrm{T}\mathbf{Q}/N_t = \mathbf{V}(\mathbf{S}^2/N_t)\mathbf{V}^\mathrm{T}\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
ndarray
|
Zero-mean data matrix, shape \((N_x, N_t)\). |
required |
n_modes
|
int
|
Leading modes to compute. Default 20. |
20
|
n_iter
|
int
|
Power-iteration steps. Default 4. |
4
|
random_state
|
int
|
Seed for reproducibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Sigma |
ndarray
|
Singular values (descending), shape \((N_\mathrm{modes},)\). |
Psi |
ndarray
|
Spatial modes (approximately orthonormal), shape \((N_x, N_\mathrm{modes})\). |
Phi |
ndarray
|
Temporal coefficients, shape \((N_\mathrm{modes}, N_t)\). |
References
Halko, Martinsson & Tropp (2011). Finding structure with randomness. SIAM Review, 53(2), 217–288.
Source code in src/models/data_driven/autoencoders/pod_utils.py
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 221 | |
romda.models.data_driven.autoencoders.pod_utils.spod_sieber(Q, Nf, kind='gaussian')
¶
Sieber spectral POD — filtered correlation matrix.
Low-pass filters the temporal correlation matrix
\(\mathbf{C} = \mathbf{Q}^\mathrm{T}\mathbf{Q}/N_t\) with the banded
symmetric Toeplitz matrix \(\mathbf{G}\) (see _toeplitz_filter_matrix,
built from a normalised kernel of half-width Nf, see
_filter_kernel),
then solves the same "method of snapshots" eigenvalue problem as
snapshot_pod, with \(\tilde{\mathbf{C}}\) in place of \(\mathbf{C}\):
Nf=0 skips the filtering step (\(\tilde{\mathbf{C}} = \mathbf{C}\)) and
recovers standard snapshot POD exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
ndarray
|
Zero-mean data matrix, shape \((N_x, N_t)\). |
required |
Nf
|
int
|
Filter half-width (0 recovers POD; \(N_t/2\) approaches the DFT). |
required |
kind
|
str
|
|
'gaussian'
|
Returns:
| Name | Type | Description |
|---|---|---|
Sigma |
ndarray
|
Singular values (descending), shape \((N_t,)\). |
Psi |
ndarray
|
Spatial modes with orthonormal columns, shape \((N_x, N_t)\). |
Phi |
ndarray
|
Temporal SPOD coefficients, shape \((N_t, N_t)\). |
C_tilde |
ndarray
|
Filtered correlation matrix, shape \((N_t, N_t)\). |
References
Sieber, Paschereit & Oberleithner (2016). Spectral proper orthogonal decomposition. J. Fluid Mech., 792, 798–828.
Source code in src/models/data_driven/autoencoders/pod_utils.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 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 | |
romda.models.data_driven.autoencoders.pod_utils.spod_towne(Q, dt=1.0, n_fft=None, n_ovlp=None, window='hamming', weight=None, conf_level=0.95)
¶
Spectral POD via Welch-averaged cross-spectral density (Towne et al., 2018).
Splits \(\mathbf{Q}\) into n_blks overlapping blocks of length n_fft
(Welch's method, step n_fft - n_ovlp), windows and Fourier-transforms
each block, then — at every frequency — solves a "method of snapshots"
eigenvalue problem across blocks (analogous to snapshot_pod, but with
blocks in place of time snapshots) to avoid ever forming the full
\(N_x \times N_x\) cross-spectral density (CSD) matrix.
For block \(b = 0, \dots, n_\mathrm{blk}-1\) starting at snapshot \(b\,(n_\mathrm{fft}-n_\mathrm{ovlp})\), the windowed block DFT at frequency \(f_k\) is
with \(w\) the window. Stacking the blocks,
\(\hat{\mathbf{Q}}_k = [\hat{\mathbf{q}}^{(1)}_k, \dots,
\hat{\mathbf{q}}^{(n_\mathrm{blk})}_k] \in \mathbb{C}^{N_x \times n_\mathrm{blk}}\),
the (weighted) cross-block Gram matrix and its eigendecomposition give the
SPOD modes and modal energies at frequency \(f_k\):
with \(\mathbf{W} = \mathrm{diag}(\mathrm{weight})\) the spatial weight matrix (\(\mathbb{I}\) by default). The modal energy spectrum is \(L_k = \boldsymbol{\lambda}_k\), doubled (\(L_k = 2\boldsymbol{\lambda}_k\)) at interior frequency bins of a real, one-sided spectrum to account for the folded negative-frequency energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
ndarray
|
Zero-mean data matrix, shape \((N_x, N_t)\). |
required |
dt
|
float
|
Time step. |
1.0
|
n_fft
|
int
|
Block/FFT length. Default \(2^{\lfloor \log_2 (N_t / 10) \rfloor}\). |
None
|
n_ovlp
|
int
|
Block overlap. Default |
None
|
window
|
str or ndarray
|
Window name (passed to |
'hamming'
|
weight
|
ndarray
|
Spatial integration weights \(\mathrm{diag}(\mathbf{W})\), shape \((N_x,)\). Uniform weights (no integration) by default. |
None
|
conf_level
|
float
|
Target confidence level for the chi-squared-based interval |
0.95
|
Returns:
| Name | Type | Description |
|---|---|---|
L |
ndarray
|
Modal energy spectrum, shape |
Psi |
ndarray
|
Complex SPOD spatial modes, shape |
f |
ndarray
|
Frequency vector, shape |
Lc |
ndarray
|
Nominal confidence bounds |
info |
dict
|
Effective |
Notes
Lc is computed from scipy.special.gammaincinv(1 - conf_level, n_blks)
and scipy.special.gammaincinv(conf_level, n_blks), intended as a
chi-squared confidence interval in the spirit of Welch's method. However,
scipy.special.gammaincinv(a, y) requires its second argument \(y\)
(a probability) in \([0, 1]\), whereas here it is called with \(y =\)
n_blks (an integer \(\ge 2\)); numerically this returns nan for the
n_blks values produced by this function. Treat Lc as unverified
until this is checked against the intended formula.
References
Towne, Schmidt & Colonius (2018). Spectral proper orthogonal decomposition and its relationship to dynamic mode decomposition and resolvent analysis. J. Fluid Mech., 847, 821–867.
Source code in src/models/data_driven/autoencoders/pod_utils.py
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 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 | |
romda.models.data_driven.autoencoders.pod_utils.spod_towne_reconstruct(Psi, A_blk, n_fft, n_ovlp, N_t)
¶
Reconstruct snapshots from Towne SPOD modes [stub — not yet implemented].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Psi
|
ndarray
|
SPOD spatial modes, as returned by |
required |
A_blk
|
ndarray
|
Block expansion coefficients. |
required |
n_fft
|
int
|
Block/FFT length used by |
required |
n_ovlp
|
int
|
Block overlap used by |
required |
N_t
|
int
|
Number of snapshots in the reconstructed series. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — inverse SPOD is not yet implemented. |
References
Nekkanti & Schmidt (2021). Frequency-time analysis, low-rank reconstruction and denoising of turbulent flows using SPOD. J. Fluid Mech., 926, A26.
Source code in src/models/data_driven/autoencoders/pod_utils.py
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 | |
romda.models.data_driven.autoencoders.pod_utils.print_spod_towne_summary(info)
¶
Pretty-print the block/frequency parameters of a spod_towne run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
dict
|
The |
required |
Source code in src/models/data_driven/autoencoders/pod_utils.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
romda.models.data_driven.autoencoders.pod_utils.energy_fraction(Sigma)
¶
Relative energy fraction and cumulative energy per mode.
From the eigenvalues \(\lambda_j = \Sigma_j^2\) of the (possibly filtered) temporal correlation matrix,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Sigma
|
ndarray
|
Singular values, as returned by |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rel |
ndarray
|
Relative energy per mode (sums to 1). |
cum |
ndarray
|
Cumulative relative energy. |
Source code in src/models/data_driven/autoencoders/pod_utils.py
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 | |