heimdall

Logo do pacote heimdall Heimdall

R-CMD-check Codecov test
coverage CRAN
status CRAN Downloads GitHub
Stars

Heimdall is a tool designed for concept drift detection in continuous data streams. When analyzing time series data, it is possible to observe significant changes in the data distribution or in the accuracy of predictive models during the forecasting process. These changes are known as concept drift.

The goal of the Heimdall package is to detect when concept drift occurs, enabling the detection and adaptation of models in non-stationary contexts. The package offers several state-of-the-art methods to identify and handle concept drift, as well as techniques for efficient model adaptation.

Heimdall is particularly useful when you need to move quickly from the theory of concept drift to a working streaming implementation. The package includes detectors for both real concept drift and virtual concept drift, and the repository examples are designed to help users understand that distinction through small, reproducible workflows.


Getting started

The package ships with three vignettes, also available on the package website:


Implemented detectors

The table lists every drift detector in the package: the article that proposed it, how the implementation was validated, how it works, and the kind of drift it detects. Virtual drift is a change in the input distribution P(X), seen by detectors that monitor the features. Real drift is a change in P(y X), seen by detectors that monitor the error stream of a model. Detectors marked “Virtual / Real” detect either one, depending on whether they are given a feature or an error stream.

The reproductions of the recent detectors (scripts, logs and result tables) are in development/validation/, one folder per detector.

Classic detectors

Detector Proposed in Validation How it works Drift
dfr_adwin() Bifet & Gavaldà (2007), SIAM SDM Unit tests: the change of the scikit-multiflow example, quiet on stationary data, consistent window, serialization. Its row of Table IV of the FEDD paper is reproduced (F1 0.38) Adaptive window kept as an exponential histogram; cut when two subwindows have significantly different means Virtual / Real
dfr_page_hinkley() Page (1954), Biometrika Unit tests (direction, reset, false alarms). FEDD Table IV reproduced (F1 0.46) Cumulative deviation from the running mean; alarm when it departs from its running minimum by more than a threshold Virtual / Real
dfr_cusum() Muthukrishnan, Berg & Wu (2007), ICDMW Unit tests: detects a moderate rise of the error rate, rare false alarms Accumulates deviations of the error signal; alarm when the sum exceeds a threshold Real
dfr_ddm() Gama et al. (2004), SBIA Unit tests of the error-based detectors Monitors the online error rate p and its standard deviation s; warning and drift when p + s rises well above its minimum Real
dfr_eddm() Baena-García et al. (2006), IWKDDS Unit tests of the error-based detectors Monitors the distance between consecutive errors, which makes it more sensitive to gradual drift Real
dfr_ecdd() Ross et al. (2012), Pattern Recognition Letters Unit tests (a longer ARL gives fewer false alarms) EWMA control chart on the error stream Real
dfr_hddm() Frías-Blanco et al. (2015), IEEE TKDE Unit tests of the error-based detectors HDDM_A: Hoeffding bound on an increase of the mean error Real
dfr_kswin() Raab, Heusinger & Schleif (2020), Neurocomputing Unit tests. FEDD Table IV reproduced (F1 0.41 against 0.38) Kolmogorov-Smirnov test between the recent window and a sample of older observations Virtual
dfr_kldist() Kullback & Leibler (1951), Ann. Math. Stat. Unit tests (stationary data, mean shift, multivariate). FEDD Table IV reproduced (F1 0.45) Symmetrised KL (Jeffreys) divergence between the binned reference and recent windows Virtual
dfr_mcdd() Giusti et al. (2021), Evolving Systems Unit tests. FEDD Table IV reproduced (F1 0.42 against 0.41) Test of the central tendency of the reference against the recent window Virtual
dfr_lbdd() Giusti et al. (2021), Evolving Systems Unit tests of the window detectors Levene’s variance test between the reference and the recent window Virtual
dfr_aedd() Kaminskyi, Li & Müller (2022), ICDMW Unit tests (contract, windows, criteria). FEDD Table IV reproduced (F1 0.40) Autoencoder trained on a reference window; drift when the reconstruction error of recent windows differs Virtual

Recent detectors

