Repository navigation
Residual-bootstrap uncertainty for subspaceid and AIC-based default horizons - #215
Open
baggepinnen wants to merge 5 commits into
Open
baggepinnen wants to merge 5 commits into
baggepinnen wants to merge 5 commits into
Conversation
subspaceid(data, nx; uncertainty = Val(:jackknife), nblocks) returns the model together with a SubspaceJackknife object holding one estimate per left-out block of data matrix columns, transformed to the state basis of the full-data model through the extended observability matrix. jackknife_std, jackknife_cov and pole_std compute standard deviations and covariances from these replicates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Normalize the residual covariance in find_PK by the number of data matrix columns; Q, R, S and P previously grew linearly with the record length. - Honor stable = false (eigenvalue reflection was applied unconditionally). - Assign the samples before the first and after the last Hankel column to the first and last block, so that the blocks partition the record. - Detect replicates whose observable subspace differs from the full-data model (smallest principal-angle cosine below 0.5), keep them in their own basis, warn, and record this in SubspaceJackknife.aligned; jackknife_cov(unc) throws in that case. - Support covariance-type weight matrices in the B/D regression. - Match poles by minimum total distance (Hungarian algorithm). - State the observed calibration in the documentation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orizons by AIC The jackknife, its result type and helper functions are removed. With uncertainty = Val(true), subspaceid returns the estimated model and an N4SIDStateSpace with MonteCarloMeasurements.Particles entries, one particle per model estimated from data simulated with resampled innovations. The default horizon r = s1 = s2 for integer nx is twice the AIC lag order of a VARX model, bounded by 2nx and N ÷ (6(m + p)). The previous default 2nx + 10 biased the estimated noise model for lightly damped systems. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Accept a numeric stability margin (as passed by newpem). - Convert vector-of-samples data before the horizon computation and the bootstrap. - Return the Riccati solution P for the returned covariances. - Compute the AIC log determinant from a QR factorization and fall back to separate least-squares fits for linearly dependent regressors. - Use the horizon nx + 1 for records too short for 2nx; validate kmax. - Keep only the particle fields of the bootstrap estimates. - Informative errors for marginally stable models and insufficient horizons. - Scope unsafe comparisons in the docs and evaluate stability per particle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds opt-in uncertainty estimation to the time-domain
subspaceidby a residual bootstrap, returns the ensemble of models asMonteCarloMeasurements.Particles, and changes the default horizons ofsubspaceidto a rule based on the AIC lag order of a VARX model.Uncertainty: residual bootstrap
syspis anN4SIDStateSpacewhoseA, B, C, D, K, Q, R, S, PandxhaveParticlesentries. The particles are not transformed to a common state basis. Basis-invariant quantities (frequency response, poles, stability, simulations) are meaningful per particle; statistics of matrix entries and the mean model are not. This is documented.Val(false)(default) returns the model only, unchanged. The residual bootstrap requires a stable model and throws anArgumentErrorotherwise (only possible withstable = false).K. With the previous default horizons this noise model was strongly biased for lightly damped systems (noise spectrum overestimated by a factor 2.5–9 near the resonance, not decreasing with the record length), and the bootstrap overestimated the uncertainty by up to 2.4. This is the finite-horizon bias of the state-sequence estimate ofQ, S, Rinfind_PK; it vanishes as the horizons grow. Hence the change of the default horizons below.Default horizons
r = s1 = s2 = clamp(2k, 2nx, N ÷ (6(m + p))), wherekis the lag order of a VARX model selected by AIC (lags up to 50). All lag orders are evaluated from one QR factorization with the regressors ordered by lag (varx_aic_lag,subspace_horizon). The lag order reflects the memory of the predictor, and its penalty grows with the number of channels, so short data sets and many channels give shorter horizons. The upper bound limits the data matrices to approximately one row per three columns.nx = :autokeeps the defaultmin(N ÷ 20, 50), since the rule needs the model order.N ÷ (6(m + p)) < 2nx, the horizon isnx + 1. The log determinant in the AIC is computed from a QR factorization of the residual factor, and linearly dependent regressors (e.g. duplicated input channels) fall back to separate least-squares fits.2nx + 10(median relative error of the frequency response, 30 realizations): lightly damped third-order system 0.037 → 0.023 (N = 2000) and 0.019 → 0.010 (N = 8000); 2×2 MIMO 0.032 → 0.016 and 0.021 → 0.005; 3×3 MIMO with N = 300 fails with the previous default and gives 0.023; fast first-order and well-damped systems unchanged. The noise spectrum ratio estimate/true is 0.99–1.00 for N ≥ 2000 (previously 1.35–3).focus = :simulationintest_subspace.jl, AIC selects a long lag and the relative prediction error increases from 0.10 to 0.14. The test now setsr = 2nx + 10explicitly.Calibration of the bootstrap with the new default horizons
Ratio of the RMS bootstrap standard deviation of |G| to the standard deviation over 100 noise realizations (fixed white-noise input, ω = 0.3, 1, 3, 10 rad/s): 0.85–1.13 for second- and third-order systems with measurement noise only and with process noise at N = 2000 and 8000, and for an undermodeled fourth-order system with process noise; 0.88–1.35 for the undermodeled system with measurement noise only.
Alternatives that were evaluated and not adopted: a delete-one-block jackknife (overestimation by 1.3–4 in the heavy-tailed regime, and requires alignment of the state bases), a moving-block bootstrap of the data (no better calibrated, frequent alignment failures), a bootstrap of the simulation residuals in blocks (similar calibration, requires a block length), and the asymptotic prediction-error covariance at the subspace estimate (inherits the noise-model bias; well calibrated only after several Gauss–Newton iterations, i.e. for a prediction-error estimate, which belongs in
newpem).Fixes of existing behavior
find_PKdivided the residual cross product by a constant determined by the matrix dimensions instead of by the number of data-matrix columns, so the estimatedQ,R,SandPgrew linearly with the record length (for a trueR = 0.01:0.10, 0.40, 1.60atN = 1000, 4000, 16000; now approximately0.012).Kis unaffected.stable = falsewas ignored; eigenvalue reflection of an unstableAwas always applied.Pwas returned for the covariances scaled by the factor used for numerical conditioning inared, and is now divided by that factor, so thatPcorresponds to the returnedQ, R, S.Other
subspaceid" inss.md(ensemble plot of the magnitude withmcplot, unsafe comparisons scoped with@unsafe, stability evaluated on the individual models);MonteCarloMeasurementsadded to the docs environment.stablemargin (as passed bynewpem),Pagainst the Riccati solution of the returned covariances, short records, nearly dependentFloat32outputs, AIC lag against separate least-squares fits (also with a duplicated input), particle types and sizes, reproducibility with a seeded RNG, validity of the particle models, noise-covariance normalization,stable = false, forwarding of keyword arguments, error cases, MIMO, and a Monte Carlo calibration check.Host: demeter2 · Session: f206e1d5-e03e-456f-aba8-1778b9dede55 · Working dir: ~/repos/CSI-subspace
🤖 Generated with Claude Code