Package {harbinger}


Title: A Unified Time Series Event Detection Framework
Version: 2.2.767
Author: Eduardo Ogasawara ORCID iD [aut, ths, cre], Anthony Heimlich [aut], Antonio Castro [aut], Antonio Mello [aut], Diego Carvalho [ctb], Eduardo Bezerra [ctb], Ellen Paixão [aut], Fernando Fraga [aut], Gabriel Giuliano [aut], Heraldo Borges [aut], Igor Andrade [aut], Isabele Rocha [aut], Janio Lima [aut], Jessica Souza [aut], Lais Baroni [aut], Lucas Tavares [aut], Michel Reis [aut], Rebecca Salles [aut], CEFET/RJ [cph]
Maintainer: Eduardo Ogasawara <eogasawara@ieee.org>
Description: By analyzing time series, it is possible to observe significant changes in the behavior of observations that frequently characterize events. Events present themselves as anomalies, change points, or motifs. In the literature, there are several methods for detecting events. However, searching for a suitable time series method is a complex task, especially considering that the nature of events is often unknown. This work presents Harbinger, a framework for integrating and analyzing event detection methods. Harbinger contains several state-of-the-art methods described in Salles et al. (2020) <doi:10.5753/sbbd.2020.13626>.
License: MIT + file LICENSE
URL: https://cefet-rj-dal.github.io/harbinger/, https://github.com/cefet-rj-dal/harbinger
BugReports: https://github.com/cefet-rj-dal/harbinger/issues
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: tspredit, daltoolbox, ggplot2, RcppHungarian, dplyr, patchwork, stats, stringr, zoo
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-11-29 02:07:45 UTC; gpca
Repository: CRAN
Date/Publication: 2026-11-29 03:50:09 UTC

Yahoo Webscope S5 – A1 Benchmark (Real)

Description

Part of the Yahoo Webscope S5 labeled anomaly detection dataset. A1 contains real-world time series with binary anomaly labels. Useful for evaluating anomaly detection methods on real traffic-like data. Labels available: Yes.

Usage

data(A1Benchmark)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1371/journal.pone.0262463

References

Yoshihara K, Takahashi K (2022) A simple method for unsupervised anomaly detection: An application to Web time series data. PLoS ONE 17(1).

Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(A1Benchmark)
# Access the first series and visualize
s <- A1Benchmark[[1]]
plot(ts(s$value), main = names(A1Benchmark)[1], ylab = "value")
mean(s$event)  # proportion of labeled anomalies

Yahoo Webscope S5 – A2 Benchmark (Synthetic)

Description

Part of the Yahoo Webscope S5 dataset. A2 contains synthetic time series with labeled anomalies designed to stress-test algorithms. Labels available: Yes.

Usage

data(A2Benchmark)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1371/journal.pone.0262463

References

Yoshihara K, Takahashi K (2022) A simple method for unsupervised anomaly detection: An application to Web time series data. PLoS ONE 17(1).

Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(A2Benchmark)
s <- A2Benchmark[[1]]
summary(s$value)

Yahoo Webscope S5 – A3 Benchmark (Synthetic with Outliers)

Description

Part of the Yahoo Webscope S5 dataset. A3 contains synthetic time series with labeled outliers/anomalies. Labels available: Yes.

Usage

data(A3Benchmark)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1371/journal.pone.0262463

References

Yoshihara K, Takahashi K (2022) A simple method for unsupervised anomaly detection: An application to Web time series data. PLoS ONE 17(1).

Examples

library(harbinger)
data(A3Benchmark)
s <- A3Benchmark[[1]]
# Quick visualization with harbinger
har_plot(harbinger(), s$value)

Yahoo Webscope S5 – A4 Benchmark (Synthetic with Anomalies and CPs)

Description

Part of the Yahoo Webscope S5 dataset. A4 contains synthetic time series with labeled anomalies and change points. Labels available: Yes.

Usage

data(A4Benchmark)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1371/journal.pone.0262463

References

Yoshihara K, Takahashi K (2022) A simple method for unsupervised anomaly detection: An application to Web time series data. PLoS ONE 17(1).

Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(A4Benchmark)
s <- A4Benchmark[[1]]
mean(s$event)  # proportion of anomalous or change-point timestamps

Collect batch execution log

Description

Returns one row per completed online detection cycle.

Usage

collect_batch_log(obj)

Arguments

obj

Online session.

Value

Data frame with one row per batch and columns:


Collect final detection output

Description

Materializes the final detection table from the online session trace.

Usage

collect_detection(obj)

Arguments

obj

Online session.

Value

A data frame with the usual idx, event, and type columns plus online summary columns:


Collect the online trace

Description

Returns one row per observed time point with the quantities needed to compute Detection Probability (DP) and Detection Lag (DL).

Usage

collect_trace(obj)

Arguments

obj

Online session.

Value

Data frame with one row per observation and columns:


Detect events in time series

Description

Generic S3 method for event detection using a fitted Harbinger model. Concrete methods are implemented by each detector class.

Usage

detect(obj, ...)

Arguments

obj

A harbinger detector object.

...

Additional arguments passed to methods.

Value

A data frame with columns: idx (index), event (logical), and type (character: "anomaly", "changepoint", or ""). Some detectors may also attach attributes (e.g., threshold) or extra columns (e.g., seq, seqlen).

Examples

# See detector-specific examples in the package site for usage patterns
# and plotting helpers.

Detect events using Harbinger Fuzzy Ensemble

Description

Detect events using Harbinger Fuzzy Ensemble

Usage

## S3 method for class 'har_ensemble_fuzzy'
detect(
  obj,
  serie,
  threshold = NULL,
  threshold_type = NULL,
  min_consensus = NULL,
  time_tolerance = NULL,
  use_nms = NULL,
  outliers_check = NULL,
  outlier_filter = NULL,
  ...
)

Arguments

obj

A har_ensemble_fuzzy object.

serie

Input time series.

threshold

Numeric detection threshold.

threshold_type

Either "fixed" or "percentile".

min_consensus

Minimum absolute consensus in ⁠[0,1]⁠ used with percentile thresholding. The effective threshold is the larger of the positive-score percentile and this value.

time_tolerance

Integer window for temporal fuzzification and NMS.

use_nms

Logical; whether to apply non-maximum suppression.

outliers_check

Optional refinement function.

outlier_filter

Optional post-filter over the ensemble score. It may return a logical mask or integer positions.

...

Additional arguments.

Value

A detection object with score and per-model events as attributes.


Evaluate a streaming trace

Description

Computes trace-level summaries and, when a reference label vector is provided, combines them with the standard Harbinger hard evaluation.

Usage

## S3 method for class 'har_stream_eval'
evaluate(obj, detection, reference = NULL, probability_threshold = NULL, ...)

Arguments

obj

A har_stream_eval object.

detection

Trace data frame returned by collect_trace().

reference

Optional logical or numeric event reference aligned with the observation index.

probability_threshold

Optional DP threshold used to derive an additional filtered detection vector.

...

Unused.

Value

A named list with per-observation trace metrics and aggregate summaries. The returned list always includes:

When reference is provided, it also includes:

When probability_threshold is provided, it also includes:

When both reference and probability_threshold are provided, it also includes:


Time series for anomaly detection

Description

A list of time series designed for anomaly detection tasks.

Usage

data(examples_anomalies)

Format

A list of time series for anomaly detection.

Source

Harbinger package

References

Harbinger package

Ogasawara, E., Salles, R., Porto, F., Pacitti, E. Event Detection in Time Series. 1st ed. Cham: Springer Nature Switzerland, 2025. doi:10.1007/978-3-031-75941-3

Examples

data(examples_anomalies)
# Select a simple anomaly series
serie <- examples_anomalies$simple
head(serie)

Time series for change point detection

Description

A list of time series for change point experiments.

Usage

data(examples_changepoints)

Format

A list of time series for change point detection.

Source

Harbinger package

References

Harbinger package

Ogasawara, E., Salles, R., Porto, F., Pacitti, E. Event Detection in Time Series. 1st ed. Cham: Springer Nature Switzerland, 2025. doi:10.1007/978-3-031-75941-3

Examples

data(examples_changepoints)
# Select a simple change point series
serie <- examples_changepoints$simple
head(serie)

Time series for event detection

Description

A list of time series for demonstrating event detection tasks.

Usage

data(examples_harbinger)

Format

A list of time series.

Source

Harbinger package

References

Harbinger package

Ogasawara, E., Salles, R., Porto, F., Pacitti, E. Event Detection in Time Series. 1st ed. Cham: Springer Nature Switzerland, 2025. doi:10.1007/978-3-031-75941-3

Examples

data(examples_harbinger)
# Inspect a series (Seattle daily temperatures)
serie <- examples_harbinger$seattle_daily
head(serie)

Time series for motif/discord discovery

Description

A list of time series for motif (repeated patterns) and discord (rare patterns) discovery.

Usage

data(examples_motifs)

Format

A list of time series for motif discovery.

Source

Harbinger package

References

Harbinger package

Ogasawara, E., Salles, R., Porto, F., Pacitti, E. Event Detection in Time Series. 1st ed. Cham: Springer Nature Switzerland, 2025. doi:10.1007/978-3-031-75941-3

Examples

data(examples_motifs)
# Select a simple motif series
serie <- examples_motifs$simple
head(serie)

Fit an online session

Description

Consumes the warm-up observations and optionally fits the wrapped detector according to the execution strategy.

Usage

## S3 method for class 'har_online_session'
fit(obj, ...)

Arguments

obj

Online session.

...

Additional arguments forwarded to the wrapped detector fit() method when warm-up fitting is enabled.

Value

Updated har_online_session.


GECCO Challenge 2018 – Water Quality Time Series

Description

