% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/safeguards.R
\name{detect_stagnation}
\alias{detect_stagnation}
\title{Detect Stagnation and Recommend Action}
\usage{
detect_stagnation(
  step_norms,
  f_values,
  tol_step = 1e-12,
  tol_f = 1e-14,
  max_stagnant = 5,
  is_qn = FALSE,
  already_refreshed = FALSE
)
}
\arguments{
\item{step_norms}{Vector of recent step norms (most recent last)}

\item{f_values}{Vector of recent function values (most recent last)}

\item{tol_step}{Step size tolerance for stagnation (default: 1e-12)}

\item{tol_f}{Function change tolerance for stagnation (default: 1e-14)}

\item{max_stagnant}{Maximum consecutive stagnant iterations before action (default: 5)}

\item{is_qn}{Logical; TRUE if using quasi-Newton (enables Hessian refresh option)}

\item{already_refreshed}{Logical; TRUE if Hessian was already refreshed once}
}
\value{
Character; one of "continue", "refresh_hessian", or "stop"
}
\description{
Monitors optimization progress and detects stagnation based on small consecutive
steps or function changes. Returns recommended action: continue, refresh Hessian,
or stop.
}
\details{
Stagnation is detected when either:
\itemize{
\item Step norms are consecutively below tol_step for max_stagnant iterations
\item Function changes are consecutively below tol_f for max_stagnant iterations
}

When stagnation is detected:
\itemize{
\item If using quasi-Newton and not already refreshed: return "refresh_hessian"
\item Otherwise: return "stop" (declare convergence failure)
}
}
\keyword{internal}
