r - 如何使用 R 中 TMB 中的“gdbsource”函数调试我的 .cpp 文件?
问题描述
我写这篇文章是为了在这个文件(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”文件中以找到我的错误?
提前致谢
解决方案
推荐阅读
- mongodb - 在 mongo 中运行 replSetGetStatus 命令的用户角色
- php - 使用自定义键忽略唯一角色 - Laravel - Mongodb
- wordpress - 如何将文本字段值传递到wordpress中的其他页面
- javascript - 在 React 中组合 2 个应用程序
- powershell - 使用 powershell 在两台服务器之间传递安全文本
- c++ - 使 shared_ptr 失去内存所有权
- r - R、Json、Rest API
- mysql - Jmeter中的连接异常
- travis-ci - Travis 手动确认下一阶段
- ios - 在应用内的 ios 中手动检查并下载最新版本