Benchmark time series for water quality monitoring composed of multiple sensors and an associated binary event label. This dataset supports research in anomaly and event detection for environmental data streams. See cefet-rj-dal/united for usage guidance and links to the preprocessing steps used to build the package-ready object. Labels available: Yes.

Usage

data(gecco)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

GECCO Challenge 2018 (legacy challenge page unavailable)

References

Genetic and Evolutionary Computation Conference (GECCO), Association for Computing Machinery (ACM). See also: Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(gecco)
# Select the first univariate series and inspect
series <- gecco[[1]]
summary(series$value)
# Plot values with event markers
plot(ts(series$value), main = names(gecco)[1], ylab = "value")

Anomaly detector using autoencoders

Description

Trains an encoder-decoder (autoencoder) to reconstruct sliding windows of the series; large reconstruction errors indicate anomalies.

Usage

han_autoencoder(input_size, encode_size, encoderclass = autoenc_base_ed, ...)

Arguments

input_size

Integer. Input (and output) window size for the autoencoder.

encode_size

Integer. Size of the encoded (bottleneck) representation.

encoderclass

DALToolbox encoder-decoder constructor to instantiate.

...

Additional arguments forwarded to encoderclass.

Value

han_autoencoder object

References

Examples

library(daltoolbox)
library(tspredit)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure an autoencoder-based anomaly detector
model <- han_autoencoder(input_size = 5, encode_size = 3)

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Inspect detected anomalies
print(detection[detection$event, ])


Anomaly detector based on ML classification

Description

Supervised anomaly detection using a DALToolbox classifier trained with labeled events. Predictions above a probability threshold are flagged.

A set of preconfigured classification methods are listed at https://cefet-rj-dal.github.io/daltoolbox/ (e.g., cla_majority, cla_dtree, cla_knn, cla_mlp, cla_nb, cla_rf, cla_svm).

Usage

hanc_ml(model, threshold = 0.5)

Arguments

model

A DALToolbox classification model.

threshold

Numeric. Probability threshold for positive class.

Value

hanc_ml object.

References

Examples

library(daltoolbox)

# Load labeled anomaly dataset
data(examples_anomalies)

# Use train-test example
dataset <- examples_anomalies$tt
dataset$event <- factor(dataset$event, labels=c("FALSE", "TRUE"))
slevels <- levels(dataset$event)

# Split into training and test
train <- dataset[1:80,]
test <- dataset[-(1:80),]

# Normalize features
norm <- minmax()
norm <- fit(norm, train)
train_n <- daltoolbox::transform(norm, train)

# Configure a decision tree classifier
model <- hanc_ml(cla_dtree("event", slevels))

# Fit the classifier
model <- fit(model, train_n)

# Evaluate detections on the test set
test_n <- daltoolbox::transform(norm, test)

detection <- detect(model, test_n)
print(detection[(detection$event),])


Anomaly/discord detector using native DTW + DBA clustering

Description

Distance-based anomaly and discord detection using Dynamic Time Warping (DTW) with DTW Barycenter Averaging (DBA) centroids (Sakoe & Chiba 1978; Berndt & Clifford 1994; Petitjean et al. 2011). When seq == 1, isolated observations are labeled as anomalies; when seq > 1, subsequences are labeled as discords. Self-contained base-R implementation shared across the DAL stack.

Usage

hanct_dtw(seq = 1, centers = NA, window = NULL, max_iter = 20)

Arguments

seq

Integer. Subsequence (sliding-window) size (default 1).

centers

Integer or NA. Number of centroids (NA defaults to ceil(log10(n))).

window

Integer or NULL. Optional Sakoe-Chiba warping band width.

max_iter

Integer. Maximum DTW-DBA clustering iterations (default 20).

Value

hanct_dtw object.

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure DTW-based detector
model <- hanct_dtw()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected events
print(detection[(detection$event),])


Anomaly detector using k-means

Description

Distance-based anomaly and discord detection using k-means clustering. The detector clusters the series and flags observations or subsequences that are far from the nearest centroid. When seq equals one, isolated observations are labeled as anomalies. When seq is greater than one, subsequences are labeled as discords. Wraps the kmeans implementation from the stats package.

Usage

hanct_kmeans(seq = 1, centers = NA)

Arguments

seq

sequence size

centers

number of centroids

Value

hanct_kmeans object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure k-means detector
model <- hanct_kmeans()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected events
print(detection[(detection$event),])


Anomaly detector using ARIMA (ARIMA++)

Description

Fits an ARIMA model to the series and flags observations with large model residuals as anomalies.

Usage

hanr_arima(auto = "aicc", max_order = 12, cv_folds = 2, horizon = NULL)

Arguments

auto

Order selector forwarded when tspredit::fit_arima() is available: "aicc" (default, compact AICc search) or "cv" (rolling-origin CV).

max_order

Cap for the ACF/PACF-driven candidate lags (ARIMA++ "cv").

cv_folds

Number of rolling origins for the CV selection (ARIMA++ "cv").

horizon

CV horizon (ARIMA++ "cv"); NULL -> the detected seasonal period.

Details

Fits an automatic ARIMA model via tspredit (fit_arima() when exported, otherwise ts_arima()) and flags points whose in-sample ARIMA residual is unusually large.

The first sw_size = max(p, d + 1, q) residuals are a warm-up window: they are neutralised before the outlier statistics (not only masked afterwards), so a large initialisation transient cannot inflate the threshold and hide the real anomalies. Residual magnitudes are summarised via a distance function and thresholded with the outlier heuristics from harutils().

Value

hanr_arima object.

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure ARIMA anomaly detector
model <- hanr_arima()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly detector using EMD

Description

Empirical Mode Decomposition to extract intrinsic mode functions and flag anomalies from high-frequency components. Uses the native deterministic EMD shared across the DAL stack (no hht dependency).

Usage

hanr_emd(noise = 0.1, trials = 5)

Arguments

noise

Numeric. Noise amplitude for CEEMD.

trials

Integer. Number of CEEMD trials.

Value

hanr_emd object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure EMD-based anomaly detector
model <- hanr_emd()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly detector using FBIAD

Description

Forward and Backward Inertial Anomaly Detector (FBIAD) detects anomalies in time series by comparing each observation against both forward and backward inertial context.

Usage

hanr_fbiad(sw_size = 30)

Arguments

sw_size

Window size for FBIAD.

Value

hanr_fbiad object.

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure FBIAD detector
model <- hanr_fbiad()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly detector using FFT

Description

High-pass filtering via FFT isolates high-frequency components. Anomalies are flagged where the filtered magnitude departs strongly from baseline.

Usage

hanr_fft()

Details

The spectrum is computed by FFT, a cutoff is selected from the power spectrum, low frequencies are nulled, and the inverse FFT reconstructs a high-pass signal. Magnitudes are summarized and thresholded using harutils().

Value

hanr_fft object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure FFT-based anomaly detector
model <- hanr_fft()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly Detector using FFT with AMOC Cutoff

Description

This detector combines FFT-based spectral filtering with an AMOC change-point cutoff on the power spectrum. Frequencies below the selected cutoff are removed, the signal is reconstructed from the remaining high-frequency content, and the residual is scored for anomalies.

This function extends the HARBINGER framework and returns an object of class hanr_fft_amoc.

Usage

hanr_fft_amoc()

Value

hanr_fft_amoc object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure FFT+AMOC detector
model <- hanr_fft_amoc()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Inspect detected anomalies
print(detection[detection$event, ])


Anomaly Detector using FFT with AMOC and CUSUM Cutoff

Description

This detector combines FFT-based spectral filtering with an AMOC change-point cutoff applied to the cumulative spectrum. The lower-frequency components are removed, the signal is reconstructed, and the residual is scored for anomalies.

This function extends the HARBINGER framework and returns an object of class hanr_fft_amoc_cusum.

Usage

hanr_fft_amoc_cusum()

Value

hanr_fft_amoc_cusum object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure FFT+CUSUM+AMOC detector
model <- hanr_fft_amoc_cusum()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Inspect detected anomalies
print(detection[detection$event, ])


Anomaly Detector using FFT with Binary Segmentation Cutoff

Description

This detector combines FFT-based spectral filtering with a Binary Segmentation change-point cutoff on the power spectrum. Frequencies below the selected cutoff are removed, the signal is reconstructed from the remaining high-frequency content, and the residual is scored for anomalies.

This function is part of the HARBINGER framework and returns an object of class hanr_fft_binseg.

Usage

hanr_fft_binseg()

Value

hanr_fft_binseg object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure FFT+BinSeg detector
model <- hanr_fft_binseg()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Inspect detected anomalies
print(detection[detection$event, ])



Anomaly Detector using FFT with BinSeg and CUSUM Cutoff

Description

This detector combines FFT-based spectral filtering with a Binary Segmentation change-point cutoff applied to the cumulative spectrum. The lower-frequency components are removed, the signal is reconstructed, and the residual is scored for anomalies.

This function extends the HARBINGER framework and returns an object of class hanr_fft_binseg_cusum.

Usage

hanr_fft_binseg_cusum()

Value

hanr_fft_binseg_cusum object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

#Using simple example
dataset <- examples_anomalies$simple
head(dataset)

# setting up time series fft detector
model <- hanr_fft_binseg_cusum()

# fitting the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# filtering detected events
print(detection[(detection$event),])


Anomaly Detector using Adaptive FFT and Moving Average

Description

This detector combines FFT-based spectral analysis with an adaptive moving-average filter. The residual signal is scored for anomalies, and a grouping strategy reduces false positives by keeping a representative point from each cluster.

This function extends the HARBINGER framework and returns an object of class hanr_fft_sma.

Usage

hanr_fft_sma()

Value

hanr_fft_sma object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

#Using simple example
dataset <- examples_anomalies$simple
head(dataset)

# setting up time series fft detector
model <- hanr_fft_sma()

# fitting the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# filtering detected events
print(detection[(detection$event),])


