Question on using C++ 11 language and matrix inversions in TMB

146 views
Skip to first unread message

Craig Marsh

unread,
Aug 28, 2018, 10:53:07 PM8/28/18
to TMB Users
Hi there I have 2 questions to the group, 

Firstly
- is C++ 11 compilation flag allowed? I was getting errors saying 

I get two warnings/errors that I think suggest we don't

"'auto' changes meaning in C++11; please remove it"

"range-based 'for' loops are not allowed in C++98 mode"

that was for a loop structured as

for(auto& val : vector_of_values

Secondly

I am doing inversions and determinants of large-ish matricies, the code I am bringing across used the eigen library like below,
Determinant
  PartialPivLU<Matrix<double,Dynamic,Dynamic>> lu(M);
  auto& LU = lu.matrixLU();
  double c = lu.permutationP().determinant(); // -1 or 1

and for the inversion

  V_invert = Vmat.llt().solve(MatrixXd::Identity(N_bins - 1, N_bins - 1));

I went down that road because in the eigen information it says "If your matrix is of a very small fixed size (at most 4x4) this allows Eigen to avoid performing a LU decomposition, and instead use formulas that are more efficient on such small matrices." 
Which I took as if your matrix is bigger than 4x4 don't use the matrix.inverse() or matrix.determinant() and use the decomposition methods.

So my question is what is the most efficient/fastest method to calculate inverses and determinants of matrices larger than 4x4 <Type> in TMB?

Cheers,
Craig

Craig Marsh

unread,
Aug 30, 2018, 11:58:19 PM8/30/18
to TMB Users
I have come across some TMB inversion code and general code to incorporate the eigen functionality you just have to incorporate the namespace Eigen:: if any one is interested.

  Eigen::LLT< Matrix<Type, Eigen::Dynamic, Eigen::Dynamic> > lltCovMAT(mat);
  matrix<Type> LN = lltCovMAT.matrixL();
  matrix<Type> LinvN = LN.inverse();

Hopefully that might be useful to some newbies like myself.

Maia Sosa Kapur

unread,
Oct 28, 2020, 6:31:55 PM10/28/20
to TMB Users
This is an old thread, but I'm curious about using the inverse() syntax here. To clarify, what is the value mat  in lltCovMAT(mat) ?
Reply all
Reply to author
Forward
0 new messages