% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convergence.R
\name{check_convergence}
\alias{check_convergence}
\title{Check Convergence Criteria (Stan-style)}
\usage{
check_convergence(
  g_current,
  f_current,
  f_previous,
  x_current,
  x_previous,
  iter,
  tol_grad = 1e-08,
  tol_rel_grad = 1e-06,
  tol_obj = 1e-12,
  tol_rel_obj = 1e-08,
  tol_param = 1e-08,
  max_iter = 1000
)
}
\arguments{
\item{g_current}{Current gradient vector (length Q)}

\item{f_current}{Current objective function value (scalar)}

\item{f_previous}{Previous objective function value (scalar), NA for first iteration}

\item{x_current}{Current parameter vector (length Q)}

\item{x_previous}{Previous parameter vector (length Q), NULL for first iteration}

\item{iter}{Current iteration number (0-indexed)}

\item{tol_grad}{Absolute gradient tolerance}

\item{tol_rel_grad}{Relative gradient tolerance}

\item{tol_obj}{Absolute objective change tolerance}

\item{tol_rel_obj}{Relative objective change tolerance}

\item{tol_param}{Parameter change tolerance (infinity norm)}

\item{max_iter}{Maximum iterations allowed}
}
\value{
List with two components:
\item{converged}{Logical; TRUE if any criterion satisfied}
\item{reason}{Character; description of which criterion triggered, or "" if not converged}
}
\description{
Checks multiple convergence criteria following Stan's L-BFGS implementation.
Termination occurs when \strong{any} criterion is satisfied, preventing premature
termination on ill-scaled problems while ensuring robust detection.
}
\details{
The function checks 6 convergence criteria in order:
\enumerate{
\item \strong{max_iter}: Iteration limit reached
\item \strong{gradient_abs}: max(abs(g)) < tol_grad
\item \strong{gradient_rel}: max(abs(g)) < tol_rel_grad * max(1, abs(f))
\item \strong{objective_abs}: abs(f_current - f_previous) < tol_obj
\item \strong{objective_rel}: abs(f_current - f_previous) < tol_rel_obj * max(1, abs(f_current))
\item \strong{parameter}: max(abs(x_current - x_previous)) < tol_param
}
}
\keyword{internal}