Anomaly detector using GARCH (native ARMA(1,1)-GARCH(1,1))

Description

Fits a native ARMA(1,1)-GARCH(1,1) Gaussian maximum-likelihood model to capture conditional heteroskedasticity and flags observations with large standardized residuals as anomalies. Self-contained base-R implementation shared across the DAL stack.

Usage

hanr_garch()

Value

hanr_garch object.

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure GARCH anomaly detector
model <- hanr_garch()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly detector using histograms

Description

Flags observations that fall into low-density histogram bins or outside the observed bin range.

Usage

hanr_histogram(density_threshold = 0.05)

Arguments

density_threshold

Numeric between 0 and 1. Minimum bin density to avoid being considered an anomaly (default 0.05).

Value

hanr_histogram object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure histogram-based detector
model <- hanr_histogram()

# Fit the model (no-op)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly detector based on ML regression

Description

Trains a regression model to forecast the next value from a sliding window and flags large prediction errors as anomalies. Uses DALToolbox regressors.

Preconfigured statistical and machine-learning regressors are described at https://cefet-rj-dal.github.io/tspredit/ (e.g., ts_elm, ts_mlp, ts_rf, ts_svm). Deep ++ regressors such as ts_conv1d and ts_lstm are described at https://cefet-rj-dal.github.io/daltoolboxdp/.

When the wrapped regressor comes from tspredit, its predict() method may carry auxiliary attributes in addition to the numeric forecast path. This wrapper always materializes that result as a plain vector before computing residuals.

Usage

hanr_ml(model, sw_size = 15)

Arguments

model

A DALToolbox regression model.

sw_size

Integer. Sliding window size.

Value

hanr_ml object.

References

Examples

library(daltoolbox)
library(tspredit)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure a time series regression model
model <- hanr_ml(tspredit::ts_elm(tspredit::ts_norm_gminmax(),
                   input_size=4, nhid=3, actfun="purelin"))

# Fit the model
model <- daltoolbox::fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Anomaly detector using REMD

Description

Anomaly detection using REMD with EMD-based decomposition. The detector decomposes the series, selects components according to curvature, and flags large residual deviations as anomalies. Wraps the EMD-based model presented in the forecast package. The internal ARIMA adjustment is fitted on ts_data(..., sw = 1), which is the aligned single-series representation expected by raw-series forecasters in tspredit.

Usage

hanr_remd(noise = 0.1, trials = 5)

Arguments

noise

Noise amplitude for the decomposition.

trials

Number of trials used by the decomposition step.

Value

hanr_remd object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure REMD detector
model <- hanr_remd()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Resilient Transformation Anomaly Detector (RTAD)

Description

Hybrid anomaly detector built from the Resilient Transformation (RT) proposed in the RT/RTAD paper. The series is decomposed with CEEMD, the highest-frequency structure is selected from IMF roughness, the transformed signal is differentiated, and local dispersion is used to normalize deviations before thresholding.

RTAD is not a generic wrapper around EMD. It is the standalone detector obtained when the resilient transformation is coupled with a simple decision rule.

Usage

hanr_rtad(sw_size = 30, noise = 0.001, trials = 5, sigma = sd)

Arguments

sw_size

Sliding window size used to compute local dispersion.

noise

CEEMD noise amplitude.

trials

Number of CEEMD trials.

sigma

Function used to compute local dispersion.

Value

hanr_rtad object

References

Examples

library(daltoolbox)
library(zoo)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure RTAD detector
model <- hanr_rtad()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected events
print(detection[(detection$event),])


Anomaly detector using Wavelets

Description

Multiresolution decomposition via wavelets; anomalies are flagged where aggregated wavelet detail coefficients indicate unusual energy.

Usage

hanr_wavelet(filter = "haar")

Arguments

filter

Character. Available wavelet filters: haar, d4, la8, bl14, c6.

Details

The series is decomposed with a native Maximal Overlap Discrete Wavelet Transform (MODWT, Percival & Walden, 2000) aligned with tspredit / pytspredit.wavelet, and detail bands are aggregated to compute a magnitude signal thresholded using harutils().

Value

hanr_wavelet object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure wavelet-based anomaly detector
model <- hanr_wavelet()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected anomalies
print(detection[(detection$event),])


Harbinger Ensemble

Description

Majority-vote ensemble across multiple Harbinger detectors.

Usage

har_ensemble(...)

Arguments

...

One or more detector objects.

Value

A har_ensemble object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure an ensemble of detectors
model <- har_ensemble(hanr_arima(), hanr_arima(), hanr_arima())
# model <- har_ensemble(hanr_fbiad(), hanr_arima(), hanr_emd())

# Fit all ensemble members
model <- fit(model, dataset$serie)

# Run ensemble detection
detection <- detect(model, dataset$serie)

# Show detected events
print(detection[(detection$event),])


Harbinger Fuzzy Ensemble

Description

Score-based ensemble across multiple Harbinger detectors with optional temporal fuzzification, thresholding, and non-maximum suppression.

This variant preserves the richer aggregation logic that was previously mixed into har_ensemble(), but keeps the simple majority-vote ensemble separate.

Usage

har_ensemble_fuzzy(...)

Arguments

...

One or more detector objects.

Value

A har_ensemble_fuzzy object.

References

Examples

library(daltoolbox)

data(examples_changepoints)
dataset <- examples_changepoints$simple

model <- har_ensemble_fuzzy(
  hcp_scp(sw = 30),
  hcp_chow(),
  hcp_cf_arima(sw_size = 10)
)
model <- fit(model, dataset$serie)
detection <- detect(model, dataset$serie, time_tolerance = 8, use_nms = TRUE)
print(detection[detection$event, ])


Plot Harbinger Ensemble Outputs

Description

Visualize ensemble detection results and the individual model votes stored by har_ensemble_fuzzy().

The plotting helpers do not recompute detections. They use the attributes attached to the detection object as the source of truth.

Usage

har_ensemble_plot(detection, serie, threshold = NULL, time_idx = NULL)

Arguments

detection

A detection object returned by detect.har_ensemble_fuzzy.

serie

Numeric vector with the original time series.

threshold

Optional threshold override for the score panel.

time_idx

Optional x-axis vector.

Value

A patchwork object.


Plot individual model detections in a Harbinger fuzzy ensemble

Description

Visualizes the original series and the per-model detections stored in the model_events attribute returned by detect.har_ensemble_fuzzy().

Usage

har_ensemble_plot_models(detection, serie, time_idx = NULL)

Arguments

detection

A detection object returned by detect.har_ensemble_fuzzy.

serie

Numeric vector with the original time series.

time_idx

Optional x-axis vector.

Value

A patchwork object.


Evaluation of event detection

Description

Hard evaluation of event detection producing confusion matrix and common metrics (accuracy, precision, recall, F1, etc.).

Usage

har_eval()

Value

har_eval object

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

dataset <- examples_anomalies$simple
head(dataset)

# Configure a change-point detector (GARCH)
model <- hcp_garch()

# Fit the detector
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected events
print(detection[(detection$event),])

# Evaluate detections
evaluation <- evaluate(har_eval(), detection$event, dataset$event)
print(evaluation$confMatrix)

# Plot the results
grf <- har_plot(model, dataset$serie, detection, dataset$event)
plot(grf)


Evaluation of event detection (SoftED)

Description

Soft evaluation of event detection using SoftED https://doi.org/10.48550/arXiv.2304.00439. The metric assigns partial credit to detections that fall within a tolerance window around the ground-truth event.

Usage

har_eval_soft(sw_size = 15)

Arguments

sw_size

Integer. Tolerance window size for soft matching.

Value

har_eval_soft object.

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use the simple series
dataset <- examples_anomalies$simple
head(dataset)

# Configure a change-point detector (GARCH)
model <- hcp_garch()

# Fit the detector
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected events
print(detection[(detection$event),])

# Evaluate detections (SoftED)
evaluation <- evaluate(har_eval_soft(), detection$event, dataset$event)
print(evaluation$confMatrix)

# Plot the results
grf <- har_plot(model, dataset$serie, detection, dataset$event)
plot(grf)


Full memory policy

Description

Keeps all observations seen by the online session.

Usage

har_memory_full()

Value

A har_memory_full object.

Examples

memory <- har_memory_full()
memory$mode

Last-observation memory policy

Description

Keeps only the most recent n observations in memory.

Usage

har_memory_last_observations(n)

Arguments

n

Number of observations to retain.

Value

A har_memory_last_observations object.

Examples

memory <- har_memory_last_observations(100)
memory$n

Sliding batch memory policy

Description

Keeps only the most recent batches completed batches in memory.

Usage

har_memory_sliding(batches)

Arguments

batches

Number of completed batches to retain.

Value

A har_memory_sliding object.

Examples

memory <- har_memory_sliding(3)
memory$batches

Detect-only execution strategy

Description

Uses the detector as already fitted and only calls detect() during the online loop. This is useful when the model is pre-trained or when warm-up fitting should happen only once.

Usage

har_online_detect_only(fit_on_warmup = FALSE)

Arguments

fit_on_warmup

Whether the detector should be fitted once after warm-up.

Value

A har_online_detect_only object.

Examples

exec <- har_online_detect_only()
exec$fit_each_run

Online execution strategies

Description

Execution strategies tell a Harbinger online session how the underlying detector should be invoked when a new batch is ready.

This makes the adaptation from offline detectors to streaming operation explicit instead of implicit.

For detector authors, the incremental strategy assumes an optional online_update(obj, serie, ...) function stored in the detector object. When present, it must return the updated detector after incorporating the current in-memory series. If absent, the incremental strategy behaves like detect-only execution.


Incremental execution strategy

Description

Placeholder strategy for detectors with native stateful updates. When a detector exposes an online_update() function in the detector object, the session will call it before detection. Otherwise the strategy falls back to detect-only behavior.

