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 -dimensional space to
-dimensional space, then
the first
elements of the vector is the gradient of the partial derivative with respect to the first dimension of the function's domain.
The next
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
where the vector is the independent variable of
tape
and the vector is the dynamic parameter vector of
tape
.
The gradient of with respect to
is
The Hessian is
which does not depend on ,
so the gradient of the function can be rewritten as
The tape calculates as
which does not depend on .
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 asThe function
tapeGradOffset
creates a tape ofwhere
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)