% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cv_estimators.R
\name{werm_huber_cv}
\alias{werm_huber_cv}
\title{Fit a WERM changepoint model with Huber loss and CV selection}
\usage{
werm_huber_cv(
  X,
  y,
  max_num_chgpts,
  delta = 1L,
  search_method = "efficient",
  cv = 5L,
  fit_intercept = TRUE,
  epsilon = 1.35,
  max_iter = 100L,
  tol = 1e-05,
  use_base_loss_for_cv = FALSE,
  penalty = "none",
  alpha = 0
)
}
\arguments{
\item{X}{Numeric matrix of shape \verb{(n, p)}. Observations must be in order.}

\item{y}{Numeric vector of length \code{n}. Ordered responses.}

\item{max_num_chgpts}{Integer. Upper bound of the CV search grid.}

\item{delta}{Integer. Minimum gap between candidate changepoints.
Default \code{1}.}

\item{search_method}{Character. \code{"efficient"} (default) or \code{"brute_force"}.}

\item{cv}{Integer. Number of interleaved folds. Default \code{5}.}

\item{fit_intercept}{Logical. Default \code{TRUE}.}

\item{epsilon}{Numeric. Huber transition parameter. Default \code{1.35}.}

\item{max_iter}{Integer. Maximum L-BFGS-B iterations. Default \code{100}.}

\item{tol}{Numeric. Gradient-norm tolerance. Default \code{1e-5}.}

\item{use_base_loss_for_cv}{Logical. If \code{TRUE}, uses squared loss for CV
segment fits and scoring instead of the default absolute error.
Default \code{FALSE}.}

\item{penalty}{Character. Passed to the inner fixed model. Default \code{"none"}.}

\item{alpha}{Numeric. Penalty strength. Default \code{0}.}
}
\value{
An object of class \code{c("werm_huber_cv", "werm_fit")}.
}
\description{
Fit a WERM changepoint model with Huber loss and CV selection
}
\examples{
# Limit BLAS/OpenMP threads so example CPU time stays proportional to
# elapsed time on multicore CRAN machines.
Sys.setenv(
  OMP_NUM_THREADS = "1",
  OPENBLAS_NUM_THREADS = "1",
  MKL_NUM_THREADS = "1",
  BLAS_NUM_THREADS = "1"
)

if (nzchar(Sys.getenv("RETICULATE_PYTHON")) &&
    weightederm_examples_available("WERMHuberCV")) {
  set.seed(11)
  n <- 24L; p <- 2L
  X <- matrix(rnorm(n * p), n, p)
  y <- c(
    X[1:8, ] \%*\% c(4, 0),
    X[9:16, ] \%*\% c(-4, 0),
    X[17:24, ] \%*\% c(4, 0)
  ) + rnorm(n, sd = 0.02)
  fit <- werm_huber_cv(X, y, max_num_chgpts = 2L, cv = 3L, delta = 2L,
                       fit_intercept = FALSE, max_iter = 20L)
  fit$best_num_chgpts
}

}
