Issue with stochastic indexing in 0.6-12

129 views
Skip to first unread message

Cat Sun

unread,
Dec 2, 2018, 11:01:33 PM12/2/18
to nimble-users

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

 

Sun_IHPPnimble_issue.zip

Chris Paciorek

unread,
Dec 3, 2018, 3:59:21 PM12/3/18
to catheri...@gmail.com, nimble...@googlegroups.com
hi Cat,

You have the line:
zi[i] <- (sum(z[i]) > 0)

When we compile that to the C++ version of the model, z[i] is a scalar
and the sum function that is used in C++ expects a vector, matrix,
etc.

I suspect that you don't really want sum(z[i]) any way...

Chris
> --
> You received this message because you are subscribed to the Google Groups "nimble-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
> To post to this group, send email to nimble...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/92bc2ef1-7c65-439b-9585-821981f77f93%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Cat Sun

unread,
Dec 3, 2018, 6:09:03 PM12/3/18
to nimble-users
Hi Chris,

Ah, I see - thank you! I removed that, as I can derive those values from the output, and it compiles and runs fine now.

Is there a way to not have to invoke a custom nimble function for the indexing though? I had that that d06.-12 accommodates dynamic/stochastic indexing.

Again, thanks so much (and for such a quick response!)
Cat

Chris Paciorek

unread,
Dec 3, 2018, 6:17:25 PM12/3/18
to catheri...@gmail.com, nimble...@googlegroups.com
Yes, you can definitely just use dynamic indexing in your models. In
your case it looks like you just need:
x0g[i] <- grid[s[i],1]
and similarly for y0g[i].

Let us know if that doesn't work for you.

Chris
> To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/c25725f4-290f-4e22-ad3c-2a1ddb13c862%40googlegroups.com.

Cat Sun

unread,
Dec 4, 2018, 12:05:36 PM12/4/18
to nimble-users
Hi Chris,

Hmm, that's what I originally had and what triggers "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)."

That script is in my zip folder. It was this error that prompted me using the nimbleFunction workaround.

Any ideas?
Cat

Perry de Valpine

unread,
Dec 4, 2018, 12:16:35 PM12/4/18
to catheri...@gmail.com, nimble...@googlegroups.com
Cat,

Have you tried the stochastic indexing version of the code recently?  The old nimble-users exchange you referred to was from December, 2015.  Release notes show that in July 2017 (0.6-6) we supported dynamic (aka stochastic) indexing and in December 2018 (0.6-8) we turned on that support as the default.  Old release notes can be found as blog posts on R-nimble.org.

Best wishes,
Perry 

Perry de Valpine

unread,
Dec 4, 2018, 12:21:35 PM12/4/18
to catheri...@gmail.com, nimble...@googlegroups.com
Oops: That second date should be December 2017, not 2018.

Chris Paciorek

unread,
Dec 4, 2018, 12:22:10 PM12/4/18
to Perry de Valpine, Cat Sun, nimble...@googlegroups.com
Hi Cat,

Please define 'grid' in 'inits' or 'data', not in 'constants'. I
believe that will solve the problem.

Basically, 'constants' get baked into the model and can't be indexed
by a non-constant index value because there is not a variable
representing the constants.

Chris
On Tue, Dec 4, 2018 at 9:16 AM Perry de Valpine <pdeva...@berkeley.edu> wrote:
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/CABeTmqjm4ciS9m-ydg0gfFxLpOy-FLThhL1apKpDY_7i_btzRA%40mail.gmail.com.

Cat Sun

unread,
Dec 4, 2018, 12:59:13 PM12/4/18
to nimble-users
Hi Chris,

Ah I see. Thank you! Moving grid from 'constants' to 'inits'/'data' did the trick! 

Cat
Reply all
Reply to author
Forward
0 new messages