Skip to content

[FIX] ASR: apply online recency weights on the euclid path (weighted geometric median)#112

Merged
nbara merged 1 commit into
nbara:masterfrom
sappelhoff:fix/asr-online-weighting
Jul 20, 2026
Merged

[FIX] ASR: apply online recency weights on the euclid path (weighted geometric median)#112
nbara merged 1 commit into
nbara:masterfrom
sappelhoff:fix/asr-online-weighting

Conversation

@sappelhoff

Copy link
Copy Markdown
Collaborator

Two coupled fixes to the online covariance weighting in ASR.transform():

  • The euclid path discarded its recency weights. transform() builds an exponential recency weight vector and passes it to asr_process(sample_weight=...), but on the default method="euclid" path asr_process called geometric_median() with no weights (and the function had no weight parameter), so the weights were computed and silently dropped — only the riemann branch ever used them. Generalize geometric_median() to an optional sample_weight using the weighted Vardi-Zhang iteration; with sample_weight=None (or all ones) it reduces exactly to the previous unweighted algorithm, so asr_calibrate (which calls it unweighted) is numerically unchanged. Pass sample_weight through the euclid branch of asr_process.
  • The recency weight vector used prefix sums instead of suffix sums. A block's recency is the number of more-recent samples that follow it, i.e. the suffix sum of the per-block sample counts; the previous prefix-sum index mis-weighted interior blocks whenever chunk sizes differed. Add a _recency_weights helper that accumulates the suffix sample count newest→oldest.

Testing

Adds regression tests for the weighted median (uniform == unweighted), the euclid wiring, and the suffix-sum weights. Full tests/test_asr.py passes; ruff clean.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.22%. Comparing base (8e53091) to head (6d0ab3a).

Files with missing lines Patch % Lines
meegkit/utils/asr.py 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #112      +/-   ##
==========================================
+ Coverage   83.16%   83.22%   +0.05%     
==========================================
  Files          25       25              
  Lines        2834     2843       +9     
==========================================
+ Hits         2357     2366       +9     
  Misses        477      477              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sappelhoff

Copy link
Copy Markdown
Collaborator Author

Note: includes the nonlinear_eigenspace reproducibility fix from #118 (needed for the riemann path to have stable CI). Once #118 merges, this commit will drop out on rebase.

@sappelhoff
sappelhoff force-pushed the fix/asr-online-weighting branch from 6d752d0 to 0433ac5 Compare July 13, 2026 17:10
@sappelhoff sappelhoff mentioned this pull request Jul 14, 2026
@sappelhoff
sappelhoff force-pushed the fix/asr-online-weighting branch from eb454b3 to a7985ed Compare July 19, 2026 09:12
…geometric median)

Two coupled fixes to the online covariance weighting in ASR.transform():

- The euclid path discarded its recency weights. transform() builds an
  exponential recency weight vector and passes it to
  asr_process(sample_weight=...), but on the default method="euclid" path
  asr_process called geometric_median() with no weights (and the function
  had no weight parameter), so the weights were computed and silently
  dropped -- only the riemann branch ever used them. Generalize
  geometric_median() to an optional sample_weight using the weighted
  Vardi-Zhang iteration; with sample_weight=None (or all ones) it reduces
  exactly to the previous unweighted algorithm, so asr_calibrate (which
  calls it unweighted) is numerically unchanged. Pass sample_weight through
  the euclid branch of asr_process.

- The recency weight vector used prefix sums instead of suffix sums. A
  block's recency is the number of MORE-RECENT samples that follow it, i.e.
  the suffix sum of the per-block sample counts; the previous prefix-sum
  index mis-weighted interior blocks whenever chunk sizes differed. Add a
  _recency_weights helper that accumulates the suffix sample count
  newest->oldest; the most recent block keeps weight 1 and older blocks
  decay toward ~5%.

Adds regression tests for the weighted median, the euclid wiring, and the
suffix-sum weights.
@nbara
nbara force-pushed the fix/asr-online-weighting branch from a7985ed to 6d0ab3a Compare July 20, 2026 13:28
@nbara
nbara merged commit f71758d into nbara:master Jul 20, 2026
7 checks passed
@sappelhoff
sappelhoff deleted the fix/asr-online-weighting branch July 20, 2026 14:05
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.

2 participants