% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{focus_offline}
\alias{focus_offline}
\title{Run FOCuS detector in offline batch mode}
\usage{
focus_offline(
  Y,
  threshold,
  type = "univariate",
  family = "gaussian",
  theta0 = NULL,
  dim_indexes = NULL,
  quantiles = NULL,
  pruning_mult = 2L,
  pruning_offset = 1L,
  side = "right",
  shape = NULL,
  anomaly_intensity = NULL,
  rho = NULL,
  mu0_arp = NULL
)
}
\arguments{
\item{Y}{Numeric vector or matrix. Data array. For univariate detection,
a numeric vector. For multivariate detection, a matrix with observations
in rows and dimensions in columns.}

\item{threshold}{Numeric scalar or vector. Detection threshold(s). Can be:
\itemize{
  \item A scalar: applied to all test statistics (default behavior for most cost functions)
  \item A vector: length must match the number of test statistics (for example, np-focus
    returns both the sum and max statistics, so threshold should be length 2).
  \item \code{Inf}: no thresholding (returns all statistics)
}}

\item{type}{Character string specifying detector type. See
\code{\link{detector_create}()} for options. Defaults to \code{"univariate"}.}

\item{family}{Character string specifying distribution family. See
\code{\link{get_statistics}()} for options. Defaults to \code{"gaussian"}.}

\item{theta0}{Numeric vector. Null hypothesis parameter. Default is \code{NULL}.}

\item{dim_indexes}{List of integer vectors. Projection index sets for
multivariate detectors. Default is \code{NULL}.}

\item{quantiles}{Numeric vector. Quantiles for nonparametric detectors.
Default is \code{NULL}.}

\item{pruning_mult}{Integer. Pruning multiplier parameter. Default is 2.}

\item{pruning_offset}{Integer. Pruning offset parameter. Default is 1.}

\item{side}{Character string. For one-sided detectors: \code{"right"} or
\code{"left"}. Default is \code{"right"}.}

\item{shape}{Numeric scalar. Shape parameter for gamma distribution.
Default is \code{NULL}.}

\item{anomaly_intensity}{Numeric scalar. Anomaly intensity threshold for
pruning candidates. Only candidates with sufficient signal magnitude are
retained. Default is \code{NULL} (disabled).}

\item{rho}{Numeric vector. AR coefficients for AutoRegressive Process (ARP)
detectors. Required when \code{type = "arp"}. Default is \code{NULL}.}

\item{mu0_arp}{Numeric scalar. Pre-change mean for ARP detectors (optional).
Only used when \code{type = "arp"}.
Default is \code{NULL}.}
}
\value{
A list with components:
  \item{stat}{Numeric matrix. Test statistics over time (n_obs × n_stats).
    Each row corresponds to one time point, each column to one statistic.}
  \item{changepoint}{Integer vector. Detected changepoints at each time
    point (1-based indices), or NA if no changepoint detected at that time.}
  \item{detection_time}{Integer or NULL. Time of first detection (1-based),
    or NULL if no detection occurred.}
  \item{detected_changepoint}{Integer or NULL. Changepoint location at
    detection time (1-based), or NULL if no detection occurred.}
  \item{candidates}{Data frame. Final candidate segments (see
    \code{detector_candidates()}).}
  \item{threshold}{Numeric vector. Threshold(s) used for detection.}
  \item{n}{Integer. Number of observations processed.}
  \item{type}{Character. Detector type used.}
  \item{family}{Character. Distribution family used.}
  \item{shape}{Numeric or NULL. Shape parameter (for gamma family).}
}
\description{
Processes all data at once and returns detection results and trajectories.
This is the most efficient way to run changepoint detection when all data
is available upfront.
}
\details{
This function runs the complete detection algorithm in C++ for maximum
efficiency. It processes observations sequentially and stops at the first
detection (when any statistic exceeds its threshold).

For multivariate data, the algorithm computes multiple statistics (one per
projection). Detection occurs when ANY statistic exceeds its threshold.
}
\examples{
# Univariate Gaussian detection
set.seed(123)
Y <- c(rnorm(100, mean = 0), rnorm(100, mean = 2))
result <- focus_offline(Y, threshold = 10, type = "univariate",
                       family = "gaussian")
cat("Detection at time:", result$detection_time, "\n")
cat("Changepoint at:", result$detected_changepoint, "\n")

# Plot statistics
plot(result$stat, type = "l", ylab = "Test Statistic", xlab = "Time")
abline(h = result$threshold, col = "red", lty = 2)
if (!is.null(result$detection_time)) {
  abline(v = result$detection_time, col = "blue", lty = 2)
}

# Poisson detection
Y_poisson <- c(rpois(100, lambda = 2), rpois(100, lambda = 5))
result_poisson <- focus_offline(Y_poisson, threshold = 10,
                                type = "univariate",
                                family = "poisson")

}