Usage

har_online_incremental(fit_on_warmup = TRUE)

Arguments

fit_on_warmup

Whether the detector should be fitted once after warm-up.

Value

A har_online_incremental object.

Examples

exec <- har_online_incremental()
exec$mode

Online memory policies

Description

Memory policies define how much recent context an online Harbinger session keeps in memory before each detection cycle.

The online layer treats memory as an execution policy rather than as a property of the detector itself.


Full refit execution strategy

Description

Re-fits the detector on the current in-memory series before each batch detection.

Usage

har_online_refit_full(fit_on_warmup = TRUE)

Arguments

fit_on_warmup

Whether the detector should be fitted once after warm-up.

Value

A har_online_refit_full object.

Examples

exec <- har_online_refit_full()
exec$mode

Harbinger online session

Description

Creates and runs a streaming session that reuses existing Harbinger detectors without changing their offline APIs. The session layer is intentionally additive: it orchestrates ingestion, batching, memory management, tracing, and evaluation support around the detector already provided by the package.

The session supports:

Usage

har_online_session(
  source,
  detector,
  executor = har_online_refit_full(),
  warmup_size = 30,
  batch_size = 30,
  memory = har_memory_full(),
  mode = c("auto", "pull", "push")
)

Arguments

source

Streaming source object. May be NULL for push-only sessions.

detector

Any existing Harbinger detector.

executor

Execution strategy. Defaults to har_online_refit_full().

warmup_size

Number of initial observations consumed before regular streaming detection starts.

batch_size

Number of new observations required to trigger one online detection cycle.

memory

Memory policy. Defaults to har_memory_full().

mode

Session mode:

  • "auto": behaves like pull mode when a source is available and like push mode when source = NULL;

  • "pull": observations are requested through next_observation(source);

  • "push": observations must be provided explicitly through ingest().

Value

A har_online_session object.

Examples

source <- har_source_simulated(c(10, 11, 12, 20, 12, 11, 10))
session <- har_online_session(
  source = source,
  detector = hcp_page_hinkley(min_instances = 3, threshold = 1),
  warmup_size = 3,
  batch_size = 2
)
session <- daltoolbox::fit(session)
session <- run_online(session)
head(collect_detection(session))

Streaming data sources for Harbinger

Description

The online layer of Harbinger consumes observations through source objects. A source abstracts how new observations are collected, allowing the online session to work with simulated vectors, data frames, callback-based feeds, and external stream collectors.

The source API is intentionally small:

An observation consumed by the online layer is normalized to a list with:

Kafka support in this package is intentionally limited to a stub interface. Actual collection is expected to be delegated to Python code integrated via reticulate.

Value

Source object.


Plot event detection on a time series

Description

Convenience plotting helper for Harbinger detections. It accepts a detector, the input series, an optional detection data frame, and optional ground-truth events to color-code true positives (TP), false positives (FP), and false negatives (FN). It can also mark detected change points and draw reference horizontal lines.

Usage

har_plot(
  obj,
  serie,
  detection = NULL,
  event = NULL,
  mark.cp = TRUE,
  ylim = NULL,
  idx = NULL,
  pointsize = 0.5,
  colors = c("green", "blue", "red", "purple"),
  yline = NULL
)

Arguments

obj

A harbinger detector used to produce detection.

serie

Numeric vector with the time series to plot.

detection

Optional detection data.frame as returned by detect().

event

Optional logical vector with ground-truth events (same length as serie).

mark.cp

Logical; if TRUE, marks detected change points with dashed vertical lines.

ylim

Optional numeric vector of length 2 for y-axis limits.

idx

Optional x-axis labels or indices (defaults to seq_along(serie)).

pointsize

Base point size for observations.

colors

Character vector of length 4 with colors for TP, FN, FP, and motif segments.

yline

Optional numeric vector with y values to draw dotted horizontal lines.

Value

A ggplot object showing the time series with detected events highlighted.

References

Examples

library(daltoolbox)

# Load an example anomaly dataset
data(examples_anomalies)

# Use the simple time series
dataset <- examples_anomalies$simple
head(dataset)

# Set up an ARIMA-based anomaly detector
model <- hanr_arima()

# Fit the detector
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Inspect detected events
print(detection[(detection$event),])

# Evaluate detections (soft evaluation)
evaluation <- evaluate(har_eval_soft(), detection$event, dataset$event)
print(evaluation$confMatrix)

# Plot the results
grf <- har_plot(model, dataset$serie, detection, dataset$event)
plot(grf)


Simulated stream collector

Description

Reference collector that replays an in-memory vector, matrix, or data frame one observation at a time. It lets a har_source_kafka() run end-to-end without a broker, and is the template for a real-broker collector.

Usage

har_simulated_collector(data)

Arguments

data

Numeric vector, matrix, or data frame in time order.

Value

A har_simulated_collector object exposing get_next()/close().

Examples

collector <- har_simulated_collector(c(10, 11, 12))
collector$get_next()
collector$get_next()

Base source object

Description

Creates the common base used by Harbinger streaming sources.

Usage

har_source(name = "source")

Arguments

name

Human-readable source name.

Value

A har_source object.


Callback source

Description

Creates a pull-style source that retrieves observations by calling an R function. The callback must return either NULL when no observation is available or an observation compatible with the online observation contract. In practice this means a scalar, a one-row data.frame, or a list containing at least a value field and optionally idx, timestamp, and payload.

Usage

har_source_callback(poll_fn, name = "callback")

Arguments

poll_fn

Function called to request the next observation.

name

Source name.

Value

A har_source_callback object.


Data-frame source

Description

Convenience wrapper around har_source_simulated() for table-shaped inputs.

Usage

har_source_dataframe(
  data,
  timestamp_col = NULL,
  value_cols = NULL,
  name = "dataframe"
)

Arguments

data

Data frame in time order.

timestamp_col

Optional timestamp column name or position.

value_cols

Optional value columns. Defaults to all columns except the timestamp column when provided.

name

Source name.

Value

A har_source_dataframe object.

Examples

df <- data.frame(ts = 1:3, value = c(10, 11, 9))
source <- har_source_dataframe(df, timestamp_col = "ts", value_cols = "value")
obs <- next_observation(source)
obs$observation$timestamp

Kafka source (dependency-free streaming abstraction)

Description

Kafka-shaped source that holds the broker configuration but delegates the actual consumption to a pluggable collector exposing get_next(). Harbinger declares no Kafka dependency: attach a har_simulated_collector() to test end-to-end, or your own collector backed by a real Kafka client (e.g. a reticulate Python consumer) to read a live topic. The collector is pulled one observation at a time, modelling true streaming.

Usage

har_source_kafka(
  topic,
  bootstrap_servers,
  group_id,
  collector = NULL,
  value_schema = NULL,
  name = "kafka"
)

Arguments

topic

Kafka topic name.

bootstrap_servers

Character vector with broker addresses.

group_id

Consumer group identifier.

collector

Optional collector object exposing get_next() (and an optional close()). Without one the source raises on next_observation().

value_schema

Optional schema description for the payload.

name

Source name.

Value

A har_source_kafka object.

Examples

# Stub example: a simulated collector, no broker required.
source <- har_source_kafka(
  topic = "sensor-events",
  bootstrap_servers = c("broker:9092"),
  group_id = "harbinger",
  collector = har_simulated_collector(c(10, 11, 12, 20, 12))
)
next_observation(source)$observation$value

# Real example: a collector backed by a live Kafka client (user code).
## Not run: 
kafka_collector <- function(consumer) {
  obj <- list(
    get_next = function() {
      msg <- reticulate::iter_next(consumer, completed = NULL)
      if (is.null(msg)) NULL else as.numeric(msg$value)
    },
    close = function() consumer$close()
  )
  class(obj) <- append("kafka_collector", "har_stream_collector")
  obj
}
# consumer <- reticulate::import("kafka")$KafkaConsumer("sensor-events", ...)
# source <- har_source_kafka("sensor-events", c("broker:9092"), "harbinger",
#                            collector = kafka_collector(consumer))

## End(Not run)

Simulated source

Description

Creates a replay source from an in-memory vector or data frame. This is the recommended source for reproducible streaming experiments and is the direct replacement for the simulated data flow used in the Nexus prototype.

Usage

har_source_simulated(data, timestamp = NULL, name = "simulated")

Arguments

data

Numeric vector, matrix, or data frame containing observations in time order.

timestamp

Optional vector with one timestamp per observation.

name

Source name.

Value

A har_source_simulated object.

Examples

source <- har_source_simulated(c(1, 2, 3))
obs <- next_observation(source)
obs$observation$value

Stream collector (extension seam for live brokers)

Description

Abstract pull collector that yields one observation at a time. This is the extension point for live streams: provide a collector whose get_next() returns a single observation (scalar, one-row data.frame, or a list with at least a value field) or NULL when the stream is exhausted, and an optional close(). Harbinger ships no broker dependency; a real Kafka collector is user-supplied code backed by the user's own client (e.g. via reticulate).

Usage

har_stream_collector()

Value

A har_stream_collector object whose get_next() must be overridden.

Examples

collector <- har_stream_collector()
try(collector$get_next())

Streaming evaluation for online detection

Description

Evaluates structured online traces produced by har_online_session(). This evaluator complements har_eval() by computing the metrics introduced in the Nexus paper, namely Detection Probability (DP) and Detection Lag (DL), while also exposing conventional end-of-run classification metrics when labels are available.

Usage

har_stream_eval()

Value

A har_stream_eval object.

Examples

source <- har_source_simulated(c(1, 1, 1, 10, 1, 1))
session <- har_online_session(
  source = source,
  detector = hcp_page_hinkley(min_instances = 3, threshold = 1),
  warmup_size = 3,
  batch_size = 1
)
session <- daltoolbox::fit(session)
session <- run_online(session)
trace <- collect_trace(session)
daltoolbox::evaluate(har_stream_eval(), trace)

