Hi Folks,
I work with hierarchical linear models to estimate abundance from a subset of imperfectly detected individuals within the population - i.e., capture-recapture and spatial-capture-recapture models. I'm trying to fit in nimble a single-season spatial capture-recapture model originally written in JAGS, and have come across an issue with stochastic/dynamic indexing: I get an error about dynamic indexing, which I thought is accommodated in version 0.6-12? I've tried a workaround, but that doesn't work either, so any help would be much appreciated. I'm using nimbleOptions(allowDynamicIndexing = TRUE,showCompilerOutput = TRUE). The issue is as follows:
If I try to model a inhomogeneous point process to describe variation in density, I get the following error "Error in getSymbolicParentNodesRecurse(code, constNames, indexNames, nimbleFunctionNames, :
getSymbolicParentNodesRecurse: dynamic indexing of constants is not allowed in grid[s[i], 1]. Try adding the dynamically-indexed constant as data instead (using the data argument of nimbleModel)." This was essentially exactly Dan Linden'squestion and post on 12/21/15 with this part of his likelihood:
s[i]~dcat(probs[1:nG])
d2[i,j]<- (grid[s[i],1]-grid[traps[j],1])^2 + (grid[s[i],2]-grid[traps[j],2])^2
So, I tried to implement Perry's recommendation in that thread to use a custom nimbleFunction (see below) to do the the indexing, and the model then successfully defined. Yay!
myIndexCalc <- nimbleFunction(
run = function(gridCol = double(1), index = double()) {
return(gridCol [index])
returnType(double(0))
})
However, then I get a compiling error about an issue with 'sum' and 'non-class type 'double'', and then that the shared library is not created:
compiling... this may take a minute. On some systems there may be some compiler warnings that can be safely ignored.
c:/Rtools/mingw_64/bin/g++ -I"C:/PROGRA~1/R/R-35~1.1/include" -DNDEBUG -DR_NO_REMAP -I"C:/Users/CatSun/Documents/R/win-library/3.5/nimble/include" -I"" -I"" -DEIGEN_MPL2_ONLY=1 -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations -O2 -Wall -mtune=generic -c P_3_nimMod_SCR_MID_10.cpp -o P_3_nimMod_SCR_MID_10.o
c:/Rtools/mingw_64/bin/g++ -I"C:/PROGRA~1/R/R-35~1.1/include" -DNDEBUG -DR_NO_REMAP -I"C:/Users/CatSun/Documents/R/win-library/3.5/nimble/include" -I"" -I"" -DEIGEN_MPL2_ONLY=1 -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations -O2 -Wall -mtune=generic -c P_3_nimMod_SCR_MID_10_nfCode.cpp -o P_3_nimMod_SCR_MID_10_nfCode.o
P_3_nimMod_SCR_MID_10_nfCode.cpp: In member function 'virtual void zi_L22_UID_43::simulate(const indexedNodeInfo&) const':
P_3_nimMod_SCR_MID_10_nfCode.cpp:2509:65: error: request for member 'sum' in '(*(NimArr<1, double>**)((const zi_L22_UID_43*)this)->zi_L22_UID_43::model_z)->NimArr<1, double>::<anonymous>.NimArrBase<T>::operator[]<double>((int)((double)*ARG1_INDEXEDNODEINFO__->indexedNodeInfo::info.std::vector<double, std::allocator<double> >::operator[]()(0ull) - 1.0e+0))', which is of non-class type 'double'
Interm_64 = ((**model_z)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1]).sum();
^
At global scope:
cc1plus.exe: warning: unrecognized command line option "-Wno-ignored-attributes"
cc1plus.exe: warning: unrecognized command line option "-Wno-misleading-indentation"
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: P_3_nimMod_SCR_MID_10_nfCode.o] Error 1
Error: Failed to create the shared library
It looks like something in my user nimble function isnt working, but I cant quite make sense of the error. I've attached 2 scripts: one that returns the original dynamic indexing error , and a second script that uses the custom function and returns the compiling issue.
Where is my issue? Any help would be much appreciated. Thanks!
Cat
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/160f7628-a825-454d-9eb2-c4488ba85e72%40googlegroups.com.