Koopman Kernel DMD: PyTorch Architecture

Navigation:

Overview & Formula Token

formula = "Y ~ koopman(temperature, k=18, delay_embed=8, n_lift=64)"

Parameter Specification

Parameter

Type

Default

Description

feature_name

str

required

Input dynamical observable column.

k

int

12

Number of Koopman eigenmodes retained.

n_lift

int

64

Random Fourier dictionary dimension for EDMD lifting.

delay_embed

int

1

Hankel time-delay embedding depth.

alpha_res

float

10.0

Spectral residual penalty weight.

alpha_unit

float

10.0

Unit-circle eigenvalue deviation penalty weight.

Complexity & Performance

  • Closed-Form EDMD: Estimates the finite-dimensional Koopman generator \(K_{\text{EDMD}}\) via Ridge regression on lifted delay coordinates and carries the trailing delay rows of every group across splits via state_in / _state_out.

State, Complexity and Limits

  • Class and file: KoopmanEffect, src/tam/model/spectrum/_koopman.py. Label: (BETA).

  • State: {"hist": (B, delay_embed - 1, d)} when delay_embed > 1 (stateful), none otherwise. Layout: (B, T, d); others= adds columns to the delay embedding.

  • Columns: exactly k, always. get_n_coeffs() does not depend on the data.

  • Time and memory: the fit is one SVD of at most 20 000 snapshot rows; a feature map costs \(\mathcal{O}(B\,T\,(d\,d_H)^2)\) for the quadratic lift.

  • Device: the dictionary is drawn on the CPU in float64 and moved to the device of the input.

  • Extrapolation: with a delay embedding 'linear' and 'saturation' are refused at construction.

  • Limits: very short series (fewer than three steps per group) fall back to the first k dictionary directions.

  • Penalty terms: the weight of every dictionary column is \(1 + \alpha_{\text{res}}\, r^2 + \alpha_{\text{unit}}\,(|\mu|^2 - 1)^2\), where \(r^2\) is the ResDMD residual of the mode (how badly its eigenpair satisfies the transition equation on the training snapshots) and \(|\mu|\) the modulus of its eigenvalue; the defaults are alpha_res = alpha_unit = 10. Both terms add to the unit baseline, so a mode that is exact and on the unit circle has weight 1 and a poor mode is shrunk by up to a factor that grows linearly in alpha_res and quadratically in the distance of \(|\mu|^2\) from 1. Pairs of complex-conjugate modes share their weight. The two constants are fixed by the user: the smoothing criterion (GCV or REML) tunes the single scale \(\lambda\) that multiplies the whole penalty, not the two constants.

  • Chunk equivalence bound: tests/spectrum/test_stateful_contract.py checks that the second of two chunks, started from the state of the first, equals the matching rows of the one-pass features within atol=1e-8 (float64), and that every group computed alone equals the same group inside a batch within atol=1e-10.

Code

Feature map of KoopmanEffect (build_feature_map):

    def build_feature_map(self, x_col: torch.Tensor, state_in: Optional[Dict[str, Any]] = None) -> torch.Tensor:
        """Evaluates Koopman eigenfunction feature map along each trajectory: ``(B, T, d)`` in, ``(B, T, k)`` out."""
        if self._W_proj is None:
            self.initialize(x_col)

        x3, shape, layout = to_btd(x_col, True)
        if x3.shape[-1] != self._d_in:
            raise ValueError(f"koopman expects {self._d_in} input column(s), got {x3.shape[-1]}")
        x_h, hist = self._hankel(x3, state_in)
        if self.stateful:
            self._state_out = {"hist": hist}
        psi = self._lift(x_h)

        W = self._W_proj.to(device=psi.device, dtype=psi.dtype)
        return from_btk(psi @ W, shape, layout)

Penalty of KoopmanEffect (build_penalty_matrix):

    def build_penalty_matrix(self) -> torch.Tensor:
        """Returns diagonal penalty matrix weighted by Koopman spectral residuals and lambda_p."""
        if self._penalty_diag is None:
            self._penalty_diag = torch.ones(self.k, device=TORCH_DEVICE, dtype=torch.get_default_dtype())

        return torch.diag(self.lambda_p * self._penalty_diag.to(device=TORCH_DEVICE, dtype=torch.get_default_dtype()))

Parsing of the koopman(...) token in the factory:

        elif ttype == 'koopman':
            k = int(params_resolved.get('k', 12))
            n_lift = int(params_resolved.get('n_lift', 64))
            delay_embed = int(params_resolved.get('delay_embed', 1))
            reg = float(params_resolved.get('reg', 1e-4))
            alpha_res = float(params_resolved.get('alpha_res', 10.0))
            alpha_unit = float(params_resolved.get('alpha_unit', 10.0))
            seed = int(params_resolved.get('seed', 42))
            extrap_val = params_resolved.get('extrapolate', 'continue')
            additional_features = _parse_additional_features(params_resolved)
            effects_list.append(KoopmanEffect(
                feature_name=feature_name,
                k=k,
                n_lift=n_lift,
                delay_embed=delay_embed,
                reg=reg,
                alpha_res=alpha_res,
                alpha_unit=alpha_unit,
                seed=seed,
                lambda_p=lambda_p,
                extrapolate=extrap_val,
                additional_features=additional_features,
            ))