Streaming experiment runner

Description

Runs a reproducible grid of online streaming experiments by combining detectors, source factories, batch settings, memory policies, and optional labeled references.

The experiment runner is intentionally lightweight. It reuses the online session layer and returns both the raw runs and a compact summary table.

Usage

har_stream_experiment(
  detectors,
  source_factory,
  warmup_grid,
  batch_grid,
  memory_grid,
  executor = har_online_refit_full(),
  reference = NULL,
  mode = c("auto", "pull", "push"),
  ...
)

Arguments

detectors

Named list of detector objects. An unnamed list is also accepted and will be labeled by class.

source_factory

Function that creates a fresh source object for each run. This keeps each execution independent and reproducible.

warmup_grid

Integer vector of warm-up sizes.

batch_grid

Integer vector of batch sizes.

memory_grid

List of memory policy objects.

executor

Execution strategy. Defaults to har_online_refit_full().

reference

Optional event reference vector.

mode

Session mode: "auto", "pull", or "push".

...

Additional arguments forwarded to run_online().

Value

A har_stream_experiment object with:

Examples

factory <- function() har_source_simulated(c(1, 1, 1, 10, 1, 1))
experiment <- har_stream_experiment(
  detectors = list(page = hcp_page_hinkley(min_instances = 3, threshold = 1)),
  source_factory = factory,
  warmup_grid = 3,
  batch_grid = c(1, 2),
  memory_grid = list(har_memory_full())
)
experiment$summary

Harbinger

Description

Base class for time series event detection in the Harbinger framework. It provides shared state handling and helper methods used by anomaly, change-point, and motif detectors. Concrete detectors extend this class and implement their own fit() and/or detect() S3 methods.

Usage

harbinger()

Details

Internally, this class stores references to the original series, indices of non-missing observations, and helper structures to restore detection results in the original series index space. It also exposes utility hooks for deviation measures, filter criteria, and candidate selection provided by harutils().

Value

A harbinger object that can be extended by detectors.

References

Examples

# See the specific detector examples for anomalies, change points, and motifs
# at https://cefet-rj-dal.github.io/harbinger


Harbinger Utilities

Description

Utility object that groups helper functions used by Harbinger detectors.

Usage

harutils()

Details

These helpers naturally fall into semantic groups rather than a single homogeneous toolbox.

Deviation measures

Filter criteria

For har_filter_mad(), the residual center is estimated by the sample median and the scale by the median absolute deviation (MAD), rescaled by 1.4826 by default so that it is consistent with the standard deviation under Gaussian data. This makes the rule robust when the residual distribution is skewed or already contains a few extreme points. If the MAD is zero, finite observations different from the median are selected against the degenerate interval ⁠[median, median]⁠.

For har_filter_grubbs(), the returned threshold attribute is an empirical detection boundary intended for interpretability in residual plots: it records the least extreme detected value on each side. This keeps the cutoff visually meaningful even though the Grubbs decision itself is iterative. The function also returns a score attribute with the Grubbs G statistic at each detected position and NA elsewhere.

Candidate selection

This organization makes it easier to swap only one semantic stage of the pipeline: score construction, filter definition, or candidate selection.

Value

A harutils object exposing the helper functions.

References

Examples

# Basic usage of utilities
utils <- harutils()

# Compute L2 distance on residuals
res <- c(0.1, -0.5, 1.2, -0.3)
d2 <- utils$har_deviation_l2(res)
print(d2)

# Huber deviation offers a smoother robust alternative
dh <- utils$har_deviation_huber(res)
print(dh)

# Apply 3-sigma outlier rule and keep only first index of contiguous runs
idx <- utils$har_filter_gaussian(d2)
flags <- utils$har_candidate_selection_firstgroup(idx, d2)
print(which(flags))

# MAD filter uses a robust location/scale summary
midx <- utils$har_filter_mad(c(d2, 8))
print(attr(midx, "threshold"))

# Grubbs outlier rule with an interpretable plotting threshold
gidx <- utils$har_filter_grubbs(c(d2, 8))
print(attr(gidx, "threshold"))
print(attr(gidx, "score")[gidx])

# Sequence-aware candidate selection using a reference distribution
idx2 <- c(31, 32, 33)
flags2 <- utils$har_candidate_selection_referencedistribution(
  idx2,
  c(rep(0, 30), 4, 5, 4.5),
  c(rep(0, 30), 4, 5, 4.5)
)
print(which(flags2))


At Most One Change (AMOC)

Description

Change-point detection method focusing on identifying at most one change in mean and/or variance via exact single-split Gaussian profile log-likelihood.

Usage

hcp_amoc()

Details

AMOC detects a single most significant change point under a cost function optimized for a univariate series. It is useful when at most one structural break is expected.

Value

hcp_amoc object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure the AMOC detector
model <- hcp_amoc()

# Fit the detector (no-op for AMOC)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change point(s)
print(detection[(detection$event),])


Binary Segmentation (BinSeg)

Description

Multi-change-point detection via Binary Segmentation on Gaussian mean/variance profile log-likelihood.

Usage

hcp_binseg(Q = 2)

Arguments

Q

Integer. Maximum number of change points to search for.

Details

Binary Segmentation recursively partitions the series around the largest detected change until a maximum number of change points or stopping criterion is met. This is a fast heuristic widely used in practice.

Value

hcp_binseg object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure the BinSeg detector
model <- hcp_binseg()

# Fit the detector (no-op for BinSeg)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Bayesian Online Change Point Detection – "++" re-implementation

Description

Change-point detection with a native, self-contained Bayesian Online Change Point Detector (no ocp dependency). This is an adaptation of BOCPD (Adams & MacKay 2007) with documented innovations over the ocp backend:

  1. Autoregressive UPM. ocp uses an i.i.d. Gaussian underlying predictive model, which only sees shifts in level and variance. Here the per-run-length model is a conjugate Bayesian linear autoregression (a regression of x_t on ⁠[1, x_{t-1}, ...]⁠, Normal-Inverse-Gamma prior, Student-t predictive), so it also detects changes in dynamics (slope, trend, autocorrelation).

  2. Log-space + eps-pruning. The run-length recursion runs in log-space and the run-length distribution is pruned to the entries holding all but a fraction prune_eps of the peak mass – a bounded-state, streaming recursion.

  3. Surprise-based extraction. Change points are read from the Bayesian predictive surprise ⁠-log p(x_t | x_{1:t-1})⁠ via a causal robust local z-score, replacing ocp's noisy three-list voting.

This mirrors the canonical implementation in the pyharbinger package (class HcpBocpd); the two implementations produce identical detections.

Usage

hcp_bocpd(
  hazard = 250,
  threshold = 6,
  min_distance = 15,
  burn_in = 5,
  order = 1,
  local_window = 20,
  prune_eps = 1e-06
)

Arguments

hazard

Positive scalar; the prior change probability per step is 1 / hazard.

threshold

Local z-score a surprise peak must reach to be flagged.

min_distance

Minimum distance between selected change points.

burn_in

Number of initial observations to ignore.

order

Autoregressive order of the UPM (regressors ⁠[1, x_{t-1}, ...]⁠).

local_window

Trailing window of the robust local z-score baseline.

prune_eps

Run lengths below prune_eps times the peak mass are pruned.

Value

An hcp_bocpd object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure BOCPD detector
model <- hcp_bocpd()

# Fit the model (no-op; detection is self-contained)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Change Finder (robust), autoregressive SDAR – "++" re-implementation

Description

Change-point detection with a native, self-contained robust ChangeFinder (no forecast dependency). This is an adaptation of the original ChangeFinder-ARIMA with documented innovations: instead of scoring forecast::auto.arima residuals, it implements the canonical two-stage online SDAR (Sequentially Discounting AutoRegressive) ChangeFinder of Takeuchi & Yamanishi (2006) – strong on abrupt/variance/multi-change regimes – and takes the union with a Gaussian mean+variance structural break (shared with hcp_chow/hcp_gft), which recovers the smooth trend/slope changes the AR-surprise score is blind to.

This mirrors the canonical implementation in the pyharbinger package (class HcpCfArima); the two implementations produce identical detections.

Usage

hcp_cf_arima(sw_size = 5, r = 0.07, order = 1, h = 0.15)

Arguments

sw_size

Integer. Smoothing window for the two-stage scores / warm-up.

r

SDAR forgetting (discounting) factor.

order

Autoregressive order of the SDAR model.

h

Minimal segment fraction for the mean+variance structural break.

Value

hcp_cf_arima object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure ChangeFinder-ARIMA detector
model <- hcp_cf_arima()

# Fit the model (no-op; detection is self-contained)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Change Finder (robust), discounted Holt – "++" re-implementation

Description

Change-point detection with a native, self-contained robust ChangeFinder (no forecast dependency). This is an adaptation of the original ChangeFinder-ETS with documented innovations: instead of scoring forecast::ets residuals, it implements the canonical two-stage online ChangeFinder of Takeuchi & Yamanishi (2006) with a discounted Holt (level+trend, the exponential-smoothing analogue of SDAR) predictor, and takes the union with a Gaussian mean+variance structural break (shared with hcp_chow/hcp_gft), which recovers smooth trend/slope changes the surprise score is blind to.

This mirrors the canonical implementation in the pyharbinger package (class HcpCfEts); the two implementations produce identical detections.

Usage

hcp_cf_ets(sw_size = 5, alpha = 0.8, beta = 0.1, r = 0.05, h = 0.15)

Arguments

sw_size

Integer. Smoothing window for the two-stage scores / warm-up.

alpha

Holt level smoothing factor.

beta

Holt trend smoothing factor.

r

Forgetting (discounting) factor for the residual variance.

h

Minimal segment fraction for the mean+variance structural break.

