Как отладить мой. cpp файл, используя функцию `gdbsource` в TMB в R? - PullRequest
0 голосов
/ 13 апреля 2020

Я пишу для реализации регрессии Симплекс в этом файле (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", чтобы найти мою ошибку?

Заранее спасибо

...