Skip to main content

3. Delay embedding

From time series to samples of recent history

The delay embedding block of the NLSA Python toolkit: delay windows, the bookkeeping of samples reserved for forecasts and finite differences, velocities for the cone kernel, and the functions that build the space of samples.

A single snapshot of the predictors rarely determines how the system will evolve: two months with the same sea surface temperature can belong to a developing or a decaying El Niño. Delay embedding represents each time by its recent history instead. Sample n is the window of 2h + 1 consecutive snapshots

\[ x_n = \big(y_{n}, \, y_{n+1}, \, \dots, \, y_{n+2h}\big), \]

where \(y_t\) is the predictor vector at time t and h is num_half_delays. A window of 13 months (h = 6) is used in the Niño 3.4 forecasts and of 49 months (h = 24) in the Koopman analysis. The theory behind delay embedding, and why it helps the kernel and Koopman methods, is outlined under Data-driven methods (see also Das and Giannakis 2019).

A forecast made from sample n uses the window up to its last snapshot, so the initial time of the forecast is the end of the window, and lead time q is verified against the target q steps after it. No information from after the initial time is used.

Options

Delay embedding is set in the same DataPars object as the data:

DataPars (nlsa_models.climate, defined in src/nlsa_models/climate.py)
Option Type or values Default Description
num_half_delays int 0 Half-width h of the delay window. Each sample is represented by 2h + 1 consecutive snapshots (2h delays); 0 means no delay embedding.
delay_embedding_mode "explicit" or "on_the_fly" "on_the_fly" How delay vectors are formed: "on_the_fly" assembles each window when it is needed (low memory); "explicit" builds the matrix of all windows (Hankel matrix) once (more memory). In the climate pipeline this field is currently not read: the builder functions such as make_data_driven_l2_space take their own delay_embedding_mode argument, which defaults to "on_the_fly".
num_before int 0 Extra samples reserved before the first delay window. The Koopman generator needs fd_order // 2 of them for its finite differences.
num_after int 0 Extra samples reserved after the last sample, so that future values are available. For kernel analog forecasting it must be at least the number of prediction steps; the Koopman generator needs fd_order // 2 more.
velocity_covariate bool False Add the time tendency (a finite-difference velocity) to every snapshot. Required by the cone kernel.
velocity_fd_order 2 or 4 or 6 or 8 or None None Order (2, 4, 6 or 8) of the central finite difference used for the velocities. It also reserves that many samples, half at each end of the record.
eval_batch_size int or None None Evaluate functions on the samples in batches of this size, to reduce memory. None evaluates all samples at once.

How many samples

From a record of T time steps, the code keeps N samples and reserves the rest:

\[ N = T - 2h - n_b - n_a - n_v , \]

with h = num_half_delays, \(n_b\) = num_before, \(n_a\) = num_after, and \(n_v\) = velocity_fd_order if velocities are used (0 otherwise). The record is laid out like this:

Layout of the T time steps of a record
Segment, in time order Length Why it is reserved
Start of the record \(n_v/2\) The finite-difference velocities are not valid at the ends of the record
Before the windows \(n_b\) Room for the finite differences of the Koopman generator
History of the first window 2h The delays of the first sample
Ends of the N windows N The samples: initial times of the forecasts
After the windows \(n_a\) Future values for forecasts, finite differences or quadrature
End of the record \(n_v/2\) Velocities not valid

DataPars computes these numbers from the dates and the options:

Derived properties of DataPars
Property Value Meaning
num_total_samples T Time steps between the first and last date of the period
num_delays 2h Delays per window
num_velocity_fd \(n_v\) Time steps reserved for velocities
num_samples N Samples after embedding
num_delay_samples 2h + N Time steps covered by the windows
delay_embedding_origin \(n_v/2 + n_b\) Index of the first snapshot of the first window
delay_embedding_center origin + h Index of the centre of the first window; used to align spatial patterns
delay_embedding_end origin + 2h Index of the last snapshot of the first window: the first initial time

