17 #define TYPEDEFS(scalartype_)                   \    19 typedef scalartype_ scalartype;                 \    20 typedef vector<scalartype> vectortype;          \    21 typedef matrix<scalartype> matrixtype;          \    22 typedef array<scalartype> arraytype    24 #define VARIANCE_NOT_YET_IMPLEMENTED            \    26 vectortype variance(){return vectortype();}     \    54 #define SIMULATE_NOT_YET_IMPLEMENTED            \    56 vectortype sqrt_cov_scale(vectortype x){}       \    57 void simulate(vectortype &u){}                  \    58 vectortype simulate(){}                         \    62 #define SIMULATE_IMPLEMENTED_UNKNOWN_SIZE       \    63 void simulate(vectortype &x) {                  \    65   x = sqrt_cov_scale(x);                        \    66   x = zero_derivatives(x);                      \    69 #define SIMULATE_IMPLEMENTED_KNOWN_SIZE(SIZE)   \    70 SIMULATE_IMPLEMENTED_UNKNOWN_SIZE               \    71 vectortype simulate() {                         \    81 template<
class arraytype>
    82 arraytype zero_derivatives(arraytype x) {
    83   for(
int i=0; i<x.size(); i++)
    84     x(i) = asDouble(x(i));
    89 template<
class arraytype>
    90 void rnorm_fill(arraytype &x) {
    91   for(
int i=0; i<x.size(); i++)
    92     x(i) = Rf_rnorm(0., 1.);
   111 template <
class scalartype_>
   113   TYPEDEFS(scalartype_);
   120   MVNORM_t(matrixtype Sigma_, 
bool use_atomic=
true){
   121     setSigma(Sigma_, use_atomic);
   134   matrixtype 
cov(){
return Sigma;}
   137   void setSigma(matrixtype Sigma_, 
bool use_atomic=
true){
   143       matrixtype I(Sigma.rows(),Sigma.cols());
   145       Eigen::LDLT<Eigen::Matrix<scalartype,Dynamic,Dynamic> > ldlt(Sigma);
   147       vectortype D = ldlt.vectorD();
   148       logdetS = D.log().sum();
   152   scalartype Quadform(vectortype x){
   153     return (x*(vectortype(Q*x))).sum();
   157     return -scalartype(.5)*logdetQ + scalartype(.5)*Quadform(x) + x.size()*scalartype(log(sqrt(2.0*M_PI)));
   165     for(
int i = 0; i < S.rows(); i++){
   166       for(
int j = 0; j < S.cols(); j++){
   167         S(i,j) = S(i,j) * keep(i) * keep(j);
   169       S(i,i) += not_keep(i) * scalartype(1.0 / (2.0 * M_PI));
   175     matrixtype m(x.size()/x.cols(),x.cols());
   176     for(
int i=0;i<x.size();i++)m(i)=x[i];
   178     for(
int i=0;i<x.size();i++)y[i]=mQ(i);
   181   int ndim(){
return 1;}
   182   VARIANCE_NOT_YET_IMPLEMENTED
   183   vectortype sqrt_cov_scale(vectortype u) {
   184     if(L_Sigma.rows() == 0) {
   185       Eigen::LLT<Eigen::Matrix<scalartype,Dynamic,Dynamic> > llt(Sigma);
   186       L_Sigma = llt.matrixL();
   188     vectortype ans = L_Sigma * u;
   191   SIMULATE_IMPLEMENTED_KNOWN_SIZE(Sigma.rows());
   207 template <
class scalartype>
   259 template <
class scalartype_>
   261   TYPEDEFS(scalartype_);
   266     int n=int((1.0+sqrt(1.0+8*nx))/2.0);
   267     if((n*n-n)/2!=nx)std::cout << 
"vector does not specify an UNSTRUCTERED_CORR\n";
   271     for(i=0;i<L.rows();i++){
   272       for(j=0;j<L.cols();j++){
   273         if(i>j){L(i,j)=x[k];k++;}
   276     matrixtype llt=L*L.transpose();
   277     matrixtype Sigma=llt;
   278     for(i=0;i<Sigma.rows();i++){
   279       for(j=0;j<Sigma.cols();j++){
   280         Sigma(i,j)/=sqrt(llt(i,i)*llt(j,j));
   283     this->setSigma(Sigma); 
   288 template <
class scalartype>
   301 template<
class scalartype_> 
   303   TYPEDEFS(scalartype_);
   307     return x*x*.5 + log(sqrt(2.0*M_PI));
   309   scalartype operator()(vectortype x){
   310     return (x*x*scalartype(.5) + scalartype(log(sqrt(2.0*M_PI))) ).sum() ;
   312   scalartype operator()(arraytype x){
   313     return (x*x*scalartype(.5) + scalartype(log(sqrt(2.0*M_PI))) ).sum() ;
   315   arraytype 
jacobian(arraytype x){
return x;}
   316   int ndim(){
return 1;}
   317   VARIANCE_NOT_YET_IMPLEMENTED
   319   vectortype simulate() {
   321     x[0] = 
rnorm(0.0, 1.0);
   325   void simulate(vectortype &x) {
   328   vectortype sqrt_cov_scale(vectortype u) {
   374 template <
class distribution>
   376   TYPEDEFS(
typename distribution::scalartype);
   379   distribution MARGINAL;
   382   AR1_t(scalartype phi_, distribution f_) : phi(phi_), MARGINAL(f_) {}
   389     scalartype sigma=sqrt(scalartype(1)-phi*phi); 
   390     value+=MARGINAL(x(0));                                       
   391     for(
int i=1;i<n;i++)value+=MARGINAL((x(i)-x(i-1)*phi)/sigma);
   392     value+=scalartype((n-1)*m)*log(sigma);
   397   scalartype operator()(arraytype x){
   402     scalartype sigma=sqrt(scalartype(1)-phi*phi); 
   403     value+=MARGINAL(x.col(0));                                  
   404     for(
int i=1;i<n;i++)value+=MARGINAL((x.col(i)-x.col(i-1)*phi)/sigma);
   405     value+=scalartype((n-1)*m)*log(sigma);
   411     scalartype sigma=sqrt(scalartype(1)-phi*phi); 
   415     y.col(0) = y.col(0) + MARGINAL.jacobian(x.col(0));
   416     for(
int i=1;i<n;i++){
   418       y.col(i-1) = y.col(i-1) - (phi/sigma) * MARGINAL.jacobian((x.col(i)-x.col(i-1)*phi)/sigma);
   419       y.col(i) = y.col(i) +  MARGINAL.jacobian((x.col(i)-x.col(i-1)*phi)/sigma)/sigma;
   423   int ndim(){
return 1;}
   424   VARIANCE_NOT_YET_IMPLEMENTED
   427   arraytype sqrt_cov_scale(arraytype u) {
   428     if(u.dim.size() == 1) {
   431       u.dim.resize(2); u.dim << 1, u.size();
   435     scalartype sigma = sqrt(1.0 - phi * phi); 
   436     x.col(0) = MARGINAL.sqrt_cov_scale(u.col(0));
   437     for(
int i=1; i<n; i++)
   438       x.col(i) = phi * x.col(i-1) + sigma * MARGINAL.sqrt_cov_scale(u.col(i));
   441   vectortype sqrt_cov_scale(vectortype u) {
   444     arraytype u_array(u, dim);
   445     return sqrt_cov_scale(u_array);
   450     x = sqrt_cov_scale(x);
   451     x = zero_derivatives(x);
   453   void simulate(arraytype &x) {
   455     x = sqrt_cov_scale(x);
   456     x = zero_derivatives(x);
   460 template <
class scalartype, 
class distribution>
   464 template <
class scalartype>
   494 template <
class scalartype_>
   496   TYPEDEFS(scalartype_);
   512   ARk_t(vectortype phi_){
   515     V0.resize(k,k);Q0.resize(k,k);
   516     M.resize(k,k);I.resize(k,k);
   520     for(
int i=0;i<k;i++){
   521       for(
int j=0;j<k;j++){
   529     gamma=((I-M).inverse())*matrixtype(phi);
   531     sigma=sqrt(scalartype(1)-(phi*gamma).
sum());
   533     for(
int i=0;i<k;i++){
   534       for(
int j=0;j<k;j++){
   537           V0(i,j)=scalartype(1); 
   545     L0=Q0.llt().matrixL(); 
   546     logdetQ0=scalartype(0);
   547     for(
int i=0;i<k;i++)logdetQ0+=scalartype(2)*log(L0(i,i));
   555     for(
int i=0;i<n;i++){
   556       if(i==0){rho(0)=scalartype(1);}
   557       else if(i<=k){rho(i)=gamma(i-1);}
   560         for(
int j=0;j<k;j++)tmp+=phi[j]*rho[i-1-j];
   579     for(
int i=0; (i<k) & (i<x.size()); i++){
   582       for(
int j=col+1; j<k; j++) mu -= L0(j,col) * x(k-1-j);
   584       sd = scalartype(1) / L0(col, col);
   585       value -= 
dnorm(x[i], mu, sd, 
true);
   588     for(
int i=k;i<x.size();i++){
   590       for(
int j=0;j<k;j++){
   591         tmp+=phi[j]*x[i-1-j];
   593       value-=
dnorm(x[i],tmp,sigma,1);
   602         y.col(i)=y.col(i)+Q0(i,j)*x.col(j);
   605     for(
int i=1;i<=k;i++)v[i]=-phi[i-1];
   607     for(
int i=k;i<x.cols();i++){
   608       for(
int j1=0;j1<=k;j1++){
   609         for(
int j2=0;j2<=k;j2++){
   610           y.col(i-j1)=y.col(i-j1)+v[j1]*v[j2]*x.col(i-j2);
   616   int ndim(){
return 1;}
   617   VARIANCE_NOT_YET_IMPLEMENTED
   619   vectortype sqrt_cov_scale(vectortype u){
   620     vectortype x(u.size());
   623     for (
int i = 0; (i < k) & (i < x.size()); i++) {
   626       for (
int j = col + 1; j < k; j++)
   627         mu -= L0(j, col) * x(k - 1 - j);
   629       sd = scalartype(1) / L0(col, col);
   630       x(i) = sd * u(i) + mu;
   633     for (
int i = k; i < x.size(); i++) {
   635       for (
int j = 0; j < k; j++) {
   636         tmp += phi[j] * x[i - 1 - j];
   638       x(i) = sigma * u(i) + tmp;
   642   SIMULATE_IMPLEMENTED_UNKNOWN_SIZE
   645 template <
class scalartype>
   668 template <
class scalartype_>
   670   TYPEDEFS(scalartype_);
   672   typedef Matrix<scalartype,2,2> matrix2x2;
   673   typedef Matrix<scalartype,2,1> matrix2x1;
   674   typedef Matrix<scalartype,4,4> matrix4x4;
   675   typedef Matrix<scalartype,4,1> matrix4x1;
   676   scalartype shape,scale,c0,c1;
   681   matrix4x1 vecSigma,iBvecSigma;
   686   contAR2_t(vectortype grid_, scalartype shape_, scalartype scale_=1){
   687     shape=shape_;scale=scale_;grid=grid_;
   688     c0=scalartype(-1);c1=scalartype(2)*shape_;
   689     c0=c0/(scale*scale); c1=c1/scale;
   690     A << scalartype(0), scalartype(1), c0, c1;
   696     vecSigma << 0,0,0,scalartype(-2)*c1*V0(1,1);
   697     iBvecSigma=iB*vecSigma;
   699     neglogdmvnorm.resize(grid.size());
   703     expAdt.resize(grid.size());
   704     expAdt[0]=expA(scalartype(0));
   705     for(
int i=1;i<grid.size();i++)expAdt[i]=expA(grid(i)-grid(i-1));
   708   matrix4x4 expB(scalartype t){
   712   matrix2x2 V(scalartype t){
   714     tmp=expB(t)*iBvecSigma-iBvecSigma;
   716     for(
int i=0;i<4;i++)ans(i)=tmp(i);
   725     ans = neglogdmvnorm[0](y0);
   726     for(
int i=1;i<grid.size();i++){
   727       y0 << x(i-1), dx(i-1);
   729       ans += neglogdmvnorm[i](y-expAdt[i]*y0);
   737   scalartype operator()(vectortype x){ 
   739     dim << 2 , x.size()/2 ;
   742     return this->operator()(y.
col(0),y.
col(1));
   744   arraytype matmult(matrix2x2 Q,arraytype x){
   746     y.col(0) = Q(0,0)*x.col(0)+Q(0,1)*x.col(1); 
   747     y.col(1) = Q(1,0)*x.col(0)+Q(1,1)*x.col(1);
   753     arraytype tmp(y(0).dim);
   754     y.col(0) = neglogdmvnorm[0].jacobian(x.col(0)); 
   755     for(
int i=1;i<grid.size();i++){
   761       tmp=neglogdmvnorm[i].jacobian( x.col(i) - matmult(expAdt[i],x.col(i-1)) );
   762       y.col(i)=y.col(i)+tmp;
   763       y.col(i-1)=y.col(i-1)-matmult(expAdt[i].transpose(), tmp );
   767   int ndim(){
return 2;} 
   768   VARIANCE_NOT_YET_IMPLEMENTED
   771 template <
class scalartype, 
class vectortype>
   775 template <
class scalartype>
   827 template <
class scalartype_>
   829   TYPEDEFS(scalartype_);
   831   Eigen::SparseMatrix<scalartype> Q;
   833   int sqdist(vectortype x, vectortype x_) {
   836     for(
int i=0; i<x.size(); i++){
   837       tmp = CppAD::Integer(x[i]) - CppAD::Integer(x_[i]);
   844   GMRF_t(Eigen::SparseMatrix<scalartype> Q_, 
int order_=1, 
bool normalize=
true){
   845     setQ(Q_, order_, normalize);
   847   GMRF_t(arraytype x, vectortype delta, 
int order_=1, 
bool normalize=
true){
   849     typedef Eigen::Triplet<scalartype> T;
   850     std::vector<T> tripletList;
   851     for(
int i=0; i<n; i++){
   852       for(
int j=0; j<n; j++){
   853         if (sqdist(x.col(i),x.col(j)) == 1){
   854           tripletList.push_back(T(i, j, scalartype(-1)));
   855           tripletList.push_back(T(i, i, scalartype( 1)));
   859     for(
int i=0; i<n; i++) {
   860       tripletList.push_back(T(i, i, delta[i]));
   862     Eigen::SparseMatrix<scalartype> Q_(n, n);
   863     Q_.setFromTriplets(tripletList.begin(), tripletList.end());
   864     setQ(Q_, order_, normalize);
   866   void setQ(Eigen::SparseMatrix<scalartype> Q_, 
int order=1, 
bool normalize=
true){
   869 #ifndef TMBAD_FRAMEWORK   870       Eigen::SimplicialLDLT< Eigen::SparseMatrix<scalartype> > ldl(Q);
   871       vectortype D = ldl.vectorD();
   872       logdetQ = (log(D)).
sum();
   874       logdetQ = newton::log_determinant(Q);
   880     for(
int i=1; i<
order; i++){
   883     logdetQ = scalartype(order) * logdetQ;
   886   scalartype Quadform(vectortype x){
   887     return (x * (Q * x.matrix()).
array()).
sum();
   889   scalartype operator()(vectortype x){
   890     return -scalartype(.5) * logdetQ + scalartype(.5) * Quadform(x) + x.size() * scalartype(log(sqrt(2.0 * M_PI)));
   895     matrixtype m(x.size()/x.cols(),x.cols());
   896     for(
int i=0; i<x.size(); i++) m(i) = x[i];
   897     matrixtype mQ = m * Q;
   898     for(
int i=0; i<x.size(); i++) y[i] = mQ(i);
   901   int ndim() { 
return 1; }
   902   vectortype variance() {
   906     for(
int i=0; i<n; i++) ans[i] = C(i,i);
   910   Eigen::SparseMatrix<scalartype> L;
   911   Eigen::PermutationMatrix<Dynamic,Dynamic> Pinv;
   912   vectortype sqrt_cov_scale(vectortype u) {
   914       Eigen::SimplicialLLT<Eigen::SparseMatrix<scalartype> > solver(Q);
   915       L = solver.matrixL();
   916       Pinv = solver.permutationPinv();
   919     matrixtype x = L.transpose().template triangularView<Eigen::Upper>().solve(u.matrix());
   923   SIMULATE_IMPLEMENTED_KNOWN_SIZE(Q.rows())
   933 template <
class scalartype>
   937 template <
class scalartype, 
class arraytype >
   941 template <
class scalartype, 
class arraytype >
   944   for(
int i=0; i<d.size(); i++) d[i] = delta;
   947 template <
class scalartype>
   959 template <
class distribution>
   961   TYPEDEFS(
typename distribution::scalartype);
   967   SCALE_t(distribution f_, scalartype scale_){scale=scale_;f=f_;}
   970     scalartype ans=f(x/scale);
   971     ans+=x.size()*log(scale);
   974   scalartype operator()(vectortype x){
   975     scalartype ans=f(x/scale);
   976     ans+=x.size()*log(scale);
   980     return f.jacobian(x/scale)/scale;    
   982   int ndim(){
return f.ndim();}
   983   vectortype variance(){
   984     return (scale*scale)*f.variance();
   986   vectortype sqrt_cov_scale(vectortype u){
   987     return scale * f.sqrt_cov_scale(u);
   989   SIMULATE_IMPLEMENTED_UNKNOWN_SIZE
   991 template <
class scalartype, 
class distribution>
  1018 template <
class distribution>
  1020   TYPEDEFS(
typename distribution::scalartype);
  1026   VECSCALE_t(distribution f_, vectortype scale_){scale=scale_;f=f_;}
  1030     scalartype ans=f(x/scale);
  1031     ans+=(log(scale)).
sum();
  1034   scalartype operator()(vectortype x){
  1036     scalartype ans=f(x/scale);
  1037     ans+=(log(scale)).
sum();
  1043     for(
int i=0;i<y.cols();i++)y.col(i)=y.col(i)/scale[i];
  1045     for(
int i=0;i<y.cols();i++)y.col(i)=y.col(i)/scale[i];
  1048   int ndim(){
return f.ndim();}
  1049   VARIANCE_NOT_YET_IMPLEMENTED
  1050   vectortype sqrt_cov_scale(vectortype u){
  1051     return scale * f.sqrt_cov_scale(u);
  1053   SIMULATE_IMPLEMENTED_UNKNOWN_SIZE
  1056 template <
class vectortype, 
class distribution>
  1105 template <
class distribution1, 
class distribution2>
  1107   TYPEDEFS(
typename distribution1::scalartype);
  1113   SEPARABLE_t(distribution1 f_, distribution2 g_){f=f_;g=g_;}
  1134     for(
int i=0;i<n;i++){m=m*revd[i];revnewdim[i]=revd[i];}
  1137     return arraytype(x,revnewdim.reverse());
  1139   scalartype operator()(arraytype x){
  1140     if(this->ndim() != x.dim.size())std::cout << 
"Wrong dimension in SEPARABLE_t\n";
  1145     scalartype q=scalartype(.5)*(y.sum()); 
  1148     arraytype zf=zeroVector(x.dim,n);
  1149     q+=f(zf)*(scalartype(x.size())/scalartype(zf.size()));
  1152     arraytype zg=zeroVector(x.dim,m);
  1153     q+=g(zg)*(scalartype(x.size())/scalartype(zg.size()));
  1154     q-=log(sqrt(2.0*M_PI))*(zf.size()*zg.size());
  1158   int ndim(){
return f.ndim()+g.ndim();}
  1159   VARIANCE_NOT_YET_IMPLEMENTED
  1170   scalartype operator()(arraytype x, 
int i){
  1171     if(this->ndim() != x.dim.size())std::cout << 
"Wrong dimension in SEPARABLE_t\n";
  1176     scalartype q=scalartype(.5)*(y.col(i).sum()); 
  1180       arraytype zf=zeroVector(x.dim,n);
  1181       q+=f(zf)*(scalartype(x.size())/scalartype(zf.size()));
  1184       arraytype zg=zeroVector(x.dim,m);
  1185       q+=g(zg)*(scalartype(x.size())/scalartype(zg.size()));
  1186       q-=log(sqrt(2.0*M_PI))*(zf.size()*zg.size());
  1192   arraytype sqrt_cov_scale(arraytype u) {
  1196     int f_size = f_dim.prod();
  1197     int g_size = g_dim.prod();
  1200     new_dim << g_dim, f_size;
  1202     for(
int i=0; i<f_size; i++) {
  1203       u.col(i) = g.sqrt_cov_scale( u.col(i) );
  1207     new_dim.resize(f.ndim() + 1);
  1208     new_dim << f_dim, g_size;
  1210     for(
int i=0; i<g_size; i++) {
  1211       u.col(i) = f.sqrt_cov_scale( u.col(i) );
  1218   void simulate(arraytype &x) {
  1220     x = sqrt_cov_scale(x);
  1221     x = zero_derivatives(x);
  1246 template <
class distribution1, 
class distribution2>
  1296 template <
class distribution>
  1298   TYPEDEFS(
typename distribution::scalartype);
  1314   void initialize(
int n_){
  1322       for(
int i=0;i<nA;i++)mark[proj[i]]=1;
  1324       for(
int i=0;i<n;i++)
if(!mark[i])cproj[k++]=i;
  1332       for(
int i=0;i<n;i++)
  1333         for(
int j=0;j<n;j++)
  1334           v(k++)=scalartype(i==j);
  1341       for(
int i=0;i<n*n;i++)Q(i)=a[i];
  1343       matrixtype QBB(nB,nB);
  1344       for(
int i=0;i<nB;i++)
  1345         for(
int j=0;j<nB;j++)
  1346           QBB(i,j)=Q(cproj[i],cproj[j]);
  1351   vectortype projB(vectortype x){
  1353     for(
int i=0;i<nB;i++)y[i]=x[cproj[i]];
  1356   vectortype setZeroB(vectortype x){
  1357     for(
int i=0;i<nB;i++)x[cproj[i]]=scalartype(0);
  1360   scalartype operator()(vectortype x){
  1361     initialize(x.size());
  1365     arraytype xa(x,dim);
  1366     vectortype y=projB(f.jacobian(xa));
  1368     return f(xa) - dmvnorm(y) + 2*dmvnorm(y*scalartype(0));
  1371   arraytype projB(arraytype x){
  1372     vectortype z((x.size()/n)*nB);
  1374     dim[dim.size()-1]=nB;
  1376     for(
int i=0;i<nB;i++)y.col(i)=x.col(cproj[i]);
  1379   arraytype setZeroB(arraytype x){
  1380     for(
int i=0;i<nB;i++)x.col(cproj[i])=x.col(0)*scalartype(0);
  1384     initialize(x.dim[x.dim.size()-1]);
  1385     arraytype xa=setZeroB(x);
  1386     arraytype y=projB(f.jacobian(xa));
  1390     arraytype tmp=f.jacobian(xa);
  1391     arraytype tmp0=tmp*scalartype(0);
  1392     arraytype tmp2=dmvnorm.jacobian(y);
  1394     for(
int i=0;i<nB;i++){ 
  1395       tmp0.col(cproj[i])=tmp2.col(i);
  1398     tmp0=f.jacobian(tmp0);
  1400     tmp0=setZeroB(tmp0);
  1404   int ndim(){
return f.ndim();}
  1405   VARIANCE_NOT_YET_IMPLEMENTED
  1406   SIMULATE_NOT_YET_IMPLEMENTED
  1409 template <
class distribution>
 #define SIMULATE_NOT_YET_IMPLEMENTED
 
array< Type > col(int i)
Extract sub-array with write access Index i refers to the outer-most (i.e. final) dimension...
 
vectortype cov(int n)
Covariance extractor. Run Youle-Walker recursions and return a vector of length n representing the au...
 
Collection of multivariate Gaussian distributions (members listed in density.hpp) ...
 
matrix< Type > jacobian(Functor f, vector< Type > x)
Calculate jacobian of vector function with vector values. 
 
scalartype operator()(vectortype x)
Evaluate the negative log density. 
 
Multivariate normal distribution with unstructered correlation matrix. 
 
Type dnorm(Type x, Type mean, Type sd, int give_log=0)
Probability density function of the normal distribution. 
 
MVNORM_t< scalartype > MVNORM(matrix< scalartype > Sigma, bool use_atomic=true)
Construct object to evaluate multivariate zero-mean normal density with user supplied covariance matr...
 
SEPARABLE_t< distribution1, distribution2 > SEPARABLE(distribution1 f_, distribution2 g_)
Construct object to evaluate the separable extension of two multivariate zero-mean normal densities...
 
scalartype operator()(vectortype x, vectortype dx)
Evaluate the negative log density of the process x with nuisance parameters dx. 
 
void simulate(vectortype &x)
Draw a simulation from the process. 
 
Standardized normal distribution. 
 
array< Type > transpose()
Array transpose (Special case of array permutation) 
 
matrixtype cov()
Covariance matrix extractor. 
 
scalartype operator()(arraytype x)
Evaluate the negative log density. 
 
VECSCALE_t< distribution > VECSCALE(distribution f_, vectortype scale_)
Construct object to evaluate a scaled density. See VECSCALE_t for details. 
 
scalartype operator()(scalartype x)
Evaluate the negative log density. 
 
Continuous AR(2) process. 
 
UNSTRUCTURED_CORR_t< scalartype > UNSTRUCTURED_CORR(vector< scalartype > x)
Construct object to evaluate the density with unstructured correlation matrix. See UNSTRUCTURED_CORR_...
 
scalartype operator()(vectortype x)
Evaluate the negative log density. 
 
Apply scale transformation on a density. 
 
Taped sorting of a vector. 
 
Matrix exponential: 2x2 case which can be handled efficiently. 
 
Matrix class used by TMB. 
 
Type sum(Vector< Type > x)
 
Type rnorm(Type mu, Type sigma)
Simulate from a normal distribution. 
 
matrix< Type > invertSparseMatrix(Eigen::SparseMatrix< Type > A)
 
Vector class used by TMB. 
 
Apply a vector scale transformation on a density. 
 
scalartype operator()(arraytype x)
Evaluate the negative log density. 
 
scalartype operator()(vectortype x, vectortype keep)
Evaluate projected negative log density. 
 
Matrix< scalartype, n1 *n3, n2 *n4 > kronecker(Matrix< scalartype, n1, n2 > x, Matrix< scalartype, n3, n4 > y)
Kronecker product of two matrices. 
 
Stationary AR(k) process. 
 
scalartype operator()(vectortype x)
Evaluate the negative log density. 
 
matrix< Type > matinvpd(matrix< Type > x, Type &logdet)
Matrix inverse and determinant. 
 
Projection of multivariate gaussian variable. 
 
Separable extension of two densitites. 
 
Utility functions for TMB (automatically included) 
 
Multivariate normal distribution with user supplied covariance matrix. 
 
Gaussian Markov Random Field. 
 
GMRF_t< scalartype > GMRF(Eigen::SparseMatrix< scalartype > Q, int order, bool normalize=true)
Construct object to evaluate density of Gaussian Markov Random Field (GMRF) for sparse Q...