Reference
Metrics¶
Forecast-quality and dynamical metrics for reservoir models, with first-class support for reporting horizons in Lyapunov times — the natural clock of a chaotic attractor — rather than raw integration steps. A valid-prediction time in Lyapunov times (\(\text{VPT}_{\Lambda t} = \text{steps} \cdot dt \cdot \lambda_\mathrm{max}\)) expresses a physical horizon relative to the system's instability rate. Comparisons still require matching error definitions, thresholds, normalization, forecast origins and censoring conventions. Supply the actual sampling interval and a suitable exponent when changing system parameters; canonical table values are reference values for their stated systems.
The conversions, the canonical \(\lambda_\mathrm{max}\) tables, valid_prediction_time,
and reservoir_lyapunov are pure PyTorch/NumPy and always available. The
series- and System-based paths of largest_lyapunov need the optional
resdag[dynamics] extra (tsdynamics, Python ≥ 3.12) — see
Work · Lyapunov time for the prose walkthrough.
Forecast accuracy¶
valid_prediction_time counts the contiguous prefix strictly below its
threshold. Its NRMSE scales come from the supplied truth tensor, and per-step
batch errors are reduced with the median. The common tuning workflow instead
uses fixed training scales; record that distinction when comparing results.
rmse, nrmse and r2 return aggregate scalar errors rather than a valid prefix.
valid_prediction_time
¶
valid_prediction_time(
pred: Tensor,
truth: Tensor,
*,
threshold: float = 0.3,
metric: str = "nrmse",
units: str = "steps",
dt: float | None = None,
lambda_max: float | None = None,
dataset: str | None = None,
**kw: float
) -> float
Valid Prediction Time: contiguous steps a forecast stays accurate.
Per-step error is the NRMSE — the RMSE across feature channels, each
channel normalised by the per-dimension standard deviation of truth over
the (batch, time) axes — reduced across the batch with the median.
The VPT is the number of steps, counting from the start, whose error stays
strictly below threshold (0 if the very first step is already over).
This matches resdag.hpo.losses.forecast_horizon exactly (that copy
is kept out of the optional-HPO import path); see the module docstring.
| PARAMETER | DESCRIPTION |
|---|---|
pred
|
Forecast and ground truth of shape
TYPE:
|
truth
|
Forecast and ground truth of shape
TYPE:
|
threshold
|
NRMSE threshold below which a step counts as "valid".
TYPE:
|
metric
|
Per-step error metric. Only NRMSE is implemented (the reservoir-computing standard); the argument exists for forward compatibility.
TYPE:
|
units
|
Return the horizon in raw steps, or converted to Lyapunov times
(
TYPE:
|
dt
|
Integration step, required for
TYPE:
|
lambda_max
|
Largest Lyapunov exponent, required for
TYPE:
|
dataset
|
A built-in generator name (
TYPE:
|
**kw
|
Extra keys forwarded to inference;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The VPT: an integer step count as a |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Examples:
>>> import torch
>>> pred = torch.zeros(1, 100, 3)
>>> truth = torch.zeros(1, 100, 3)
>>> valid_prediction_time(pred, truth) # identical -> full horizon
100.0
Source code in src/resdag/metrics/forecast.py
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 | |
rmse
¶
Root-mean-square error between a forecast and the truth.
The RMSE is taken over all elements (batch, time, and feature axes),
in the raw units of the data. For a scale-free, threshold-comparable
error use nrmse instead.
| PARAMETER | DESCRIPTION |
|---|---|
pred
|
Forecast and ground truth of shape
TYPE:
|
truth
|
Forecast and ground truth of shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
\(\sqrt{\operatorname{mean}((\hat y - y)^2)}\) over every element. |
Examples:
>>> import torch
>>> x = torch.zeros(1, 10, 3)
>>> rmse(x, x)
0.0
Source code in src/resdag/metrics/observables.py
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 | |
nrmse
¶
Normalised RMSE — scale-free forecast error.
The RMSE is normalised so the metric is invariant to the absolute scale of
the data, which is what makes a fixed error threshold (the basis of
valid_prediction_time) meaningful across systems. Two conventions:
normalization="std"(default) — per-feature RMSE, each channel divided by the per-dimension standard deviation oftruthover the(batch, time)axes, then combined across channels. This is exactly the per-step NRMSE thatvalid_prediction_timethresholds (reduced here over the whole trajectory rather than per step), so the two never disagree.normalization="range"— the scalar RMSE over all elements divided by the peak-to-peak range (max - min) oftruth.
| PARAMETER | DESCRIPTION |
|---|---|
pred
|
Forecast and ground truth of shape
TYPE:
|
truth
|
Forecast and ground truth of shape
TYPE:
|
normalization
|
Whether to normalise by the per-dimension standard deviation of the
truth (the reservoir-computing standard, matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The normalised RMSE ( |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Examples:
>>> import torch
>>> truth = torch.randn(1, 200, 3)
>>> nrmse(truth, truth) # identical
0.0
Source code in src/resdag/metrics/observables.py
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 | |
r2
¶
Coefficient of determination \(R^2\) of a forecast.
The standard variance-explained score, pooled over all elements:
where \(\bar y\) is the grand mean of truth. 1.0 is a perfect
forecast; 0.0 matches the skill of predicting the mean; negative values
are worse than the mean.
| PARAMETER | DESCRIPTION |
|---|---|
pred
|
Forecast and ground truth of shape
TYPE:
|
truth
|
Forecast and ground truth of shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The \(R^2\) score. Returns |
Examples:
>>> import torch
>>> truth = torch.randn(1, 200, 3)
>>> r2(truth, truth)
1.0
Source code in src/resdag/metrics/observables.py
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 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
Lyapunov-time conversions¶
lyapunov_time
¶
Return the Lyapunov time \(t_\lambda = 1 / \lambda_\mathrm{max}\).
One Lyapunov time is the characteristic timescale over which infinitesimally close trajectories of a chaotic system separate by a factor of \(e\).
| PARAMETER | DESCRIPTION |
|---|---|
lambda_max
|
Largest Lyapunov exponent (must be strictly positive for a chaotic system).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The Lyapunov time \(1 / \lambda_\mathrm{max}\), in the same time
units as |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/resdag/metrics/lyapunov.py
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 | |
steps_per_lyapunov_time
¶
Return the number of integration steps in one Lyapunov time.
A convenience for turning a horizon-in-steps into a horizon-in-Lyapunov-times (divide the step count by this) and vice versa.
| PARAMETER | DESCRIPTION |
|---|---|
dt
|
Integration step (time between consecutive samples).
TYPE:
|
lambda_max
|
Largest Lyapunov exponent (strictly positive).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/resdag/metrics/lyapunov.py
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 | |
steps_to_lyapunov
¶
Convert a step count to Lyapunov times \(\Lambda t\).
This is the headline conversion: VPT_in_Lyapunov = steps * dt * lambda_max.
| PARAMETER | DESCRIPTION |
|---|---|
steps
|
Number of integration steps (e.g. a valid-prediction time).
TYPE:
|
dt
|
Integration step.
TYPE:
|
lambda_max
|
Largest Lyapunov exponent (strictly positive).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The horizon expressed in Lyapunov times, |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Examples:
A Lorenz-63 valid-prediction time of 357 steps at dt = 0.02:
>>> round(steps_to_lyapunov(357, dt=0.02, lambda_max=0.9056), 2)
6.47
Source code in src/resdag/metrics/lyapunov.py
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 | |
lyapunov_to_steps
¶
Convert a horizon in Lyapunov times back to a whole number of steps.
The inverse of steps_to_lyapunov, rounded to the nearest integer
step (horizons are discrete step counts).
| PARAMETER | DESCRIPTION |
|---|---|
lyap
|
Horizon in Lyapunov times \(\Lambda t\).
TYPE:
|
dt
|
Integration step.
TYPE:
|
lambda_max
|
Largest Lyapunov exponent (strictly positive).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/resdag/metrics/lyapunov.py
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 | |
Canonical exponents¶
CANONICAL_LAMBDA_MAX
module-attribute
¶
CANONICAL_LAMBDA_MAX: dict[str, float] = {
"lorenz": 0.9056,
"rossler": 0.0714,
"kuramoto_sivashinsky": 0.043,
}
MACKEY_GLASS_LAMBDA
module-attribute
¶
Estimators¶
largest_lyapunov
¶
largest_lyapunov(
source: Any, *, dt: float | None = None, from_: str | None = None, **kw: Any
) -> float
Estimate the largest Lyapunov exponent of source.
A single entry point that dispatches on the type of source:
- generator name (
str, e.g."lorenz","mackey_glass") — returns the canonical literature value fromCANONICAL_LAMBDA_MAX/MACKEY_GLASS_LAMBDA(keyed bytau=for Mackey-Glass). No dependency. - time series (
numpy.ndarray/torch.Tensor) — a diagnostic estimate viatsdynamics.lyapunov_from_data. Data-driven exponents are noisy; you must opt in withfrom_="data"so a series is never silently mistaken for accurate. Needsresdag[dynamics]. - tsdynamics System — a high-accuracy Benettin estimate via
tsdynamics.lyapunov_spectrum. Needsresdag[dynamics].
| PARAMETER | DESCRIPTION |
|---|---|
source
|
What to estimate the exponent of; see above.
TYPE:
|
dt
|
Integration step. Required for the series path; forwarded to the System path if given. Ignored for a generator name.
TYPE:
|
from_
|
Set to
TYPE:
|
**kw
|
Extra arguments:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The estimated largest Lyapunov exponent (inverse natural-time units). |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If a |
TypeError
|
If an array is passed without |
KeyError
|
If a generator name has no canonical value. |
Examples:
>>> largest_lyapunov("lorenz")
0.9056
>>> largest_lyapunov("mackey_glass", tau=17)
0.0086
Source code in src/resdag/metrics/lyapunov.py
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 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 | |
reservoir_lyapunov
¶
reservoir_lyapunov(
source: Any,
warmup_inputs: Tensor | tuple[Tensor, ...],
*,
horizon: int = 1000,
k: int = 1,
transient: int = 100,
seed: int | None = 0
) -> float | ndarray
Largest (or top-k) Lyapunov exponent of a driven ESN reservoir.
Estimates the maximal Lyapunov exponent of the reservoir's own dynamics via Benettin's algorithm with QR reorthonormalisation of the analytic tangent map, iterated along an input-driven reservoir trajectory. This is a sampled local-stability diagnostic. Negative estimates support contraction along the supplied driven trajectory; they do not prove a global Echo State Property for every input. This is distinct from the forecasted attractor's largest Lyapunov exponent.
A local CPU float64 evaluation copy preserves caller weights, device,
cached state and training mode. Training-only noise is disabled. The
validated tangent map supports the standard tanh ESNCell, including
per-neuron leaks, recurrent calibration gains and intrinsic gains/biases.
Other update equations are rejected until their tangent maps are validated.
The reservoir map is the leaky-ESN update
whose Jacobian with respect to the state is
with \(f' = 1 - \tanh^2\) and calibrated gains included in
\(W_\mathrm{hh}\). Scalar leakage generalizes row-wise for vector leaks. The
driving inputs come from warmup_inputs; the trajectory is looped over
them if horizon exceeds their length, so a short synchronisation window
still yields a long tangent-space average.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The reservoir to analyse, or a model containing exactly one ESN reservoir.
TYPE:
|
warmup_inputs
|
Driving inputs of shape
TYPE:
|
horizon
|
Number of tangent-map iterations (after the transient). Longer gives a tighter estimate.
TYPE:
|
k
|
Number of leading exponents to return.
TYPE:
|
transient
|
Additional tangent iterations discarded before the
TYPE:
|
seed
|
Seed for the random initial tangent frame. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float or ndarray
|
The maximal Lyapunov exponent ( |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
NotImplementedError
|
If the cell is not a standard tanh |
Notes
Exponents are per reservoir step. Multiply by 1/dt to compare with
a natural-time attractor exponent from CANONICAL_LAMBDA_MAX.
Examples:
>>> import torch
>>> from resdag.layers import ESNLayer
>>> res = ESNLayer(100, feedback_size=3, spectral_radius=0.9, seed=0)
>>> feedback = torch.randn(1, 300, 3)
>>> lam = reservoir_lyapunov(res, feedback, horizon=500)
>>> lam < 0.0 # contraction along this driven trajectory
True
Source code in src/resdag/metrics/lyapunov.py
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 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
Reservoir and attractor observables¶
memory_capacity
¶
memory_capacity(
source: Any,
*,
max_delay: int = 100,
n_samples: int = 2000,
washout: int = 200,
alpha: float = 1e-08,
input_low: float = -1.0,
input_high: float = 1.0,
seed: int = 0,
return_curve: bool = False,
test_samples: int | None = None
) -> float | tuple[float, ndarray]
Linear short-term memory capacity of a reservoir (Jaeger 2001).
Drives the reservoir with a scalar i.i.d. uniform input \(u_t\) and, for
each delay \(k = 1 \dots\) max_delay, fits a linear readout from
the reservoir state \(h_t\) to the delayed input \(u_{t-k}\). The
memory capacity is the sum of the squared correlations of the reconstruction
the standard forgetting-curve integral (Jaeger, Short-term memory in echo state networks, 2001). Readouts are fitted on one random input trajectory and scored on an independently generated, independently warmed trajectory. No evaluation samples enter fitting or centering statistics.
The theoretical population capacity is at most the number of reservoir
states, under the usual independent-input assumptions. This finite-sample
estimator may exceed that bound through sampling noise, particularly for
many delays and few test samples. It is not guaranteed to increase with
spectral radius. Increase test_samples and repeat seeds to assess
uncertainty; this diagnostic is not an autonomous forecast score.
The actual cell update runs on a local CPU float64 evaluation copy. Caller weights, cached state, device and training mode are preserved. Training-only noise is disabled. One augmented least-squares solve fits all delayed targets together, avoiding the loss of conditioning from normal equations.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The reservoir to probe, or a model containing exactly one ESN reservoir.
The reservoir must accept a scalar feedback (
TYPE:
|
max_delay
|
Largest delay \(k_{\max}\) in the forgetting sum. Should comfortably
exceed the reservoir's memory (a few times
TYPE:
|
n_samples
|
Number of
TYPE:
|
washout
|
Leading driven steps discarded so the reservoir state reflects the input history rather than the (zero) initial condition.
TYPE:
|
alpha
|
Non-negative ridge regularization on centered reservoir features. The intercept is unpenalized. Zero selects an unregularized least-squares fit; positive values stabilize correlated or underdetermined states.
TYPE:
|
input_low
|
Lower bound of the uniform input distribution.
TYPE:
|
input_high
|
Upper bound of the uniform input distribution \(u_t \sim \mathcal{U}(\text{low}, \text{high})\). The default symmetric
TYPE:
|
seed
|
Seed for the input draw, so the estimate is fully deterministic.
TYPE:
|
test_samples
|
Number of independent scoring samples, at least 2.
TYPE:
|
return_curve
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float or tuple of (float, numpy.ndarray)
|
The memory capacity \(MC\). When |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the reservoir needs multiple feedback channels or an external driver, counts are invalid, training/scoring samples are fewer than 2, or the distribution bounds / regularization are invalid. |
Examples:
>>> from resdag.layers import ESNLayer
>>> res = ESNLayer(100, feedback_size=1, spectral_radius=0.9, seed=0)
>>> mc = memory_capacity(res, max_delay=120, n_samples=2000)
>>> mc >= 0.0
True
See Also
effective_spectral_radius : Realized contraction rate of the driven reservoir.
Source code in src/resdag/metrics/observables.py
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 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 406 407 408 409 410 | |
effective_spectral_radius
¶
effective_spectral_radius(
source: Any, states: Tensor, *, max_states: int = 256, seed: int = 0
) -> float
Mean spectral radius of the state-dependent leaky-ESN Jacobian.
For leak rate \(\alpha\) and recurrent matrix \(W\), the update is \(h_t = (1-\alpha)h_{t-1} + \alpha\tanh(\mathrm{pre}_t)\), with Jacobian
The activation derivative depends on tanh(pre), which differs from the
stored hidden state when any neuron has a leak rate below 1. Consecutive states recover
that activation without re-running the reservoir. Bias and drive affect the
result through the trajectory's activation saturation. W here includes
calibrated recurrent row gains and intrinsic gains. Leak rates may differ
per neuron. Caller weights, cached state and mode are preserved.
This returns a mean local eigenvalue radius. Leakage and non-normal weights mean it need not be below the weight spectral radius, and it does not bound transient amplification. Eigensolves use CPU float64 after one transfer, so trajectories from CUDA and MPS reservoirs are both supported.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The reservoir whose recurrent Jacobian is analysed, or a model
containing exactly one standard
TYPE:
|
states
|
Reservoir states sampled along an attractor trajectory, of shape
TYPE:
|
max_states
|
Cap on the number of trajectory states the mean is taken over; the states are subsampled on an evenly spaced deterministic grid so the estimate stays manageable for a long trajectory — each state costs one \(N \times N\) eigenvalue solve.
TYPE:
|
seed
|
Retained for API compatibility; even subsampling uses no randomness.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The mean realized spectral radius \(\langle \rho(J_t) \rangle\) over the sampled states, in per-step units. Leakage and non-normal recurrent weights mean this need not be below the weight spectral radius. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
NotImplementedError
|
If the cell is not a standard tanh |
Examples:
>>> import torch
>>> from resdag.layers import ESNLayer
>>> res = ESNLayer(100, feedback_size=1, spectral_radius=0.9, seed=0)
>>> u = torch.rand(1, 1500, 1) * 2 - 1
>>> res.reset_state(batch_size=1)
>>> st = res(u)
>>> esr = effective_spectral_radius(res, st)
>>> esr < 0.9 # tanh saturation contracts below the nominal weight radius
True
See Also
resdag.layers.cells.ESNCell.spectral_radius_achieved : The weight spectral radius including calibration gains, before activation derivatives and leakage. resdag.metrics.reservoir_lyapunov : Benettin/QR maximal Lyapunov exponent of the driven reservoir (a time-averaged log-contraction, vs this per-step eigenvalue mean).
Source code in src/resdag/metrics/observables.py
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 | |
correlation_dimension
¶
correlation_dimension(
trajectory: Tensor | ndarray,
*,
n_bins: int = 20,
r_min_frac: float = 0.01,
r_max_frac: float = 0.5,
fit_window: tuple[float, float] = (0.1, 0.5),
max_points: int = 2000,
seed: int = 0
) -> float
Grassberger-Procaccia correlation dimension of an attractor trajectory.
Estimates the fractal (correlation) dimension \(D_2\) of the attractor a trajectory lives on, via the Grassberger-Procaccia algorithm (Grassberger & Procaccia, Characterization of strange attractors, 1983). The correlation sum
counts the fraction of point pairs closer than \(r\). On a \(D_2\)-dimensional attractor it scales as \(C(r) \sim r^{D_2}\) over an intermediate ("scaling") range of \(r\), so \(D_2\) is the slope of \(\log C(r)\) against \(\log r\) fit over that range.
This is the standard attractor-fidelity metric for reservoir forecasts: a free-running forecast that reproduces the true system's climate (its long-run geometry) matches the truth's correlation dimension, even when the pointwise trajectory has long since decorrelated.
Reference values (used to validate this implementation):
- Lorenz-63 \(D_2 \approx 2.05\) (literature; Grassberger & Procaccia 1983).
- A limit cycle / closed curve \(D_2 \approx 1.0\) (a 1-D manifold).
- \(d\)-dimensional i.i.d. noise \(D_2 \approx d\) (it fills the embedding space).
| PARAMETER | DESCRIPTION |
|---|---|
trajectory
|
The attractor trajectory, of shape |
n_bins
|
Number of log-spaced radii \(r\) at which \(C(r)\) is evaluated.
TYPE:
|
r_min_frac
|
Smallest radius as a fraction of the largest pairwise distance.
TYPE:
|
r_max_frac
|
Largest radius as a fraction of the largest pairwise distance.
The radius grid spans
TYPE:
|
fit_window
|
The scaling region over which the \(\log C\) vs \(\log r\) slope
is fit, given as fractions of the (valid)
TYPE:
|
max_points
|
Cap on the number of trajectory points used (the pair count is
\(O(M^2)\)); a longer trajectory is uniformly subsampled.
TYPE:
|
seed
|
Seed for the subsampling draw, so the estimate is deterministic.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The estimated correlation dimension \(D_2\). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Notes
The estimate is a geometry metric, not an error: two trajectories on the
same attractor but out of phase share a correlation dimension. Compare a
forecast's dimension to the truth's (|D2_pred - D2_truth|) to score
climate reconstruction — this is what
resdag.hpo.losses.attractor_dimension_error optimises.
Examples:
>>> import numpy as np
>>> t = np.linspace(0, 2 * np.pi, 3000, endpoint=False)
>>> circle = np.stack([np.cos(t), np.sin(t)], axis=1)
>>> abs(correlation_dimension(circle) - 1.0) < 0.15
True
Source code in src/resdag/metrics/observables.py
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 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |