% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mlp_fit.R
\name{fit_mlp}
\alias{fit_mlp}
\title{Fit Rolling MLP Models for Change Point Detection}
\usage{
fit_mlp(vec, w = 100, mlp_control = list(), parallel = FALSE)
}
\arguments{
\item{vec}{Numeric vector. The input signal.}

\item{w}{Integer. Window size for the small-window MLP. The large-window
MLP automatically uses window size \code{2w}.}

\item{mlp_control}{A named list of MLP hyperparameters. Any subset may be
supplied; unspecified values fall back to defaults. Supported fields:
\describe{
\item{\code{act1}}{Activation function for the small-window MLP
(\code{"Act_Logistic"}).}
\item{\code{act2}}{Activation function for the large-window MLP
(\code{"Act_Logistic"}).}
\item{\code{lr1}}{Learning rate for the small-window MLP
(default: \code{0.001}).}
\item{\code{lr2}}{Learning learning rate for the large-window MLP
(default: \code{0.001}).}
\item{\code{hl1}}{Number of hidden units for the small-window MLP
(default: \code{6}).}
\item{\code{hl2}}{Number of hidden units for the large-window MLP
(default: \code{8}).}
\item{\code{ep1}}{Training epochs for the small-window MLP
(default: \code{300}).}
\item{\code{ep2}}{Training epochs for the large-window MLP
(default: \code{600}).}
}}

\item{parallel}{Logical. If \code{TRUE}, rolling-window MLPs are
fitted using parallel computation via \pkg{parallel}, \pkg{foreach},
and \pkg{doSNOW}. If \code{FALSE}, all computation is performed
serially. Setting \code{parallel = FALSE} is recommended for CRAN checks
and for systems where parallel backends are unavailable.}
}
\value{
A list with two elements:
\describe{
\item{\code{small}}{List of fitted values for each rolling window of size \code{w}.}
\item{\code{large}}{List of fitted values for each rolling window of size \code{2w}.}
}
}
\description{
Fits two multilayer perceptron (MLP) models over rolling windows of a
univariate signal. A small-window MLP (window size \code{w}) captures
local structure, while a large-window MLP (window size \code{2w})
captures broader trends. Their residual behavior is used by
\code{\link{calc_detector}} to construct the changepoint detector.

All MLP hyperparameters are supplied through a unified
\code{mlp_control} list for consistency with \code{\link{scan_cp}}.
}
\details{
Each rolling window is standardized before fitting. The returned matrices
contain three columns:
\enumerate{
\item standardized input \code{x}
\item fitted values \code{y_hat}
\item original indices
}

When \code{parallel = TRUE}, a cluster is created using
\code{parallel::makeCluster()}.

When \code{parallel = FALSE}, the function falls back to
serial execution using \code{\%do\%}.
}
