You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Urgent help about the use of TMB templates in R package with Rcpp
Description:
For my project, I am trying to use two TMB templates (LocalLikelihood1 and LocalLikelihood2) with some C files also. LocalLikelihood1 is same as the LocalLikelihood.cpp in https://github.com/mlysy/LocalCop/tree/master/src. I created a second one because of two different estimations. Besides, I followed the steps given here for creating two templates correctly (in that sense it is different what it was done in the package LocalCop it seems, for detail: https://github.com/mlysy/LocalCop). Since I have limited knowledge on C++ I tried to stick previous codes and also mimicked what is discussed in different discussions but still I could not figure out why I got errors related to RcppEigen ?
Reproducible Steps:
I just created a testVDAG package with Locallikelihood1.cpp with the header files like Clayton.h etc.
When I check the package I got error messages related to RcppEigen files like Meta.h, DenseBase.h telling me that
-Line 83 no members matching and similar
This is my main .cpp file
/// @file LocalLikelihood1.cpp
///
/// Local Likelihood functions.
This is one of the .h files
/// @file ClaytonCopula.h
/// Local likelihood for the Clayton copula.
///
/// @param[in] lu1 First log-uniform response vector.
/// @param[in] lu2 Second log-uniform response vector.
/// @param[in] yc Covariate vector in centered form yc = Y-y.
/// @param[in] beta Length-two vector of dependence parameters,
/// such that eta(yc) = beta[0] + beta[1] * yc.
/// @param[in] wgt Local likelihood weights.
/// @return Negative local loglikelihood (scalar).
template
Type ClaytonNLL(vector lu1, vector lu2,
vector yc, vector beta, vector wgt) {
// parameter on regular scale
vector theta = (beta[0] + beta[1] * yc).exp();
vector ll = (1.0 + theta).log() - (1.0 + theta) * (lu1 + lu2);
ll -= (2.0 + 1.0/theta) * ((-theta * lu1).exp() + (-theta * lu2).exp() - 1.0).log();
ll *= wgt;
return -ll.sum();
}
This is my DESCRIPTION file (you can use the given mail address if you want)
Package: testVDAG
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: OzanEvkaya [email protected]
Maintainer: The package maintainer [email protected]
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
LinkingTo:
Rcpp, RcppEigen, TMB
Imports:
Rcpp,
TMB
I created .R file for this part named as testVDAG.R
Urgent help about the use of TMB templates in R package with Rcpp
Description:
For my project, I am trying to use two TMB templates (LocalLikelihood1 and LocalLikelihood2) with some C files also. LocalLikelihood1 is same as the LocalLikelihood.cpp in https://github.com/mlysy/LocalCop/tree/master/src. I created a second one because of two different estimations. Besides, I followed the steps given here for creating two templates correctly (in that sense it is different what it was done in the package LocalCop it seems, for detail: https://github.com/mlysy/LocalCop). Since I have limited knowledge on C++ I tried to stick previous codes and also mimicked what is discussed in different discussions but still I could not figure out why I got errors related to RcppEigen ?
Reproducible Steps:
I just created a testVDAG package with Locallikelihood1.cpp with the header files like Clayton.h etc.
When I check the package I got error messages related to RcppEigen files like Meta.h, DenseBase.h telling me that
-Line 83 no members matching and similar
This is my main .cpp file
/// @file LocalLikelihood1.cpp
///
/// Local Likelihood functions.
#define TMB_LIB_INIT R_init_tsVine
#include <TMB.hpp>
#include "FrankCopula.h"
#include "GaussCopula.h"
#include "GumbelCopula.h"
#include "JoeCopula.h"
#include "ClaytonCopula.h"
template
Type objective_function::operator() () {
DATA_VECTOR(y1); // first response vector
DATA_VECTOR(y2); // second response vector
DATA_VECTOR(wgt); // weights
DATA_VECTOR(yc); // centered covariates, i.e., Y - y
DATA_INTEGER(family); // copula family: 1-3-4-5-6.
PARAMETER_VECTOR(beta); // dependence parameter: eta = beta[0] + beta[1] * yc
Type nll = 0.0;
if(family == 1) {
// Gaussian copula
nll = GaussNLL(y1, y2, yc, beta, wgt);
} else if(family == 3) {
// Clayton copula
nll = ClaytonNLL(y1, y2, yc, beta, wgt);
} else if(family == 4) {
// Gumbel copula
nll = GumbelNLL(y1, y2, yc, beta, wgt);
} else if(family == 5) {
// Frank copula
nll = FrankNLL(y1, y2, yc, beta, wgt);
} else if(family == 6) {
// Joe copula
nll = JoeNLL(y1, y2, yc, beta, wgt);
}
return nll;
}
This is one of the .h files
/// @file ClaytonCopula.h
/// Local likelihood for the Clayton copula.
///
/// @param[in] lu1 First log-uniform response vector.
/// @param[in] lu2 Second log-uniform response vector.
/// @param[in] yc Covariate vector in centered form
yc = Y-y
./// @param[in] beta Length-two vector of dependence parameters,
/// such that
eta(yc) = beta[0] + beta[1] * yc
./// @param[in] wgt Local likelihood weights.
/// @return Negative local loglikelihood (scalar).
template
Type ClaytonNLL(vector lu1, vector lu2,
vector yc, vector beta, vector wgt) {
// parameter on regular scale
vector theta = (beta[0] + beta[1] * yc).exp();
vector ll = (1.0 + theta).log() - (1.0 + theta) * (lu1 + lu2);
ll -= (2.0 + 1.0/theta) * ((-theta * lu1).exp() + (-theta * lu2).exp() - 1.0).log();
ll *= wgt;
return -ll.sum();
}
This is my DESCRIPTION file (you can use the given mail address if you want)
Package: testVDAG
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: OzanEvkaya [email protected]
Maintainer: The package maintainer [email protected]
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
LinkingTo:
Rcpp, RcppEigen, TMB
Imports:
Rcpp,
TMB
I created .R file for this part named as testVDAG.R
#'Test package for semVineDAG
#' @useDynLib testVDAG, .registration = TRUE
#' @importFrom Rcpp sourceCpp
Sorry for above long lines, to reproduce you can look at the attached file for the testVDAG project in R
TMB Version:
packageVersion("TMB")
[1] ‘1.7.16’
R Version:
$arch
[1] "x86_64"
$os
[1] "mingw32"
$system
[1] "x86_64, mingw32"
$version.string
[1] "R version 3.6.2 (2019-12-12)"
Operating System:
Windows 10 Enterprise 64-bit operating system, x64 based processor
testVDAG.zip
The text was updated successfully, but these errors were encountered: