TMB Documentation  v1.9.1
atomic Namespace Reference

Namespace with special functions and derivatives. More...

## Classes

struct  AtomicGlobal
For backwards compatibility with CppAD. More...

struct  AtomicLocal
User interface to checkpointing using TMBad. More...

## Functions

template<class Type >
CppAD::vector< Type > bessel_i_10 (CppAD::vector< Type > x)
Atomic version of $$besselI(x,\nu)$$. Valid parameter range: $$x =(x,\nu) \in \mathbb{R}_+\times\mathbb{R}$$. More...

template<class Type >
CppAD::vector< Type > bessel_k_10 (CppAD::vector< Type > x)
Atomic version of $$besselK(x,\nu)$$. Valid parameter range: $$x =(x,\nu) \in \mathbb{R}_+\times\mathbb{R}$$. More...

template<class Type >
CppAD::vector< Type > D_incpl_gamma_shape (CppAD::vector< Type > x)
Atomic version of scaled incomplete gamma function differentiated to any order wrt. shape parameter

$\exp(c) \int_0^{y} \exp(-t) t^{\lambda-1} \log(t)^n \:dt$

where the 4 input parameters are passed as a vector $$x=(y,\lambda,n,c)$$. Note that the normalized incomplete gamma function is obtained as the special case $$n=0$$ and $$c=-\log \Gamma(\lambda)$$. Valid parameter range: $$x \in \mathbb{R}_+\times\mathbb{R}_+\times\mathbb{N}_0\times\mathbb{R}$$. More...

template<class Type >
CppAD::vector< Type > D_lgamma (CppAD::vector< Type > x)
Atomic version of the n'th order derivative of the log gamma function.

$\frac{d^n}{d\lambda^n}\log \Gamma(\lambda)$

where the 2 input parameters are passed as a vector $$x=(\lambda,n)$$. The special case $$n=0$$ gives the log gamma function. More...

template<class Type >
matrix< Type > expm (matrix< Type > x)
Matrix exponential. More...

template<class Type >
CppAD::vector< Type > inv_incpl_gamma (CppAD::vector< Type > x)
Atomic version of inverse of scaled incomplete gamma function. Given $$z$$ find $$y$$ such that

$z = \exp(c) \int_0^{y} \exp(-t) t^{\lambda-1} \:dt$

where the 3 input parameters are passed as a vector $$x=(z,\lambda,c)$$. The special case $$c=-\log \Gamma(\lambda)$$ gives the inverse normalized incomplete gamma function. Valid parameter range: $$x \in \mathbb{R}_+\times\mathbb{R}_+\times\mathbb{R}$$. More...

template<class Type >
CppAD::vector< Type > invpd (CppAD::vector< Type > x)
Atomic version of log determinant and inverse of positive definite n-by-n matrix. Calculated by Cholesky decomposition. More...

template<class Type >
CppAD::vector< Type > logdet (CppAD::vector< Type > x)
Atomic version of log determinant of positive definite n-by-n matrix. More...

template<class Type >
Type logdet (matrix< Type > x)
Log-determinant of positive definite matrix.

template<class Type >
CppAD::vector< Type > matinv (CppAD::vector< Type > x)
Atomic version of matrix inversion. Inverts n-by-n matrix by LU-decomposition. More...

template<class Type >
matrix< Type > matinv (matrix< Type > x)
Matrix inverse. More...

template<class Type >
matrix< Type > matinvpd (matrix< Type > x, Type &logdet)
Matrix inverse and determinant. More...

template<class Type >
CppAD::vector< Type > matmul (CppAD::vector< Type > x)
Atomic version of matrix multiply. Multiplies n1-by-n2 matrix with n2-by-n3 matrix. More...

template<class Type >
matrix< Type > matmul (matrix< Type > x, matrix< Type > y)
Matrix multiply. More...

template<class Type >
CppAD::vector< Type > pnorm1 (CppAD::vector< Type > x)
Atomic version of standard normal distribution function. Derivative is known to be 'dnorm1'. More...

template<class Type >
CppAD::vector< Type > ppois (CppAD::vector< Type > x)
Atomic version of poisson cdf $$ppois(n,\lambda)$$. Valid parameter range: $$x =(n,\lambda) \in \mathbb{N}_0\times\mathbb{R}_+$$. More...

template<class Type >
CppAD::vector< Type > qnorm1 (CppAD::vector< Type > x)
Atomic version of standard normal quantile function. Derivative is expressed through 'dnorm1'. More...

## Detailed Description

Namespace with special functions and derivatives.

This namespace extends the 'derivatives table' of CppAD.

• R's special math library is extended with derivatives in cases where symbolic derivatives are available. These special functions are often iterative and therefore difficult to implement with AD types. Instead, we code the derivatives based on the double versions available from R. This approach requires fewer code lines, and has the benefit of obtaining the same high accuracy as R's math functions.
• Some matrix operations are extended with derivatives. This greatly reduces the AD memory usage. Furthermore, these atomic operations can be linked to a performance library by setting preprocesor flag EIGEN_USE_BLAS.
• New symbols can be added by advanced users. First option is to code the reverse mode derivatives by hand using the TMB_ATOMIC_VECTOR_FUNCTION macro, see source code for examples. Second option is to generate reverse mode derivatives automatically using the macro REGISTER_ATOMIC.

## § bessel_i_10()

template<class Type >
 CppAD::vector atomic::bessel_i_10 ( CppAD::vector< Type > x )

