Tape {RTMB}R Documentation

The AD tape

Description

The AD tape as an R function

Usage

MakeTape(f, x)

## S3 method for class 'Tape'
x$name

## S3 method for class 'Tape'
print(x, ...)

TapeConfig(
  comparison = c("NA", "forbid", "tape", "allow"),
  atomic = c("NA", "enable", "disable"),
  vectorize = c("NA", "disable", "enable")
)

DataEval(f, x)

GetTape(obj, name = c("ADFun", "ADGrad", "ADHess"), warn = TRUE)

Arguments

f

R function

x

numeric vector

name

Name of a tape method

...

Ignored

comparison

Set behaviour of AD comparison (">","==", etc).

atomic

Set behaviour of AD BLAS operations (notably matrix multiply).

vectorize

Enable/disable AD vectorized 'Ops' and 'Math'.

obj

Output from MakeADFun

warn

Give warning if obj was created using another DLL?

Details

A 'Tape' is a representation of a function that accepts fixed size numeric input and returns fixed size numeric output. The tape can be constructed using F <- MakeTape(f, x) where f is a standard differentiable R function (or more precisely: One using only functions that are documented to work for AD types). Having constructed a tape F, a number of methods are available:

Evaluation:

Transformation:

Modification:

Extract tape information:

Value

Object of class "Tape".

Methods (by generic)

Functions

Examples

F <- MakeTape(prod, numeric(3))
show(F)
F$print()
H <- F$jacfun()$jacfun() ## Hessian tape
show(H)
#### Handy way to plot the graph of F
if (requireNamespace("igraph")) {
   G <- igraph::graph_from_adjacency_matrix(F$graph())
   plot(G, vertex.size=17, layout=igraph::layout_as_tree)
}
## Taped access of an element of 'rivers' dataset
F <- MakeTape(function(i) DataEval( function(i) rivers[i] , i), 1 )
F(1)
F(2)

[Package RTMB version 1.5 Index]