Value

hcp_cf_ets object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure ChangeFinder-ETS detector
model <- hcp_cf_ets()

# Fit the model (no-op; detection is self-contained)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Change Finder using Linear Regression

Description

Change-point detection by modeling residual deviations with linear regression and applying a second-stage smoothing and thresholding, inspired by ChangeFinder https://doi.org/10.1109/TKDE.2006.1599387.

Usage

hcp_cf_lr(sw_size = 30)

Arguments

sw_size

Integer. Sliding window size for smoothing/statistics.

Value

hcp_cf_lr object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure ChangeFinder-LR detector
model <- hcp_cf_lr()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Chow Test (structural break), scale-aware re-implementation

Description

Change-point detection by structural break in a linear model. This is a native re-implementation (no strucchange dependency) and an adaptation of the original Chow/strucchange approach with a documented innovation: where the classical Chow test only compares the mean regression coefficients of the two sub-samples (homoskedastic errors), this version reports the single break that maximises the Gaussian mean + variance log-likelihood ratio over an unknown break date. It is therefore scale-aware – it also detects variance/scale regime changes the mean-only Chow test is blind to. The break is scanned over the trimmed range following the sup-type construction of Andrews (1993).

This mirrors the canonical implementation in the pyharbinger package (class HcpChow); the two implementations produce identical detections.

Usage

hcp_chow()

Value

hcp_chow object

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure the Chow detector
model <- hcp_chow()

# Fit the detector (no-op for Chow)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Change-point detector using GARCH (GARCH++)

Description

Change-point detection for variance and regime shifts using a native ARMA(1,1)-GARCH(1,1) model. Combines BIC-penalized step-change segmentation on log conditional variance (Inclan & Tiao 1994; Kokoszka & Leipus 2000) with ChangeFinder smoothing on standardized GARCH residuals.

Usage

hcp_garch(sw_size = 5, min_seg = 25, pen_scale = 8, min_gap = 15)

Arguments

sw_size

Sliding window size for ChangeFinder residual smoothing (default 5).

min_seg

Minimum segment length for log-volatility segmentation (default 25).

pen_scale

BIC penalty multiplier for log-volatility breaks (default 8.0).

min_gap

Minimum separation when merging volatility and residual breaks (default 15).

Value

hcp_garch object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use an increasing amplitude example
dataset <- examples_changepoints$increasing_amplitude
head(dataset)

# Configure GARCH++ change-point detector
model <- hcp_garch()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Generalized Fluctuation Test (GFT), scale-aware re-implementation

Description

Structural change detection by multiple breaks in a linear model. This is a native re-implementation (no strucchange dependency) and an adaptation of the original strucchange::breakpoints approach with documented innovations: (1) the least-squares (mean-only) Bai & Perron breakpoints are generalised to a Gaussian mean + variance segmentation cost (each segment pays the ML deviance m * log(RSS/m) with a per-segment variance), so breaks in scale/variance regimes are detected, not only breaks in the mean/trend; (2) the number of breaks is chosen by the conservative LWZ information criterion (Liu, Wu & Zidek 1997) instead of the Gaussian BIC, which curbs over-segmentation; (3) the Bai-Perron dynamic program is vectorised.

This mirrors the canonical implementation in the pyharbinger package (class HcpGft); the two implementations produce identical detections.

Usage

hcp_gft(penalty = "lwz")

Arguments

penalty

break-count information criterion: "lwz" (default, conservative) or "bic".

Value

hcp_gft object

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure the GFT detector
model <- hcp_gft()

# Fit the detector (no-op for GFT)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Joinpoint Regression++ change-point detector

Description

Piecewise linear change-point detection based on Joinpoint Regression++.

The detector searches for a globally optimal set of joinpoints with dynamic programming, fits linear segments between candidate breaks, and compares models with 0 to k_max joinpoints using BIC, BIC3, and a weighted BIC (WBIC) criterion.

This implementation is intended for univariate numeric series and follows the same family of ideas used by the National Cancer Institute Joinpoint Regression Program, but it is documented here as a Joinpoint Regression++ variant because it replaces brute-force breakpoint enumeration with dynamic programming and weighted model selection while keeping a lightweight Harbinger-compatible API.

Usage

hcp_joinpoint(min_between = 2, min_end = 2, k_max = 5, log_transform = FALSE)

Arguments

min_between

Minimum number of observations between consecutive joinpoints.

min_end

Minimum number of observations required in the first and last segments.

k_max

Maximum number of joinpoints considered during model selection.

log_transform

Logical indicating whether the series should be log transformed before fitting. This is useful for multiplicative trends and growth-rate interpretation.

Value

An hcp_joinpoint object.

References


KSWIN change-point detector

Description

Kolmogorov-Smirnov Windowing for univariate time series. The detector keeps a sliding window, compares an early sample against the most recent observations, and flags a changepoint when the two empirical distributions differ significantly.

This implementation is restricted to univariate numeric series and is intended to capture virtual drift on the signal directly, without any classifier.

Usage

hcp_kswin(window_size = 100, stat_size = 30, alpha = 0.005, data = NULL)

Arguments

window_size

Size of the sliding window.

stat_size

Size of the statistic subwindow used for the KS test.

alpha

Significance level for the KS test.

data

Optional initial window content.

Value

An hcp_kswin object.

References


Page-Hinkley change-point detector

Description

Online change-point detection for univariate time series using the classical Page-Hinkley statistic. The detector accumulates deviations from the running mean and raises a changepoint when the cumulative score crosses the configured threshold.

This implementation is restricted to univariate numeric series. It is meant to capture virtual drift on the observed signal directly, without any classifier or multivariate preprocessing.

Usage

hcp_page_hinkley(
  min_instances = 30,
  delta = 0.005,
  threshold = 50,
  alpha = 1 - 1e-04
)

Arguments

min_instances

Minimum number of observations required before a change can be reported.

delta

Slack term subtracted from the deviation score.

threshold

Detection threshold for the cumulative statistic.

alpha

Forgetting factor applied to the cumulative score.

Value

An hcp_page_hinkley object.

References


Pruned Exact Linear Time (PELT)

Description

Multiple change-point detection using the PELT algorithm for Gaussian mean/variance with Liu-Wu-Zidek (LWZ) penalty.

Usage

hcp_pelt()

Details

PELT performs optimal partitioning while pruning candidate change-point locations to achieve near-linear computational cost.

Value

hcp_pelt object.

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure the PELT detector
model <- hcp_pelt()

# Fit the detector (no-op for PELT)
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Seminal change point

Description

Window-based change-point detection that compares two local linear models fitted on each sliding window: one using the full window and another using the same window split around its central observation. The difference between the two residual summaries is used as the change score.

The method is called "seminal" because the paper defines a seminal point for each window family, i.e. the central observation used to split the local regression into two sides. This makes the detector a local family method based on windows rather than a global segmentation algorithm.

Usage

hcp_scp(sw_size = 30)

Arguments

sw_size

Sliding window size.

Value

hcp_scp object

References

Examples

library(daltoolbox)

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Configure the seminal change-point detector
model <- hcp_scp()

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected change points
print(detection[(detection$event),])


Waypoint: adaptive change-point detection with autoencoder and CUSUM

Description

Implements the adaptive change-point detector described in the associated SBBD article: a non-supervised autoencoder learns a reference regime from temporal windows, the reconstruction error is standardized on a recent buffer, and a bilateral CUSUM supervisor validates persistent deviations. When a change is confirmed, the model is retrained on recent data and the supervisor is reset.

Usage

hcp_waypoint(
  input_size,
  encode_size,
  warmup = 500,
  retrain_size = 300,
  buffer_size = 100,
  k_factor = 0.35,
  h_low = 3.5,
  h_high = 6,
  prob_tau = 0.997,
  epochs_init = 40,
  epochs_retrain = 20,
  encoderclass = autoenc_base_ed,
  ...
)

Arguments

input_size

Integer. Window size used to build autoencoder samples.

encode_size

Integer. Latent size for the autoencoder.

warmup

Integer. Number of leading observations used to initialize the model.

retrain_size

Integer. Number of recent observations used when retraining after a confirmed change.

buffer_size

Integer. Number of previous residuals used to standardize the current reconstruction error.

k_factor

Numeric. CUSUM reference value (k).

h_low

Numeric. Warning threshold for the bilateral CUSUM supervisor.

h_high

Numeric. Confirmation threshold for the bilateral CUSUM supervisor.

prob_tau

Numeric. Quantile used to estimate the residual threshold from the warm-up regime.

epochs_init

Integer. Epochs for the initial autoencoder training.

epochs_retrain

Integer. Epochs for retraining after a confirmed change.

encoderclass

DALToolbox autoencoder constructor. Defaults to autoenc_base_ed.

...

Additional arguments forwarded to encoderclass; these are the autoencoder-specific parameters, not hcp_waypoint parameters.

Details

The method separates representation and decision:

This detector is intended for regime-change monitoring rather than isolated anomaly marking.

Value

hcp_waypoint object.

References

Examples

library(daltoolbox)

data(examples_changepoints)
dataset <- examples_changepoints$simple

model <- hcp_waypoint(input_size = 12, encode_size = 4)
model <- fit(model, dataset$serie)
detection <- detect(model, dataset$serie)
print(detection[detection$event, ])


Discord discovery using Matrix Profile (Keogh++ STOMP)

Description

Discovers unusual subsequences (discords) as local maxima of the canonical Keogh Matrix Profile (STOMP) separated by the exclusion zone round(w / 2), enhanced with the Complexity Annotation Vector (Batista & Keogh 2014; Dau & Keogh 2017) and adaptive statistical thresholding via har_outliers when qtd = NULL (or Keogh Top-K discords when qtd = k).

Usage

hdis_mp(w = 4, qtd = NULL, annotation = TRUE)

Arguments

w

