Tape the Gradient Offset of a Quadratic CppAD Tape
tape_gradoffset(pfun)
An Rcpp_ADFun
object. The independent argument to the function are the dynamic parameters of pfun
.
An Rcpp_ADFun
object.
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.
Other tape builders:
tape_Hessian()
,
tape_Jacobian()
,
tape_logJacdet()
,
tape_smd()
,
tape_swap()
,
tape_uld()