% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{detector_update}
\alias{detector_update}
\title{Update detector with new observation(s)}
\usage{
detector_update(det_ptr, y)
}
\arguments{
\item{det_ptr}{External pointer to detector created by
\code{\link{detector_create}()}.}

\item{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.}
}
\value{
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.,
\code{det |> detector_update(y) |> get_statistics()}.
}
\description{
Adds new observation(s) to the detector's internal state and updates
sufficient statistics.
}
\examples{
# 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
  }
}


}
