moretapebuilders {scorematchingad}R Documentation

Build New Tapes from Existing Tapes

Description

Build new tapes (i.e ADFun objects) from existing tapes, including differentiation, swapping independent variables and dynamic parameters, and Jacobian determinants.

Usage

tapeJacobian(tape)

tapeHessian(tape)

tapeGradOffset(tape)

tapeLogJacDet(tape)

tapeSwap(tape)

Arguments

tape

An ADFun object.

Details

The information in the fields xtape and dyntape of tape are used to perform the taping.

tapeJacobian

The returned vector is ordered with the range elements iterating fastest, then the domain elements. See https://cppad.readthedocs.io/latest/Jacobian.html.

tapeHessian

Suppose the function represented by tape maps from d-dimensional space to 1-dimensional space, then the first d elements of the vector is the gradient of the partial derivative with respect to the first dimension of the function's domain. The next d elements of the vector is the gradient of the partial derivative of the second dimension of the function's domain. The Hessian as a matrix, can be obtained by using matrix() with ncol = d.

tapeGradOffset

A quadratic function can be written as

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

where the vector x is the independent variable of tape and the vector \theta is the dynamic parameter vector of tape. 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.

Value

An ADFun object.

Functions

See Also

ADFun

Other tape builders: buildsmdtape()

Examples

tapes <- buildsmdtape("sph", "identity", "sph", "vMF",
              ytape = rep(1, 3)/sqrt(3),
              usertheta = rep(NA, 3)
              ) 
tapeJacobian(tapes$smdtape)
tapeHessian(tapes$smdtape)
tapeLogJacDet(tapeJacobian(tapes$smdtape))
tapeSwap(tapes$smdtape)

[Package scorematchingad version 0.0.67 Index]