Atomic version of $$besselI(x,\nu)$$. Valid parameter range: $$x =(x,\nu) \in \mathbb{R}_+\times\mathbb{R}$$.

Note
This atomic function does not handle the derivative wrt. $$\nu$$.
Parameters
 x Input vector of length 2.
Returns
Vector of length 1.

## § bessel_k_10()

template<class Type >
 CppAD::vector atomic::bessel_k_10 ( CppAD::vector< Type > x )

Atomic version of $$besselK(x,\nu)$$. Valid parameter range: $$x =(x,\nu) \in \mathbb{R}_+\times\mathbb{R}$$.

Note
This atomic function does not handle the derivative wrt. $$\nu$$.
Parameters
 x Input vector of length 2.
Returns
Vector of length 1.

## § D_incpl_gamma_shape()

template<class Type >
 CppAD::vector atomic::D_incpl_gamma_shape ( CppAD::vector< Type > x )

Atomic version of scaled incomplete gamma function differentiated to any order wrt. shape parameter

$\exp(c) \int_0^{y} \exp(-t) t^{\lambda-1} \log(t)^n \:dt$

where the 4 input parameters are passed as a vector $$x=(y,\lambda,n,c)$$. Note that the normalized incomplete gamma function is obtained as the special case $$n=0$$ and $$c=-\log \Gamma(\lambda)$$. Valid parameter range: $$x \in \mathbb{R}_+\times\mathbb{R}_+\times\mathbb{N}_0\times\mathbb{R}$$.

Warning
No check is performed on parameters
Parameters
 x Input vector of length 4.
Returns
Vector of length 1.

## § D_lgamma()

template<class Type >
 CppAD::vector atomic::D_lgamma ( CppAD::vector< Type > x )

Atomic version of the n'th order derivative of the log gamma function.

$\frac{d^n}{d\lambda^n}\log \Gamma(\lambda)$

where the 2 input parameters are passed as a vector $$x=(\lambda,n)$$. The special case $$n=0$$ gives the log gamma function.

Parameters
 x Input vector of length 2.
Returns
Vector of length 1.

## § inv_incpl_gamma()

template<class Type >
 CppAD::vector atomic::inv_incpl_gamma ( CppAD::vector< Type > x )

Atomic version of inverse of scaled incomplete gamma function. Given $$z$$ find $$y$$ such that

$z = \exp(c) \int_0^{y} \exp(-t) t^{\lambda-1} \:dt$

where the 3 input parameters are passed as a vector $$x=(z,\lambda,c)$$. The special case $$c=-\log \Gamma(\lambda)$$ gives the inverse normalized incomplete gamma function. Valid parameter range: $$x \in \mathbb{R}_+\times\mathbb{R}_+\times\mathbb{R}$$.

Warning
No check is performed on parameters
Parameters
 x Input vector of length 3.
Returns
Vector of length 1.

## § invpd()

template<class Type >
 CppAD::vector atomic::invpd ( CppAD::vector< Type > x )

Atomic version of log determinant and inverse of positive definite n-by-n matrix. Calculated by Cholesky decomposition.

Parameters
 x Input vector of length n*n.
Returns
Vector of length 1+n*n.

## § logdet()

template<class Type >
 CppAD::vector atomic::logdet ( CppAD::vector< Type > x )

Atomic version of log determinant of positive definite n-by-n matrix.

Parameters
 x Input vector of length n*n.
Returns
Vector of length 1.
Examples:
laplace.cpp.

## § matinv()

template<class Type >
 CppAD::vector atomic::matinv ( CppAD::vector< Type > x )

Atomic version of matrix inversion. Inverts n-by-n matrix by LU-decomposition.

Parameters
 x Input vector of length n*n.
Returns
Vector of length n*n.
Examples:
laplace.cpp.

Referenced by newton::jacobian_sparse_plus_lowrank_t< dummy >::llt_solve(), and matinv().

## § matmul()

template<class Type >
 CppAD::vector atomic::matmul ( CppAD::vector< Type > x )

Atomic version of matrix multiply. Multiplies n1-by-n2 matrix with n2-by-n3 matrix.

Parameters
 x Input vector of length 2+n1*n2+n2*n3 containing the output dimension (length=2), the first matrix (length=n1*n2) and the second matrix (length=n2*n3).
Returns
Vector of length n1*n3 containing result of matrix multiplication.

Referenced by newton::jacobian_sparse_plus_lowrank_t< dummy >::llt_solve(), and matmul().

## § pnorm1()

template<class Type >
 CppAD::vector atomic::pnorm1 ( CppAD::vector< Type > x )

Atomic version of standard normal distribution function. Derivative is known to be 'dnorm1'.

Parameters
 x Input vector of length 1.
Returns
Vector of length 1.

## § ppois()

template<class Type >
 CppAD::vector atomic::ppois ( CppAD::vector< Type > x )

Atomic version of poisson cdf $$ppois(n,\lambda)$$. Valid parameter range: $$x =(n,\lambda) \in \mathbb{N}_0\times\mathbb{R}_+$$.

Warning
No check is performed on parameters
Parameters
 x Input vector of length 2.
Returns
Vector of length 1.

## § qnorm1()

template<class Type >
 CppAD::vector atomic::qnorm1 ( CppAD::vector< Type > x )

Atomic version of standard normal quantile function. Derivative is expressed through 'dnorm1'.

Parameters
 x Input vector of length 1.
Returns
Vector of length 1.
License: GPL v2