approx_grad: Finite-difference Gradient Computer

View source: R/HelperFunctions.R

approx_gradR Documentation

Finite-difference Gradient Computer

Description

Computes a finite-difference approximation derived from the objective in fn at x, returned in the sign convention currently used by efficient_bfgs.

Usage

approx_grad(x, fn, eps = sqrt(.Machine$double.eps))

Arguments

x

Numeric vector of function arguments

fn

Function returning list(objective, gradient)

eps

Numeric scalar, finite difference tolerance

Details

Used within efficient_bfgs when fn does not supply a usable gradient. In the main lgspline() correlation-optimization path, stats::optim() is used instead when no analytic REML gradient is available. Internally this helper returns the negated central-difference approximation rather than the raw derivative.

Value

Numeric vector of finite-difference approximated gradient values in the current optimizer sign convention


lgspline documentation built on May 8, 2026, 5:07 p.m.