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 |
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
-
tapeJacobian
: Tape the Jacobian of a tape. The resulting tape returns the Jacobian as a vector. -
tapeHessian
: Tape the Hessian of a tape. The resulting tape returns the Jacobian as a vector (see https://cppad.readthedocs.io/latest/Hessian.html). -
tapeGradOffset
: A quadratic function can be written asf(x;\theta) = \frac{1}{2} x^T W(\theta) x + b(\theta)^Tx + c.
The function
tapeGradOffset
creates a tape ofb(\theta)
where\theta
is the independent variable. -
tapeLogJacDet
: Creates a tape of the log of the Jacobian determinant of a function taped intape
. The dimensions of the domain (length of independent variable) and range (length of output variable) oftape
must be equal for computation of the determinant. -
tapeSwap
: Convert an ADFun so that the independent variables become dynamic parameters and the dynamic parameters become independent variables.
See Also
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)