| detector_update | R Documentation |
Adds new observation(s) to the detector's internal state and updates sufficient statistics.
detector_update(info_ptr, y)
info_ptr |
External pointer to detector created by
|
y |
Numeric vector of new observation(s). For univariate detectors, this should be a scalar (length-1 vector). For multivariate detectors, this should be a vector matching the number of dimensions. |
An external pointer to the detector (the same object that was passed in).
The detector is updated *in place* — no copy is made — so this return value
is provided only for convenience, for example when using the native R pipe
operator ('|>') e.g.,
det |> detector_update(y) |> get_statistics().
# Univariate example
det <- detector_create(type = "univariate")
detector_update(det, 0.5)
detector_update(det, 1.2)
# Multivariate example
det_mv <- detector_create(type = "multivariate")
detector_update(det_mv, c(0.5, 1.2, -0.3))
## Online (sequential) example
# Generate data with a changepoint
set.seed(123)
Y <- c(rnorm(500, mean = 0), rnorm(500, mean = 1))
det <- detector_create(type = "univariate")
stat_trace <- numeric(length(Y))
threshold <- 20
for (i in seq_along(Y)) {
detector_update(det, Y[i])
r <- get_statistics(det, family = "gaussian")
stat_trace[i] <- r$stat
if (!is.null(r$stat) && r$stat > threshold) {
cat("Online detection at", i, "estimate tau =", r$changepoint, "\n")
plot(stat_trace[1:i], type = "l", ylab = "Test Statistic", xlab = "Time")
break
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.