Detector Proposed in Validation How it works Drift
dfr_ensemble() (CEDD / FEDD) Giusti Tavares et al. (2025), IJCNN The published member detections on 3W are combined: the crisp ensembles match the reference files exactly (28 of 28 examples), and Table IV is reproduced within 0.01 Members vote with the EFER, majority or threshold rule; FEDD gives each detection a triangular fuzzy score over a tolerance k Depends on the members
dfr_mmqt() Stucchi et al. (2023), IEEE TNNLS QuantTree port identical to the reference code; MMQT written from the paper (not in the reference repository). FPR kept at 5% on synthetic data; CWRU bearing results of Table VI reproduced Batch-wise test with one QuantTree histogram per modality (found by k-means); each batch is tested against its closest modality Virtual
dfr_eikmeans() Liu, Lu & Zhang (2021), IEEE Trans. Cybernetics Equivalent to the reference code (16,000 of 16,000 decisions identical); Tables III-V and X-XI reproduced Equal-intensity k-means partition of the training data; chi-square test on the bin counts of each window Virtual
dfr_mcd() (MCD-DD) Wan, Liang & Yoon (2024), KDD Step-by-step trace against the reference within 1e-14 (encoder, gradients, Adam, decisions); Table 2 matches the reference on 6 of 7 synthetic data sets Contrastive encoder of sample sets of sub-windows; drift when the discrepancy between consecutive sub-window concepts exceeds a learned quantile Virtual
dfr_psi() Kurian & Allali (2024), J. Data, Inf. & Mgmt. Data re-simulated from the SAS code (20 seeds); total PSI of Tables 4-6 within 0.0007 when conditioned on the paper’s draw Population Stability Index per feature over the decile bins of a baseline Virtual
dfr_onlinebcp() Yigiter et al. (2015); Xu, Yigiter & Chen (2022), SoftwareX Equivalent to the onlineBcp package (within 1e-13) on aCGH, cnv and COVID; printed outputs of the paper reproduced; an overflow of the reference fixed with log-scale numerics Posterior of the location of the last change point (normal model, normal-inverse-gamma prior, geometric prior on segment lengths) Virtual
dfr_indid() Romanenkova et al. (2022), ACM Multimedia Losses, gradients and Adam steps match the reference within 1e-15; SyntheticNormal Table 2 within the spread between seeds LSTM sequence-to-sequence model trained with the InDiD (or BCE) loss to output the probability of change at each step Virtual
dfr_llr2() Sojo, Bielza & Larrañaga (2027), Expert Systems with Applications No public detector code; compared with the authors’ result files on 16 synthetic streams and 18 configurations: no missed drift, detection times at the paper’s level, slightly more false alarms on sudden drifts Semiparametric Bayesian network fitted on a baseline; chi-square test on the per-node log-likelihood ratio between a sliding and a reference window, optionally with the Benjamini-Hochberg correction Virtual
dfr_cosine() Nigenda et al. (2022), KDD (SageMaker Model Monitor) Matches the AWS reference code within 3e-6 on BERT embeddings of CoLA; the paper gives no numbers, so the behaviour was checked on in-domain and out-of-domain sets Average cosine similarity of each embedding to the baseline embeddings, averaged over a window; alarm below a threshold Virtual
dfr_padd() Komorniczak & Ksieniewicz (2024), arXiv:2404.07776 Step-by-step identical to the reference with the same random draws (p-values within 6e-14, same detections); D1, D2 and R of experiment 2 (240 streams) reproduced Chunks are passed through a random, untrained neural network; repeated t-tests compare the output activations with those stored since the last drift Virtual
dfr_studd() Cerqueira et al. (2023), Machine Learning Step-by-step equivalent to the reference (same fits, errors, alarms and kappa); on real data, kappa and label ratios do not differ from the reference (p >= 0.2) A student model mimics a teacher; Page-Hinkley on the disagreement stream, so labels are needed only after an alarm Virtual
dfr_wwaggr() Stepikin, Romanenkova & Zaytsev (2025), ICDM Components match the reference (aggregations within 1e-14, networks within 1e-7); ensembles on HAR reach the reference F1 (mean difference 1e-4). The paper’s own data sets are not reproduced Ensemble of deep change point models (BCE, InDiD, TS-CP2, TS2Vec); window Wasserstein aggregation of the members’ scores, then a threshold Virtual
dfr_fastlr() Tatti (2019), ECML PKDD Reference code unreachable, implemented from the paper; unit tests against the brute-force optimum; the synthetic results (Step, Slope, Hill) reproduced Best two-segment Bernoulli split of the error sequence over the border indices, with a (1 - eps) guarantee; change when the likelihood ratio exceeds tau + log n Real
dfr_greedyks() Cardoso & Galeno (2023), J. Computational Science Statistic identical to the reference within 1e-16; error and effectiveness experiments statistically equal; call-center Table 6 reproduced exactly One-sample Kolmogorov-Smirnov test against a reference distribution with the constant-memory GreedyKS sketch Virtual / Real
dfr_iks() dos Reis et al. (2016), KDD KS and Kuiper statistics of the treap identical to the reference over 800 operations; in Tables 2-3 the detector beats both baselines in 18 of 18 settings Incremental two-sample Kolmogorov-Smirnov test per feature on a treap, between a reference sample and a sliding window Virtual
dfr_qts() Ramos et al. (2024), ESANN Occupancy curve and detections identical to the reference on 4 data sets; Table 1 exact on RBF and close on Toy Recent observations are mapped onto a quadtree; drift when its occupancy (occupied leaves) shifts or its derivative changes Virtual
dfr_dde() Szűcs & Németh (2025), Knowledge and Information Systems Reference repository unavailable, implemented from the paper; Table 3 reproduced exactly; on Covertype (Insects is not available) F1 0.64 against 0.55 in the paper Monitors a subset of the features; a correlation-based “domino” curve estimates the drift probability of the unmonitored ones Virtual
dfr_proton() Das et al. (2026), arXiv:2606.20913 No reference code, implemented from the paper; on the FLAIR fundus benchmark the far-OOD gain is reproduced (+8.8 against +8.1), but not the covariate-shift gain (-11.0 against +23.9) Test-time OOD score for a frozen vision-language model: cosine distance to class prototypes from a confidence-gated bank, fused with the MCM score through a variance-driven weight Virtual

