Skip to content

feat: add Adwin, an adaptive window that cuts itself when the stream … - #1

Merged
crapxxi merged 1 commit into
crapxxi:masterfrom
TheAlgorithms:master
Sep 19, 2026
Merged

crapxxi merged 1 commit into
crapxxi:masterfrom
TheAlgorithms:master

Conversation

@crapxxi

@crapxxi crapxxi commented Sep 19, 2026

Copy link
Copy Markdown
Owner

…changes (TheAlgorithms#7606)

ADWIN keeps a window of recent values and, after every sample, looks for a split into an old and a recent part whose means differ by more than a variance sensitive Hoeffding bound. When it finds one the old part is dropped, so the window grows while the stream is stationary and collapses as soon as it moves, and its length becomes an estimate of how long the current regime has lasted rather than a parameter to tune.

The window is stored as an exponential histogram, buckets of 1, 2, 4 ... elements with at most five of each size, so a window of n elements needs O(log n) buckets and cuts are tried only at bucket boundaries. The bucket merge carries the sum and the variance exactly, which the tests check against a direct computation over 2000 samples.

  • [ x ] I have read CONTRIBUTING.md.
  • [ x ] This pull request is all my own work -- I have not plagiarized it.
  • [ x ] All filenames are in PascalCase.
  • [ x ] All functions and variable names follow Java naming conventions.
  • [ x ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • [ x ] All new algorithms include a corresponding test class that validates their functionality.
  • [ x ] All new code is formatted with clang-format -i --style=file path/to/your/file.java

…changes (#7606)

ADWIN keeps a window of recent values and, after every sample, looks for a split into an old and a recent part whose means differ by more than a variance sensitive Hoeffding bound. When it finds one the old part is dropped, so the window grows while the stream is stationary and collapses as soon as it moves, and its length becomes an estimate of how long the current regime has lasted rather than a parameter to tune.

The window is stored as an exponential histogram, buckets of 1, 2, 4 ... elements with at most five of each size, so a window of n elements needs O(log n) buckets and cuts are tried only at bucket boundaries. The bucket merge carries the sum and the variance exactly, which the tests check against a direct computation over 2000 samples.

Signed-off-by: alxkm <19151554+alxkm@users.noreply.github.com>
Co-authored-by: alxkm <19151554+alxkm@users.noreply.github.com>
@crapxxi
crapxxi merged commit 0305ced into crapxxi:master Sep 19, 2026
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