我写这篇文章是为了在这个文件(simplex_reg.cpp
)中实现一个单纯形回归:
// Simplex Regression
#include <TMB.hpp>
template<class Type>
Type objective_function<Type>::operator() ()
{
// Data provided from user
DATA_VECTOR(Y);
DATA_MATRIX(X);
DATA_STRING(log);
// Parameter of the model
PARAMETER_VECTOR(Beta);
// Variables used in the programming;
int n = Y.size();
vector<Type> eta(n);
vector<Type> d0(n);
vector<Type> mu(n);
Type sd = 0.0;
Type pi = 3.141593;
Type nll = 0.0;
// Linear predictor
eta = X*Beta;
// logit is link function, and inv.logit is its inverse and is being applied
mu = 1/(1+exp(-eta));
// Density
d0 = pow((Y-mu),2)/(Y*(1-Y)*pow(mu,2)*pow((1-mu),2));
sd = sum(d0)/n;
d0 = -0.5*log(2*pi) -0.5*log(sd) - (3/2)*log(Y*(1-Y)) - (1/(2*sd))*d0;
if(log == "false"){
d0 = exp(d0);
}
nll = -sum(d0);
return nll;
}
但是,当我这样做时它会返回错误compile('simplex_reg.cpp', "-O0 -g")
。当我使用gdbsource()
如下它返回Program returned without errors
:
library(TMB)
setwd("~/Google Drive/Mestrado/dissertacao/TMB")
compile('simplex_reg.cpp', "-O0 -g")
gdbsource("Teste.R")
我已经阅读了编译和运行时错误,但我不明白它是如何gdbsource
工作的。
那么,如何将 debug/gdbsource 运行到“simplex_reg.cpp”文件中以找到我的错误?
提前致谢