The text form of a DataPars object, used as a folder name, records these choices: ns920_nd12_nb0_na24_vfd4 means N = 920 samples, 12 delays, \(n_b\) = 0, \(n_a\) = 24 and fourth-order velocities. Examples from the ENSO scripts:

Sample counts in the ENSO examples (forecasts with num_after added as described on the Experiments page)
Data Period T h \(n_v\) \(n_b\) \(n_a\) N
Niño 3.4 forecasts, training 1940–2019 960 6 4 0 24 920
Niño 3.4 forecasts, test 2018–2025 96 6 4 0 24 56
Koopman analysis, training 1940–2019 960 24 0 2 26 884
Koopman analysis of Niño 3.4 SST, test 2016–2025 120 24 0 0 24 48

What needs extra samples

Calculations that need samples beyond the windows
Calculation Needs Setting
Kernel analog forecast to Q steps The target at the Q times after each training sample num_after ≥ Q in the training data
Skill scores to Q steps The target at the Q times after each test sample num_after ≥ Q in the test data
Koopman generator, finite differences of order p p/2 snapshots before and after each window num_before ≥ p/2 and num_after ≥ p/2 (plus Q for forecasts) in the training data
Compactified integral transform with num_quad steps The num_quad snapshots after each window num_after ≥ num_quad in the training data
Velocities of order \(n_v\) \(n_v/2\) snapshots at each end Reserved automatically

These requirements are not checked when the parameters are created. With too small a num_after or num_before, the slices of the record come out too short, and the run usually stops later with an error about mismatched array shapes. The ENSO Koopman script sets them with num_before=fd_order // 2 and num_after=fd_order // 2 + num_pred_steps.

Velocities

With velocity_covariate=True, the rate of change of every predictor is computed by a central finite difference of order velocity_fd_order (2, 4, 6 or 8) and stored next to the values, so that each snapshot becomes a pair (value, velocity) and each window a pair of delay vectors. The cone kernel needs these velocities; in the example scripts, CONE_KERNEL = True switches them on. Time is counted in samples, so the velocities are changes per month or per day.

Delay embedding modes and memory

The delay vectors are long: (2h + 1) × (number of predictor columns). The Niño 3.4 predictors have 561 columns (grid points at 1° spacing), so a 13-month window holds 7,293 numbers, and twice as many with velocities. There are two ways to handle them:

  • "on_the_fly": keep the time series and assemble each window when a function is evaluated on it. This uses little memory and is the default.
  • "explicit": build the matrix of all windows (a Hankel matrix) once, which needs (2h + 1) times the memory of the data.

eval_batch_size evaluates functions on the samples in batches, which lowers peak memory further.

Note

In the climate pipeline the field DataPars.delay_embedding_mode is currently not read. The functions below take their own delay_embedding_mode argument, which is "on_the_fly" unless passed explicitly. The Lorenz 63 module does use the field.

Functions

Functions of the delay embedding block (nlsa_models.climate)
Function What it returns
clim.make_data_driven_l2_space A function impl_l2; impl_l2(data) is the space of functions on the N delay-embedded samples, each with weight 1/N. All kernel, Koopman and forecasting steps take it as an argument. Arguments: data_pars, dtype, and optionally delay_embedding_mode, shardings, jit.
clim.make_data_driven_evaluation_functional Evaluates a function on the windows, extended by num_before and num_after extra samples. Used to compute a Koopman eigenfunction at the future times needed for its forecast.
clim.make_data_driven_tangent_evaluation_functional_fd Pairs each window with its time derivative, by finite differences of order fd_order: the input of the Koopman generator.

The low-level operations are in nlsa.jax.delays: delay_eval_at (evaluation on windows assembled on the fly), hankel (explicit windows) and make_fd_operator (finite differences).

How to choose the window length is discussed in Choosing hyperparameters.

References

Das, S., and D. Giannakis. 2019. “Delay-Coordinate Maps and the Spectra of Koopman Operators.” Journal of Statistical Physics 175 (6): 1107–45. https://doi.org/10.1007/s10955-019-02272-w.