I am writing to implement a Simplex regression in this file (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;
}
However, it return an errors when I do compile('simplex_reg.cpp', "-O0 -g"). When I use gdbsource() as below it returns Program returned without errors:
library(TMB)
setwd("~/Google Drive/Mestrado/dissertacao/TMB")
compile('simplex_reg.cpp', "-O0 -g")
gdbsource("Teste.R")
I have already read the Compilation and run time errors, but I couldn't understand how gdbsourcereally works.
So, How do I run the debug/gdbsource into "simplex_reg.cpp" file to find my mistake?
Thanks in advance
asked Apr 13, 2020 at 18:21
Guilherme Parreira
1,07112 silver badges33 bronze badges
lang-r
-I/home/chris/R-361/R-3.6.1/src/include simplex_reg.cpp: In instantiation of ‘Type objective_function<Type>::operator()() [with Type = CppAD::AD<double>]’: tmb_core.hpp:1135:7: required from here simplex_reg.cpp:28:16: error: no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string<char>}) (CppAD::AD<double>)’ d0 = -0.5*log(2*pi) -0.5*log(sd) - (3/2)*log(Y*(1-Y)) - (1/(2*sd))*d0;as first error. And same within R using your >compile('simplex_reg.cpp', '-O0 -ggdb'). Is as far as I've gotten.gdbsource(). For example, I didn't manage to find the error message that you found, this is the path that I need.Program exited without errorafter running >gdbsource(simplex_reg.cpp), because the message refers to gdb, not simplex_reg.cpp. While nonsensical, I ran it many times. My approach to c++ is akin to 1000 monkeys with typewriters attempting Rilke poems. And I'd lost my path to your Teste.R, alas.