Integer. Subsequence window size (must be >= 4).

qtd

Integer or NULL. Number of top discords to return (Keogh Top-K), or NULL (default) for adaptive statistical thresholding.

annotation

Logical. Weight the Matrix Profile by the Complexity Annotation Vector (Dau & Keogh 2017) when TRUE.

Value

hdis_mp object.

References

Examples

library(daltoolbox)

# Load anomaly example data
data(examples_anomalies)

# Use a simple example
dataset <- examples_anomalies$simple
head(dataset)

# Configure discord discovery via Matrix Profile
model <- hdis_mp(w = 10)

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected discords
print(detection[(detection$event),])


Discord discovery using SAX

Description

Discord discovery using SAX https://doi.org/10.1007/s10618-007-0064-z

Usage

hdis_sax(a, w, qtd = 2)

Arguments

a

alphabet size

w

word size

qtd

number of occurrences to be classified as discords

Value

hdis_sax object

References

Examples

library(daltoolbox)

# Load motif/discord example data
data(examples_motifs)

# Use a simple sequence example
dataset <- examples_motifs$simple
head(dataset)

# Configure discord discovery via SAX
model <- hdis_sax(26, 3, 3)

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected discords
print(detection[(detection$event),])


Motif discovery using Matrix Profile (Keogh++ STOMP)

Description

Discovers repeated subsequences (motifs) using the canonical Keogh Matrix Profile (STOMP) with optional Flatness Annotation Vector (Dau & Keogh 2017, Matrix Profile V) to suppress trivial low-variance segments. Self-contained native implementation shared across the DAL stack.

Usage

hmo_mp(
  w = 4,
  qtd = 2,
  n_motifs = 1,
  n_neighbors = 10,
  radius = 3,
  annotation = TRUE
)

Arguments

w

Integer. Subsequence window size (must be >= 4).

qtd

Integer. Minimum number of occurrences to classify a motif group (>= 2).

n_motifs

Integer. Maximum number of motif groups to extract (default 1).

n_neighbors

Integer. Maximum extra occurrences gathered per motif group (default 10).

radius

Numeric. Radius multiplier around the motif pair distance (default 3).

annotation

Logical. Apply Flatness Annotation Vector (Dau & Keogh 2017) when TRUE.

Value

hmo_mp object.

References

Examples

library(daltoolbox)

# Load motif example data
data(examples_motifs)

# Use a simple sequence example
dataset <- examples_motifs$simple
head(dataset)

# Configure motif discovery via Matrix Profile
model <- hmo_mp(w = 4, qtd = 3)

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected motifs
print(detection[(detection$event),])


Motif discovery using SAX

Description

Discovers repeated subsequences (motifs) using a Symbolic Aggregate approXimation (SAX) representation https://doi.org/10.1007/s10618-007-0064-z. Subsequences are discretized and grouped by symbolic words; frequently occurring words indicate motifs.

Usage

hmo_sax(a, w, qtd = 2)

Arguments

a

Integer. Alphabet size.

w

Integer. Word/window size.

qtd

Integer. Minimum number of occurrences to classify as a motif.

Value

hmo_sax object.

References

Examples

library(daltoolbox)

# Load motif example data
data(examples_motifs)

# Use a simple sequence example
dataset <- examples_motifs$simple
head(dataset)

# Configure SAX-based motif discovery
model <- hmo_sax(26, 3, 3)

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected motifs
print(detection[(detection$event),])


Motif discovery using XSAX

Description

Discovers repeated subsequences (motifs) using an extended SAX (XSAX) representation that supports a larger alphanumeric alphabet.

Usage

hmo_xsax(a, w, qtd)

Arguments

a

Integer. Alphabet size.

w

Integer. Word/window size.

qtd

Integer. Minimum number of occurrences to be classified as motifs.

Value

hmo_xsax object.

References

Examples

library(daltoolbox)

# Load motif example data
data(examples_motifs)

# Use a simple sequence example
dataset <- examples_motifs$simple
head(dataset)

# Configure XSAX-based motif discovery
model <- hmo_xsax(37, 3, 3)

# Fit the model
model <- fit(model, dataset$serie)

# Run detection
detection <- detect(model, dataset$serie)

# Show detected motifs
print(detection[(detection$event),])


Multivariate anomaly detector using PCA

Description

Projects multivariate observations onto principal components and flags large reconstruction errors as anomalies. Based on classical PCA.

Usage

hmu_pca(num_components = NULL, variance = 0.9)

Arguments

num_components

Integer or NULL. Number of principal components to retain for reconstruction. When NULL (default) the number is chosen automatically from variance.

variance

Numeric in (0, 1]. Target cumulative proportion of variance used to pick num_components automatically when it is NULL.

Details

The series is standardized, PCA is computed, and the data are reconstructed from a reduced set of principal components. The reconstruction error (the part of the signal not captured by the retained components) is summarized and thresholded as the anomaly score.

Keeping all components would reconstruct the data exactly, leaving only floating-point round-off as the residual (a degenerate detector). By default hmu_pca therefore keeps the leading components that explain variance of the total variance, capped at ncol - 1 so at least one component is always dropped. Pass num_components to fix the number of retained components explicitly.

Value

hmu_pca object.

References

Examples

library(daltoolbox)

# Load multivariate example data
data(examples_harbinger)

# Use a multidimensional time series
dataset <- examples_harbinger$multidimensional
head(dataset)

# Configure PCA-based anomaly detector
model <- hmu_pca()

# Fit the model (example uses first two columns)
model <- fit(model, dataset[,1:2])

# Run detection
detection <- detect(model, dataset[,1:2])

# Show detected anomalies
print(detection[(detection$event),])

# Evaluate detections
evaluation <- evaluate(model, detection$event, dataset$event)
print(evaluation$confMatrix)


Add observations to an online session

Description

Pushes one observation or a collection of observations into the session queue. This is the main entry point for push-style integrations.

Usage

ingest(obj, observation)

Arguments

obj

Online session.

observation

One observation, a list of observations, or a data frame. Each individual observation is normalized to the online observation contract used by next_observation().

Value

Updated har_online_session.


Test whether an online session has finished

Description

Returns TRUE when there is no queued observation left and the pull source is exhausted. In push mode, the session is considered finished when the queue is empty.

Usage

is_finished(obj)

Arguments

obj

Online session.

Value

Logical scalar.


Load full dataset from mini data object

Description

The mini datasets stored in ⁠data/⁠ include an attr(url) pointing to the full dataset in ⁠harbinger/⁠. This helper downloads and loads the full data.

Usage

loadfulldata(x, envir = parent.frame())

Arguments

x

Dataset object or its name (string or symbol).

envir

Environment to load the full dataset into.

Value

The full dataset object.

Examples

data(A1Benchmark)
A1Benchmark <- loadfulldata(A1Benchmark)

Moving average smoothing

Description

The mas() function returns a simple moving average smoother of the provided time series.

Usage

mas(x, order)

Arguments

x

A numeric vector or univariate time series.

order

Order of moving average smoother.

Details

The moving average smoother transformation is given by

(1/k) * ( x[t] + x[t+1] + ... + x[t+k-1] )

where k=order, t assume values in the range 1:(n-k+1), and n=length(x). See also the ma of the forecast package.

Value

Numerical time series of length length(x)-order+1 containing the simple moving average smoothed values.

References

R.H. Shumway and D.S. Stoffer, 2010, Time Series Analysis and Its Applications: With R Examples. 3rd ed. 2011 edition ed. New York, Springer.

Examples

# Load change-point example data
data(examples_changepoints)

# Use a simple example
dataset <- examples_changepoints$simple
head(dataset)

# Compute a 5-point moving average
ma <- mas(dataset$serie, 5)

MIT-BIH Arrhythmia Database – MLII Lead

Description

Data collection with real-world time-series. MIT-BIH Arrhythmia Database (MIT-BIH). See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(mit_bih_MLII)

Format

A list of time series from the MLII sensor of the MIT-BIH Arrhythmia Database.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1109/51.932724

References

MIT-BIH Arrhythmia Database (MIT-BIH). See also: Moody, G. B., & Mark, R. G. (2001). The impact of the MIT-BIH Arrhythmia Database. IEEE Engineering in Medicine and Biology Magazine, 20(3), 45–50.

Examples

data(mit_bih_MLII)
data <- mit_bih_MLII[[1]]
series <- data$value

MIT-BIH Arrhythmia Database – V1 Lead

Description

Data collection with real-world time-series. MIT-BIH Arrhythmia Database (MIT-BIH). See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(mit_bih_V1)

Format

A list of time series from the V1 sensor of the MIT-BIH Arrhythmia Database.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1109/51.932724

References

MIT-BIH Arrhythmia Database (MIT-BIH). See also: Moody, G. B., & Mark, R. G. (2001). The impact of the MIT-BIH Arrhythmia Database. IEEE Engineering in Medicine and Biology Magazine, 20(3), 45–50.

Examples

data(mit_bih_V1)
data <- mit_bih_V1[[1]]
series <- data$value

MIT-BIH Arrhythmia Database – V2 Lead

Description

Data collection with real-world time-series. MIT-BIH Arrhythmia Database (MIT-BIH). See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(mit_bih_V2)

Format

A list of time series from the V2 sensor of the MIT-BIH Arrhythmia Database.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1109/51.932724

References

MIT-BIH Arrhythmia Database (MIT-BIH). See also: Moody, G. B., & Mark, R. G. (2001). The impact of the MIT-BIH Arrhythmia Database. IEEE Engineering in Medicine and Biology Magazine, 20(3), 45–50.

Examples

data(mit_bih_V2)
data <- mit_bih_V2[[1]]
series <- data$value

MIT-BIH Arrhythmia Database – V5 Lead

Description

Data collection with real-world time-series. MIT-BIH Arrhythmia Database (MIT-BIH). See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(mit_bih_V5)

