% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/detector.R
\name{calc_detector}
\alias{calc_detector}
\title{Compute the MLP-Based Changepoint Detector Statistic}
\usage{
calc_detector(y, fit_mlp_res, w = 100,
              ma_window = w, use_abs_det = TRUE)
}
\arguments{
\item{y}{Numeric vector. Original signal.}

\item{fit_mlp_res}{List. Output of \code{\link{fit_mlp}}, containing:
\itemize{
\item \code{small} — list of small-window MLP predictions
\item \code{large} — list of large-window MLP predictions
}}

\item{w}{Integer. Window size used for the small-window MLP.}

\item{ma_window}{Integer. Moving-average smoothing window applied to the
detector. Defaults to \code{w}.}

\item{use_abs_det}{Logical. Whether to take \code{abs(detector)} before
smoothing. Defaults to \code{TRUE}.}
}
\value{
A numeric vector of detector values of length \code{n - 2w}.
}
\description{
Computes the hybrid detector statistic used in scanCP. The detector
combines a \emph{ratio} component and a \emph{difference} component derived from
the residual sum of squares (RSS) of:
\itemize{
\item two adjacent small-window MLP fits (window size \code{w})
\item one large-window MLP fit (window size \verb{2w})
}

The detector highlights locations where the large-window fit performs
substantially worse than the two small-window fits, indicating a
potential changepoint.
}
\details{
For each index \code{i}, the detector uses:
\itemize{
\item \code{rss1}: RSS of the small-window MLP on \code{[i, i+w-1]}
\item \code{rss2}: RSS of the small-window MLP on \code{[i+w, i+2w-1]}
\item \code{rss.tot}: RSS of the large-window MLP on \code{[i, i+2w-1]}
}

The ratio component is:
\deqn{ (rss.tot + b) / (rss1 + rss2 + b) }

The difference component is:
\deqn{ rss.tot - rss1 - rss2 }

The final detector is a convex combination:
\deqn{ (1 - a) \cdot \text{ratio} + a \cdot \text{difference} }

Internal parameters \code{a}, \code{b}, and \code{scale_01} are kept
fixed at their defaults for simplicity and stability.
}
\examples{
\donttest{
  y <- rnorm(300)
  fit <- fit_mlp(y, w = 100)
  det <- calc_detector(y, fit, w = 100)
}

}
