tape_gradoffset: Tape the Gradient Offset of a Quadratic CppAD Tape

View source: R/RcppExports.R

tape_gradoffsetR Documentation

Tape the Gradient Offset of a Quadratic CppAD Tape

Description

Tape the Gradient Offset of a Quadratic CppAD Tape

Usage

tape_gradoffset(pfun)

Arguments

pfun

An Rcpp_ADFun object.

Details

A quadratic function can be written as

f(x;\theta) = \frac{1}{2} x^T W(\theta) x + b(\theta)^Tx + c.

The gradient of f(x; \theta) with respect to x is

\Delta f(x; \theta) = \frac{1}{2}(W(\theta) + W(\theta)^T)x + b(\theta).

The Hessian is

H f(x; \theta) = \frac{1}{2}(W(\theta) + W(\theta)^T),

which does not depend on x, so the gradient of the function can be rewritten as

\Delta f(x;\theta) = H f(x; \theta) x + b(\theta)^T.

The tape calculates b(\theta) as

b(\theta) = \Delta f(x;\theta) - H f(x; \theta) x,

which does not depend on x.

For creating this tape, the values of pfun$xtape and pfun$dyntape are used.

Value

An Rcpp_ADFun object. The independent argument to the function are the dynamic parameters of pfun.

See Also

Other tape builders: tape_Hessian(), tape_Jacobian(), tape_logJacdet(), tape_smd(), tape_swap(), tape_uld()


scorematchingad documentation built on April 4, 2025, 12:15 a.m.