Format

A list of time series from the V5 sensor of the MIT-BIH Arrhythmia Database.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

doi:10.1109/51.932724

References

MIT-BIH Arrhythmia Database (MIT-BIH). See also: Moody, G. B., & Mark, R. G. (2001). The impact of the MIT-BIH Arrhythmia Database. IEEE Engineering in Medicine and Biology Magazine, 20(3), 45–50.

Examples

data(mit_bih_V5)
data <- mit_bih_V5[[1]]
series <- data$value

Numenta Anomaly Benchmark (NAB) – artificialWithAnomaly

Description

Synthetic time series with injected anomalies from the Numenta Anomaly Benchmark (NAB). Designed for evaluating anomaly detection algorithms under controlled conditions. Labels available: Yes. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(nab_artificialWithAnomaly)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

Numenta Anomaly Benchmark (NAB) Dataset

References

Lavin, A., & Ahmad, S. (2015). Evaluating real-time anomaly detection algorithms – the Numenta Anomaly Benchmark. 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA).

Examples

data(nab_artificialWithAnomaly)
s <- nab_artificialWithAnomaly[[1]]
plot(ts(s$value), main = names(nab_artificialWithAnomaly)[1])

Numenta Anomaly Benchmark (NAB) realAWSCloudwatch

Description

Data collection with real-world time-series. Real data from AWS Cloud with anomalies As part of the Numenta Anomaly Benchmark (NAB), this dataset contains time series with real and synthetic data. The real data comes from network monitoring and cloud computing. On the other hand, synthetic data simulate series with or without anomalies. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(nab_realAWSCloudwatch)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

Numenta Anomaly Benchmark (NAB) Dataset

References

Lavin, A., & Ahmad, S. (2015). Evaluating real-time anomaly detection algorithms – the Numenta Anomaly Benchmark. 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA).

Examples

data(nab_realAWSCloudwatch)
nab_grp <- nab_realAWSCloudwatch[[1]]
serie <- nab_grp[[1]]

Numenta Anomaly Benchmark (NAB) – realAdExchange

Description

Real-world time series with labeled anomalies from ad exchange data (NAB). Useful for evaluating detection methods on operational data. Labels available: Yes. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(nab_realAdExchange)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

Numenta Anomaly Benchmark (NAB) Dataset

References

Lavin, A., & Ahmad, S. (2015). Evaluating real-time anomaly detection algorithms – the Numenta Anomaly Benchmark. 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA).

Examples

data(nab_realAdExchange)
s <- nab_realAdExchange[[1]]
mean(s$event)

Numenta Anomaly Benchmark (NAB) realKnownCause

Description

Data collection with real-world time-series. Real data with anomalies As part of the Numenta Anomaly Benchmark (NAB), this dataset contains time series with real and synthetic data. The real data comes from network monitoring and cloud computing. On the other hand, synthetic data simulate series with or without anomalies. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(nab_realKnownCause)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

Numenta Anomaly Benchmark (NAB) Dataset

References

Lavin, A., & Ahmad, S. (2015). Evaluating real-time anomaly detection algorithms – the Numenta Anomaly Benchmark. 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA).

Examples

data(nab_realKnownCause)
nab_grp <- nab_realKnownCause[[1]]
serie <- nab_grp[[1]]

Numenta Anomaly Benchmark (NAB) realTraffic

Description

Data collection with real-world time-series. Real data from online data traffic with anomalies As part of the Numenta Anomaly Benchmark (NAB), this dataset contains time series with real and synthetic data. The real data comes from network monitoring and cloud computing. On the other hand, synthetic data simulate series with or without anomalies. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(nab_realTraffic)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

Numenta Anomaly Benchmark (NAB) Dataset

References

Lavin, A., & Ahmad, S. (2015). Evaluating real-time anomaly detection algorithms – the Numenta Anomaly Benchmark. 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA).

Examples

data(nab_realTraffic)
nab_grp <- nab_realTraffic[[1]]
serie <- nab_grp[[1]]

Numenta Anomaly Benchmark (NAB) realTweets

Description

Real-world time series with labeled anomalies from Twitter volumes (NAB). Labels available: Yes. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(nab_realTweets)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

Numenta Anomaly Benchmark (NAB) Dataset

References

Lavin, A., & Ahmad, S. (2015). Evaluating real-time anomaly detection algorithms – the Numenta Anomaly Benchmark. 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA).

Examples

data(nab_realTweets)
s <- nab_realTweets[[1]]
plot(ts(s$value), main = names(nab_realTweets)[1])
mean(s$event)

Get the next observation from a source

Description

Generic used by Harbinger online sessions to request one observation in pull mode.

Usage

next_observation(obj, ...)

Arguments

obj

Source object.

...

Additional arguments passed to methods.

Value

A list with fields:


Oil Wells Dataset – Type 1

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Type 0 removed from this version due to file size. Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_1)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_1)
s <- oil_3w_Type_1[[1]]
plot(ts(s$p_tpt), main = names(oil_3w_Type_1)[1], ylab = "value")

Oil Wells Dataset – Type 2

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_2)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_2)
s <- oil_3w_Type_2[[1]]
mean(s$event)  # proportion of change points

Oil Wells Dataset – Type 4

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_4)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_4)
serie <- oil_3w_Type_4[[1]]

Oil Wells Dataset – Type 5

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_5)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_5)
serie <- oil_3w_Type_5[[1]]

Oil Wells Dataset – Type 6

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_6)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_6)
serie <- oil_3w_Type_6[[1]]

Oil Wells Dataset – Type 7

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_7)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_7)
serie <- oil_3w_Type_7[[1]]

Oil Wells Dataset – Type 8

Description

First realistic dataset with real events in oil well drilling. The data available in this package consist of time series already analyzed and applied in research experiments by the DAL group (Data Analytics Lab). The series are divided into 7 groups (Type_0, Type_1, Type_2, Type_4, Type_5, Type_6, Type_7 and Type_8). Creation date: 2019. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(oil_3w_Type_8)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCI Machine Learning Repository

References

3W dataset (UCI repository). See also: Truong, C., Oudre, L., & Vayatis, N. (2020). Selective review of change point detection methods. Signal Processing, 167, 107299.

Examples

data(oil_3w_Type_8)
serie <- oil_3w_Type_8[[1]]

Run an online session

Description

Processes the session until the pull source is exhausted and the push queue is empty, or until a fixed number of online detection cycles has been executed.

Usage

run_online(obj, max_batches = NULL, ...)

Arguments

obj

Online session.

max_batches

Optional maximum number of detection cycles to execute.

...

Additional arguments forwarded to wrapped detector methods.

Value

Updated har_online_session.


Retrieve source metadata

Description

Returns descriptive metadata about a Harbinger source object.

Usage

source_info(obj, ...)

Arguments

obj

Source object.

...

Additional arguments passed to methods.

Value

A named list with source metadata.


Step an online session once

Description

Consumes at most one new observation and triggers one batch detection cycle when the batch threshold is reached.

Usage

step_online(obj, ...)

Arguments

obj

Online session.

...

Additional arguments forwarded to wrapped detector methods.

Value

Updated har_online_session.


SAX transformation

Description

Symbolic Aggregate approXimation (SAX) discretization of a numeric time series. The series is z-normalized, quantile-binned, and mapped to an alphabet of size alpha.

Usage

trans_sax(alpha)

Arguments

alpha

Integer. Alphabet size (2–26).

Value

A trans_sax transformer object.

References

Examples

library(daltoolbox)
vector <- 1:52
model <- trans_sax(alpha = 26)
model <- fit(model, vector)
xvector <- transform(model, vector)
print(xvector)


XSAX transformation

Description

Extended SAX (XSAX) discretization using a larger alphanumeric alphabet for finer symbolic resolution.

Usage

trans_xsax(alpha)

Arguments

alpha

Integer. Alphabet size (2–36).

Value

A trans_xsax transformer object.

References

See Also

trans_sax

Examples

library(daltoolbox)
vector <- 1:52
model <- trans_xsax(alpha = 36)
model <- fit(model, vector)
xvector <- transform(model, vector)
print(xvector)


UCR Anomaly Archive – ECG

Description

Data collection with real-world time-series. Real ECG time series with labeled anomalous intervals. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(ucr_ecg)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCR Anomaly Archive

References

UCR Time Series Anomaly Archive. See also: Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(ucr_ecg)
# Access and plot a series
s <- ucr_ecg[[1]]
plot(ts(s$value), main = names(ucr_ecg)[1])

UCR Anomaly Archive – Internal Bleeding

Description

Data collection with real-world time-series. Real physiological time series with labeled anomalous intervals. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(ucr_int_bleeding)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCR Anomaly Archive

References

UCR Time Series Anomaly Archive. See also: Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(ucr_int_bleeding)
s <- ucr_int_bleeding[[1]]
plot(ts(s$value))

UCR Anomaly Archive – NASA Spacecraft

Description

Data collection with real-world time-series. Real NASA spacecraft monitoring time series with labeled anomalous intervals. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(ucr_nasa)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCR Anomaly Archive

References

UCR Time Series Anomaly Archive. See also: Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(ucr_nasa)
s <- ucr_nasa[[1]]
mean(s$event)

UCR Anomaly Archive – Italian Power Demand

Description

Data collection with real-world time-series. Real power demand time series with labeled anomalous intervals. See cefet-rj-dal/united for detailed guidance on using this package and the other datasets available in it. Labels available? Yes

Usage

data(ucr_power_demand)

Format

A list of time series.

Details

This package ships a mini version of the dataset. Use loadfulldata() to download and load the full dataset from the URL stored in attr(url).

Source

UCR Anomaly Archive

References

UCR Time Series Anomaly Archive. See also: Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 1–58.

Examples

data(ucr_power_demand)
s <- ucr_power_demand[[1]]
summary(s$value)