ADmatrix: AD matrix methods (sparse and dense) In RTMB: 'R' Bindings for 'TMB'

AD matrix methods (sparse and dense)

Description

Matrices (base package) and sparse matrices (Matrix package) can be used inside the `RTMB` objective function as part of the calculations. Behind the scenes these R objects are converted to AD representations when needed. AD objects have a temporary lifetime, so you probably won't see them / need to know them. The only important thing is which methods work for the objects.

Usage

``````## S3 method for class 'adsparse'
t(x)

## S3 method for class 'adsparse'
x[...]

## S3 replacement method for class 'adsparse'
x[...] <- value

## S4 method for signature 'adsparse,missing,missing'
diag(x)

## S4 method for signature 'advector'
expm(x)

## S4 method for signature 'adsparse'
expm(x)

## S4 method for signature 'adsparse'
dim(x)

## S4 method for signature 'anysparse,ad'
x %*% y

## S4 method for signature 'ad,anysparse'
x %*% y

x %*% y

x %*% y

## S4 method for signature 'advector,ANY'
tcrossprod(x, y = NULL)

## S4 method for signature 'advector,ANY'
crossprod(x, y = NULL)

## S4 method for signature 'advector'
cov2cor(V)

solve(a, b)

## S4 method for signature 'num,num.'
solve(a, b)

## S4 method for signature 'anysparse,ad.'
solve(a, b)

## S4 method for signature 'advector'
colSums(x)

## S4 method for signature 'advector'
rowSums(x)

## S3 method for class 'advector'
cbind(...)

## S3 method for class 'advector'
rbind(...)
``````

Arguments

 `x` matrix (sparse or dense) `...` As cbind `value` Replacement value `y` matrix (sparse or dense) `V` Covariance matrix `a` matrix `b` matrix, vector or missing

Value

Object of class `advector` with a dimension attribute for dense matrix operations; Object of class `adsparse` for sparse matrix operations.

Functions

• `t(adsparse)`: AD sparse matrix transpose. Re-directs to t,CsparseMatrix-method.

• `[`: AD sparse matrix subsetting. Re-directs to [-methods.

• ``[`(adsparse) <- value`: AD sparse matrix subset assignment. Re-directs to [<â€“methods.

• `diag(x = adsparse, nrow = missing, ncol = missing)`: AD sparse matrix diagonal extract. Re-directs to diag,CsparseMatrix-method.

• `expm(advector)`: AD matrix exponential

• `expm(adsparse)`: AD matrix exponential

• `dim(adsparse)`: AD sparse matrix dimension

• `x %*% y`: AD matrix multiply

• `x %*% y`: AD matrix multiply

• `x %*% y`: AD matrix multiply

• `x %*% y`: AD matrix multiply

• `tcrossprod(x = advector, y = ANY)`: AD matrix multiply

• `crossprod(x = advector, y = ANY)`: AD matrix multiply

• `cov2cor(advector)`: AD matrix cov2cor

• `solve(a = ad, b = ad.)`: AD matrix inversion and solve

• `solve(a = num, b = num.)`: AD matrix inversion and solve

• `solve(a = anysparse, b = ad.)`: Sparse AD matrix solve (not yet implemented)

• `colSums(advector)`: AD matrix (or array) colsums

• `rowSums(advector)`: AD matrix (or array) rowsums

• `cbind(advector)`: AD matrix column bind

• `rbind(advector)`: AD matrix row bind

Examples

``````F <- MakeTape(function(x) matrix(1:9,3,3) %*% x, numeric(3))
F\$jacobian(1:3)
F <- MakeTape(function(x) Matrix::expm(matrix(x,2,2)), numeric(4))
F\$jacobian(1:4)
``````

RTMB documentation built on May 29, 2024, 8:45 a.m.