Implementation history

Each date is the day the detector was added to heimdall: the first commit of its source file in the repository.

Date Commit Detectors
2024-05-20 6641ae7 dfr_cusum(), dfr_ddm(), dfr_ecdd(), dfr_eddm(), dfr_hddm(), dfr_kldist(), dfr_kswin(), dfr_page_hinkley()
2024-06-19 a182ce1 dfr_adwin()
2024-06-20 ecc4970 dfr_lbdd(), dfr_mcdd()
2024-08-21 8798455 dfr_aedd()
2026-11-16 27c1d54 dfr_mmqt(), dfr_eikmeans()
2026-11-16 0079de3 dfr_mcd(), dfr_psi(), dfr_ensemble()
2026-11-16 1fb1194 dfr_dde(), dfr_proton(), dfr_qts()
2026-11-17 03be450 dfr_indid(), dfr_llr2(), dfr_onlinebcp()
2026-11-20 d8fe9b9 dfr_cosine(), dfr_padd(), dfr_studd(), dfr_wwaggr()
2026-11-20 e85feb3 dfr_fastlr(), dfr_greedyks(), dfr_iks()

Drifter outputs

Besides the drift decision, every drifter exposes the statistic it monitors. After fit(), obj$drifter_output is a data frame with one row per observation, and obj$last_drifter_output holds the value for the last observation processed by update_state(). Rows are NA when the detector reported nothing for that observation, for example while its window is still filling or when it skipped a missing value.

adp_retrain() exposes the output of its drifter in obj$drifter_output as well, with one row per row of x across every call to fit(). Rows are NA while the drifter is not monitoring (during the warmup, or after a drift until the model is retrained).

