Learn R Programming

RegimeChange (version 0.1.1)

autoencoder_detect: Autoencoder-based Changepoint Detection

Description

Detects changepoints by identifying regions where reconstruction error is anomalously high, indicating the model (trained on normal patterns) fails to reconstruct the data.

Usage

autoencoder_detect(
  data,
  window_size = 50,
  latent_dim = 10,
  hidden_dims = c(32, 16),
  epochs = 100,
  batch_size = 32,
  threshold = NULL,
  contamination = 0.1,
  variational = FALSE,
  verbose = FALSE
)

Value

List with:

changepoints

Detected changepoint locations

reconstruction_error

Per-window reconstruction error

threshold

Threshold used for detection

model

Trained Keras model

Arguments

data

Numeric vector of time series data

window_size

Size of sliding window (default: 50)

latent_dim

Dimension of latent space (default: 10)

hidden_dims

Hidden layer dimensions (default: c(32, 16))

epochs

Training epochs (default: 100)

batch_size

Batch size (default: 32)

threshold

Threshold for anomaly detection. NULL for automatic selection using 3-sigma rule.

contamination

Expected proportion of anomalies for threshold selection (default: 0.1)

variational

Use Variational Autoencoder (default: FALSE)

verbose

Show training progress (default: FALSE)

Examples

Run this code
if (FALSE) {
data <- c(rnorm(100), rnorm(100, mean = 3), rnorm(100))
result <- autoencoder_detect(data, window_size = 30)
plot(result$reconstruction_error, type = "l")
abline(v = result$changepoints, col = "red")
}

Run the code above in your browser using DataLab