TMB Documentation  v1.9.11
Classes | Functions
tmbutils Namespace Reference

Utility functions for TMB (automatically included) More...

Classes

struct  array
 Array class used by TMB. More...
 
struct  Concat
 Serialized representation of objects of different types. More...
 
struct  interpol2D
 Get a smooth representation of a data matrix. More...
 
struct  interpol2D_config
 Configuration for Interpol2D More...
 
struct  matexp
 Matrix exponential: matrix of arbitrary dimension. More...
 
struct  matexp< scalartype, 2 >
 Matrix exponential: 2x2 case which can be handled efficiently. More...
 
struct  matrix
 Matrix class used by TMB. More...
 
class  order
 Taped sorting of a vector. More...
 
class  splinefun
 Spline Interpolation. More...
 
struct  vector
 Vector class used by TMB. More...
 

Functions

template<class Type >
Eigen::SparseMatrix< Type > asSparseMatrix (SEXP M)
 
template<class Type >
Eigen::SparseMatrix< Type > asSparseMatrix (matrix< Type > x)
 Create sparse matrix from dense matrix. More...
 
template<class Type >
Eigen::SparseVector< Type > asSparseVector (vector< Type > x)
 Create sparse vector from dense vector. More...
 
template<class... Ts>
Concat< Ts... > concat (Ts &... args)
 Serialized representation of objects of different types. More...
 
template<class Type >
matrix< Type > discrLyap (matrix< Type > A_)
 
template<class Type >
matrix< Type > invertSparseMatrix (Eigen::SparseMatrix< Type > A)
 
template<class Type >
bool isStructuralZero (Type x)
 Test if a scalar is a structural zero. More...
 
template<class scalartype , int n1, int n2, int n3, int n4>
Matrix< scalartype, n1 *n3, n2 *n4 > kronecker (Matrix< scalartype, n1, n2 > x, Matrix< scalartype, n3, n4 > y)
 Kronecker product of two matrices.
 
template<class scalartype >
matrix< scalartype > kronecker (matrix< scalartype > x, matrix< scalartype > y)
 Kronecker product of two matrices.
 
template<class Type >
Eigen::SparseMatrix< Type > kronecker (Eigen::SparseMatrix< Type > x, Eigen::SparseMatrix< Type > y)
 

Detailed Description

Utility functions for TMB (automatically included)

Contains basic data types such as vectors, matrices and arrays. Included automatically so you should NOT include it via

using tmbutils

Function Documentation

§ asSparseMatrix() [1/2]

template<class Type >
Eigen::SparseMatrix<Type> tmbutils::asSparseMatrix ( SEXP  M)

Create sparse matrix from R-triplet sparse matrix

Definition at line 12 of file spmat.hpp.

§ asSparseMatrix() [2/2]

template<class Type >
Eigen::SparseMatrix<Type> tmbutils::asSparseMatrix ( matrix< Type >  x)

Create sparse matrix from dense matrix.

This function converts a dense matrix to a sparse matrix based on its numerical values.

Note
Zeros are detected using isStructuralZero() ensuring that entries which might become non-zero for certain parameter settings will not be regarded as zeros.

Definition at line 53 of file spmat.hpp.

§ asSparseVector()

template<class Type >
Eigen::SparseVector<Type> tmbutils::asSparseVector ( vector< Type >  x)

Create sparse vector from dense vector.

This function converts a dense vector to a sparse vector based on its numerical values.

Note
Zeros are detected using isStructuralZero() ensuring that entries which might become non-zero for certain parameter settings will not be regarded as zeros.

Definition at line 76 of file spmat.hpp.

§ concat()

template<class... Ts>
Concat<Ts...> tmbutils::concat ( Ts &...  args)

Serialized representation of objects of different types.

This function provides an interface between a parameter list and its serialized (vector) representation. In R, this would correspond to 'unlist()/relist()'.

Example:

// Custom parameter list
template<class Type>
struct parameter_list {
Type s;
// To enable unlist/relist functionality, we must specify which members to include in representation:
auto unlist() { return concat(v, m, a, s); }
};
// Declare a parameter list
parameter_list<Type> pl;
// To 'unlist' it do
vector<Type> parms = pl.unlist();
// To 'relist' it do
pl.unlist() = parms;
Note
Return type 'auto' requires C++14.

Definition at line 95 of file concat.hpp.

§ discrLyap()

template<class Type >
matrix<Type> tmbutils::discrLyap ( matrix< Type >  A_)

Solve discrete Lyapunov equation V=AVA'+I

Definition at line 115 of file spmat.hpp.

§ invertSparseMatrix()

template<class Type >
matrix<Type> tmbutils::invertSparseMatrix ( Eigen::SparseMatrix< Type >  A)

Inverse of PD sparse matrix

Definition at line 140 of file spmat.hpp.

§ isStructuralZero()

template<class Type >
bool tmbutils::isStructuralZero ( Type  x)

Test if a scalar is a structural zero.

A structural zero is a scalar taking the value zero for all configurations of the model parameters. If the return value is true the input is guarantied to be a structural zero.

Note
Nothing can be deduced if the return value is false. For instance complex structural zeros such as \(1-sin(x)^2-cos(x)^2\) won't be detected.

Definition at line 39 of file spmat.hpp.

Referenced by asSparseMatrix(), and asSparseVector().

§ kronecker()

template<class Type >
Eigen::SparseMatrix<Type> tmbutils::kronecker ( Eigen::SparseMatrix< Type >  x,
Eigen::SparseMatrix< Type >  y 
)

Kronecker product of two sparse matrices

Definition at line 88 of file spmat.hpp.

License: GPL v2