Drifter Type drifter_output columns
dfr_ddm() error-based miss_prob: running error rate
dfr_eddm() error-based mean_distance: mean distance between two consecutive errors
dfr_hddm() error-based estimation: running error rate
dfr_ecdd() error-based Z: exponentially weighted moving average of the errors
dfr_cusum() error-based g: cumulative sum compared with lambda
dfr_fastlr() error-based score, change_point: Bernoulli likelihood-ratio score and estimated change point
dfr_adwin() univariate width: current length of the adaptive window
dfr_greedyks() univariate statistic, p_value, drift: online one-sample KS statistic, p-value and alarm
dfr_page_hinkley() univariate ph_statistic: Page-Hinkley statistic compared with threshold (the larger of the two directions when direction = "both")
dfr_kswin() univariate D: Kolmogorov-Smirnov statistic; p: its p-value
dfr_lbdd() univariate levene_p: p-value of Levene’s test
dfr_mcdd() univariate old_shapiro_p, new_shapiro_p: normality p-values of the reference and recent halves; comparison_p: p-value of the t-test or Wilcoxon test
dfr_onlinebcp() univariate prob, changepoint: posterior probability and estimated change-point location
dfr_kldist() multivariate divergence: divergence between the reference and recent halves, compared with threshold
dfr_aedd() multivariate one column per feature: reconstruction error of the most recent row (encoder-decoder), or its encoding (encoder only)
dfr_cosine() multivariate score, window_score: per-observation and window cosine similarity against the baseline
dfr_dde() multivariate per-feature monitoring and domino drift scores
dfr_eikmeans() multivariate statistic, df, p_value: chi-square test over equal-intensity k-means bins
dfr_iks() multivariate statistic, drift: incremental two-sample KS statistic and alarm
dfr_llr2() multivariate per-node log-likelihood ratio p-values and drift indicator
dfr_mcd() multivariate mcd, threshold: Maximum Concept Discrepancy and learned quantile threshold
dfr_mmqt() multivariate statistic, threshold, modality: QuantTree batch statistic, threshold and matched modality
dfr_padd() multivariate significant: fraction of random-network activations with significant t-tests
dfr_psi() multivariate psi_<feature>: Population Stability Index per monitored feature
dfr_qts() multivariate occupancy, derivative: quadtree leaf occupancy and its change
dfr_indid() deep / sequence probability: step-by-step change probability from the InDiD LSTM
dfr_proton() OOD / VLM score, base_score, proto_score, alpha, variance, calibrated, class, enqueued
dfr_studd() student-teacher teacher, student, error, statistic, drift: predictions, mimicking error and detector output
dfr_wwaggr() deep ensemble score, drift: aggregated Wasserstein/MMD score across ensemble members
dfr_ensemble() combined member detections and crisp/fuzzy ensemble vote
dfr_multi_criteria() combined one logical column per drifter in drifter_list, with its decision on that observation
dfr_inactive(), dfr_passive() baseline no columns: they monitor nothing

Choosing what a detector monitors

Every distribution-based detector selects its input through target_feat:

Inside adp_retrain() and dfr_multi_criteria(), a univariate detector without a target_feat receives the mean of each row. In adp_retrain(), column names refer to the one-hot encoded, normalized columns, so numeric columns keep their names.


What each detector cannot see

Each detector is blind to some kinds of change. Combine detectors with dfr_multi_criteria() when several kinds of change matter.

Drifter Reacts to Does not see
dfr_ddm(), dfr_hddm() increases of the error rate decreases of the error rate, and any change that leaves the error rate unchanged
dfr_eddm() errors becoming closer together changes that do not affect the distance between errors
dfr_ecdd(), dfr_cusum() increases of the error rate decreases of the error rate
dfr_page_hinkley() increases of the mean (decreases or both with direction) changes of spread or shape with the same mean
dfr_adwin() changes of the mean changes of spread or shape with the same mean
dfr_mcdd() changes of location (mean or median) changes of spread with the same centre
dfr_lbdd() changes of spread shifts of the mean with the same spread
dfr_kswin() any change of the distribution of one feature changes in the relation between features
dfr_kldist() changes of the marginal distribution of each feature; with the default 100-row window, shifts of about two standard deviations small shifts (below about one standard deviation with the default window) and changes in the relation between features
dfr_aedd() changes of the joint distribution, through the reconstruction error changes that the autoencoder reconstructs equally well

Distribution-based detectors only see virtual concept drift (changes in the inputs); error-based detectors only see real concept drift that degrades the predictions.


Long streams


Examples

Heimdall usage examples are organized to help users learn the package progressively, not only to list detector names. Every drifter has two examples:

Each example is available as a rendered walkthrough and an extracted R script.

Recommended starting points:

Browse the materials here:


Installation

The latest version of Heimdall is available on CRAN:

install.packages("heimdall")

You can install the development version directly from GitHub:

# install.packages("devtools")
library(devtools)
devtools::install_github("cefet-rj-dal/heimdall", force = TRUE, upgrade = "never")

Bugs and Feature Requests

If you encounter any issues or would like to suggest new features, please open an issue:


Contributing

See CONTRIBUTING.md for the development container, the Git hook, the code style and how the examples are generated.