kaskr / adcomp

AD computation with Template Model Builder (TMB)
Other
176 stars 80 forks source link

need DATA_INTEGER_VECTOR #32

Closed mebrooks closed 10 years ago

mebrooks commented 10 years ago

Hi,

I'm unable to compile a model and I believe it is because I'm trying to access elements of one vector using elements of a data vector that are not integers.

The reason is that data is missing on some integer dates

Lynx rufus, from Idaho, GPPD data set 212.

obs=c(346,675,802,1478,1173,756,861,972,854,1161,1318,901,901, 1173,608,811,903,584,1179,1020,1129,966) obsdates=c(1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1970,1971, 1972,1973,1974,1975,1976,1977,1978,1979,1980,1981)

I've narrowed the problem down to this line of cpp code

nll+= -dpois(obs(i), exp(x(obsdates(i))), 1);

Even just nll+= exp(x(obsdates(i))); gives the same error.

I can send you the cpp file if it helps.

The first error I get is

compile("GSS.cpp") Note: Using Makevars in /Users/molliebrooks1/.R/Makevars clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Frameworks/R.framework/Versions/3.1/Resources/library/TMB/include -DTMB_SAFEBOUNDS -DLIB_UNLOAD=R_unload_GSS -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -mtune=core2 -g -O2 -c GSS.cpp -o GSS.o In file included from GSS.cpp:1: In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/TMB/include/TMB.hpp:35: In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/TMB/include/tmbutils/tmbutils.cpp:7: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/TMB/include/tmbutils/vector.cpp:69:20: error: no member named 'size' in 'CppAD::AD' this->resize(x.size()); ~ ^ GSS.cpp:30:30: note: in instantiation of function template specialization 'tmbutils::vector::vector<AD, double>' requested here nll+= -dpois(obs(i), exp(x(obsdates(i))), 1); ^

markpayneatwork commented 10 years ago

Hi Molly,

I think what you're looking for is DATA_IVECTOR isn't it?

Mark

mebrooks commented 10 years ago

Yep. That fixed the problem. Thanks!

So the modified issue is that it's not documented on page 11 of TMB.pdf

mebrooks commented 10 years ago

While on the topic of this pdf page, I was curious if max() and min() are allowable basic calculations.

skaug commented 10 years ago

Searching in the API I find max() and min(), also for Type. But, as with all AD, it is the user's responsibility to formulate a function that is differentiable, and min/max can create problems.

mebrooks commented 10 years ago

DATA_IVECTOR has been added to TMB.pdf with my last pull request