Hi all,
I tried to run a dependent Dirichlet process mixture model using logit stick-breaking representation. My model code is as follows:
model <- nimbleCode({
# likelihood
for(i in 1:N) {
for(j in 1:J) {
y[i,j] ~ dcat(ip[z[i], j])
}
z[i] ~ dcat(w[i,1:H])
}
# prior on item parameters
for(h in 1:H) {
for(j in 1:J) {
ip[h, j] ~ dbeta(shape1 = a1, shape2 = a2)
}
}
# logit stick-breaking process
for(h in 1:(H-1)) {
b0[h] ~ dnorm(0,1.0E-03)
b1[h] ~ dnorm(0,1.0E-03)
b2[h] ~ dnorm(0,1.0E-03)
b3[h] ~ dnorm(0,1.0E-03)
}
for(i in 1:N) {
for(h in 1:(H-1)) {
logit(v[i,h]) <- b0[h] + b1[h]*x1[i] + b2[h]*x2[i] + b3[h]*x3[i]
}
w[i,1:H] <- stick_breaking(v[i,1:(H-1)]) # stick-breaking weights
}
})
N <- nrow(dat)
J <- 10
H <- 10
nMCMC <- 10000
constants <- list(N = N, J = 10, H = 10, a1 = 1, a2 = 1)
inits <- list(ip = matrix(rbeta(H*J, shape1 = 1, shape2 = 1), nrow = H, ncol = J),
z = sample(1:5, size = constants$N, replace = TRUE),
v = matrix(0.1, nrow = N, ncol = H),
b0 = rnorm(H,0,1), b1 = rnorm(H,0,1), b2 = rnorm(H,0,1), b3 = rnorm(H,0,1))
Dat <- list(y = dat[,1:10], x1 = dat[,18], x2 = dat[,19], x3 = dat[,20])
model <- nimbleModel(model, data = Dat, inits = inits, constants = constants,
dimensions = list(ip = c(H, J)))
cmodel <- compileNimble(model)
conf <- configureMCMC(model, monitors = c('z','ip','b0','b1','b2','b3'), print = TRUE)
mcmc <- buildMCMC(conf)
cmcmc <- compileNimble(mcmc, project = model)
samples <- runMCMC(cmcmc, niter = nMCMC, nburnin = 0, thin = 1, setSeed = TRUE) # no burning and thinning
However, I got the following error after compiling the model:
cmodel <- compileNimble(model)
Compiling [Note] This may take a minute. [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.
The detailed message after running printErrors() is as follows:
using C++ compiler: 'G__~1.EXE (GCC) 12.2.0' P_3_model_MID_6_nfCode.cpp: In member function 'virtual void y_L3_UID_40::simulate(const indexedNodeInfo&) const': P_3_model_MID_6_nfCode.cpp:21:104: error: cannot bind non-const lvalue reference of type 'NimArr<1, double>&' to an rvalue of type 'NimArr<1, double>' 21 | (**model_y)((ARG1_INDEXEDNODEINFO__.info[0]) - 1, (ARG1_INDEXEDNODEINFO__.info[1]) - 1) = nimArr_rcat(Interm_59); | ^~~~~~~~~ In file included from C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/RcppNimbleUtils.h:25, from C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/NamedObjects.h:28, from C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/EigenTypedefs.h:26, from P_3_model_MID_6_nfCode.cpp:6: C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/NimArr.h:289:3: note: after user-defined conversion: 'NimArr<1, T>::NimArr(int) [with T = double]' 289 | NimArr<1, T>(int is1) : NimArrBase<T>() { setSize(is1); } | ^~~~~~~~~~~~ In file included from P_3_model_MID_6_nfCode.h:10, from P_3_model_MID_6_nfCode.cpp:13: C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/nimDists.h:46:39: note: initializing argument 1 of 'double nimArr_rcat(NimArr<1, double>&)' 46 | double nimArr_rcat(NimArr<1, double> &prob); | ~~~~~~~~~~~~~~~~~~~^~~~ P_3_model_MID_6_nfCode.cpp: In member function 'virtual double y_L3_UID_40::calculate(const indexedNodeInfo&) const': P_3_model_MID_6_nfCode.cpp:33:123: error: cannot bind non-const lvalue reference of type 'NimArr<1, double>&' to an rvalue of type 'NimArr<1, double>' 33 | (**model_logProb_y)((ARG1_INDEXEDNODEINFO__.info[0]) - 1, (ARG1_INDEXEDNODEINFO__.info[1]) - 1) = nimArr_dcat(Interm_60, Interm_61, 1); | ^~~~~~~~~ C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/NimArr.h:289:3: note: after user-defined conversion: 'NimArr<1, T>::NimArr(int) [with T = double]' 289 | NimArr<1, T>(int is1) : NimArrBase<T>() { setSize(is1); } | ^~~~~~~~~~~~ C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/nimDists.h:45:49: note: initializing argument 2 of 'double nimArr_dcat(double, NimArr<1, double>&, int)' 45 | double nimArr_dcat(double x, NimArr<1, double> &prob, int give_log); | ~~~~~~~~~~~~~~~~~~~^~~~ P_3_model_MID_6_nfCode.cpp: In member function 'virtual double y_L3_UID_40::calculateDiff(const indexedNodeInfo&) const': P_3_model_MID_6_nfCode.cpp:48:43: error: cannot bind non-const lvalue reference of type 'NimArr<1, double>&' to an rvalue of type 'NimArr<1, double>' 48 | LocalNewLogProb = nimArr_dcat(Interm_62, Interm_63, 1); | ^~~~~~~~~ C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/NimArr.h:289:3: note: after user-defined conversion: 'NimArr<1, T>::NimArr(int) [with T = double]' 289 | NimArr<1, T>(int is1) : NimArrBase<T>() { setSize(is1); } | ^~~~~~~~~~~~ C:\Users\Chris\AppData\Local\R\win-library\4.3\nimble\include/nimble/nimDists.h:45:49: note: initializing argument 2 of 'double nimArr_dcat(double, NimArr<1, double>&, int)' 45 | double nimArr_dcat(double x, NimArr<1, double> &prob, int give_log); | ~~~~~~~~~~~~~~~~~~~^~~~ P_3_model_MID_6_nfCode.cpp: In member function 'virtual double y_L3_UID_40::getParam_0D_double(int, const indexedNodeInfo&) const': P_3_model_MID_6_nfCode.cpp:68:141: error: request for member 'size' in '(*(NimArr<2, double>**)((const y_L3_UID_40*)this)->y_L3_UID_40::model_ip)->NimArr<2, double>::operator()((int)((*(NimArr<1, double>**)((const y_L3_UID_40*)this)->y_L3_UID_40::model_z)->NimArr<1, double>::<unnamed>.operator[](int)((int)((__gnu_cxx::__alloc_traits<std::allocator<double>, double>::value_type)ARG2_INDEXEDNODEINFO__->indexedNodeInfo::info.std::vector<double, std::allocator<double> >::operator[](std::vector<double, std::allocator<double> >::size_type)(0) - (__gnu_cxx::__alloc_traits<std::allocator<double>, double>::value_type)1)) - (double)1), (int)((__gnu_cxx::__alloc_traits<std::allocator<double>, double>::value_type)ARG2_INDEXEDNODEINFO__->indexedNodeInfo::info.std::vector<double, std::allocator<double> >::operator[](std::vector<double, std::allocator<double> >::size_type)(1) - (__gnu_cxx::__alloc_traits<std::allocator<double>, double>::value_type)1))', which is of non-class type 'double' 68 | PARAMANSWER_ = static_cast<int>((**model_ip)(((**model_z)[(ARG2_INDEXEDNODEINFO__.info[0]) - 1]) - 1, (ARG2_INDEXEDNODEINFO__.info[1]) - 1).size()); | ^~~~ make: *** [C:/PROGRA~1/R/R-43~1.1/etc/x64/Makeconf:272: P_3_model_MID_6_nfCode.o] Error 1
I have no idea what this error means. I'll greatly appreciate your help. Thank you very much!
Best,
Cody