Skip to content

Add find_delay, fix vector aic, and improve the delay estimation example - #212

Merged
baggepinnen merged 4 commits into
masterfrom
delayest-docs-improvements
Nov 24, 2026
Merged

baggepinnen merged 4 commits into
masterfrom
delayest-docs-improvements

Conversation

@baggepinnen

Copy link
Copy Markdown
Member

Changes

New function find_delay (src/delay.jl, exported together with DelaySweep): fits an arx model for each candidate inputdelay, scores the candidates on validation data (simulation or one-step prediction error) and returns the best delay together with the loss curve. plot(sweep) plots the loss as a function of the delay. Tests in test/test_delay.jl.

Bug fix in aic: for vector residuals the method used 2d / size(x, 2), which equals 2d since size(x, 2) == 1. The penalty was therefore not normalized by the number of samples, which affected find_na and find_nanb. The method now computes log(sse(e) / N) + 2d / N. Test added in test/test_utils.jl.

Delay estimation example (docs/src/examples/delayest.md):

  • The inputdelay convention of arx is stated explicitly and used consistently (a pure delay of n samples corresponds to inputdelay = n + 1). The previous example used inputdelay = τ_samples, which is one sample short.
  • The cross-correlation section uses a random colored input and shows that the confidence bounds are invalid for a colored input (the correlation leaks into lags shorter than the delay), followed by a prewhitened cross-correlation. The deterministic chirp is removed.
  • The experiments start at rest (the nonzero initial state is removed).
  • The regularization of the impulse-response estimate is selected from the simulation fit on separate validation data, instead of the statement that it cannot be tuned.
  • A delay-sweep section with find_delay; find_nanb is applied to noisy data since information criteria are not informative for noise-free data.
  • The ARX order statement (na = 4 is order 4), the echo example (low-frequency gain of 0.6 instead of an energy fraction), and the internal-delay conclusions (delay sweep including zero delay) are corrected.
  • Housekeeping: seeded random number generator, unused DelimitedFiles removed, τ_samples derived from τ / Ts, distinct names for the shifted dataset, typos.

Verification

  • Full test suite passes locally (3182 passed, 1 broken, the latter pre-existing).
  • All code blocks of the example were executed and the resulting figures inspected. The documentation build was not run, since it downloads a dataset used by other pages.

Notes

  • With output noise, the ARX-based sweep is biased because arx is biased by output noise. In the example (noise standard deviation 0.1 relative to an output of standard deviation of about 3) the delay is recovered exactly, whereas for larger noise levels and small na it deviated by several samples. This is documented in the docstring.
  • Version not bumped.

Host: demeter2, session 5b64e4e0-6634-41ce-b4c4-90775881ee48, working directory ~/repos/CSI-delay

🤖 Generated with Claude Code

baggepinnen and others added 4 commits November 23, 2026 12:12
- Add find_delay, which sweeps the input delay of an ARX model and compares the candidates on validation data, together with a plot recipe.
- Normalize aic for vector residuals by the number of samples. The previous method used size(x, 2) = 1 for vectors and thus penalized the number of parameters by 2d instead of 2d/N, which affected find_na and find_nanb.
- Delay example: use the inputdelay convention of arx consistently, prewhiten the input before cross-correlation, start the experiments at rest, select the FIR regularization from validation data, use find_delay, correct the model order and echo-gain statements, evaluate the internal-delay examples with the delay sweep, seed the random number generator and fix typos.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…onvention, use validation data for the closed-loop sweep

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eep only corrections and additions

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…zation parameter

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@baggepinnen
baggepinnen merged commit 8328392 into master Nov 24, 2026
2 checks passed
@baggepinnen
baggepinnen deleted the delayest-docs-improvements branch November 24, 2026 06:04
baggepinnen referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant