R/helpers_convergence.R

Defines functions checkConvergence

Documented in checkConvergence

#' ELBO Convergence Check helper method
#'
#' @description
#' Returns \code{TRUE} when the absolute ELBO change between consecutive
#' iterations falls below \code{convergence_threshold}. Returns \code{FALSE}
#' if either ELBO value is \code{NULL} or \code{NA}.
#'
#' @param elbo_c Numeric scalar. ELBO at the current iteration.
#' @param elbo_prev Numeric scalar. ELBO at the previous iteration.
#' @param convergence_threshold Positive scalar. Tolerance for convergence.
#'
#' @return Logical scalar.
#' @keywords internal


checkConvergence <- function(elbo_c, elbo_prev, convergence_threshold) {
  if (is.null(elbo_prev) || is.na(elbo_prev)) return(FALSE)
  if (is.null(elbo_c)    || is.na(elbo_c))    return(FALSE)

  abs(elbo_c - elbo_prev) <= convergence_threshold
}

Try the fda.vi package in your browser

Any scripts or data that you put into this service are public.

fda.vi documentation built on June 20, 2026, 5:06 p.m.