--
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 view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/50ae551c-f852-4be6-ad9c-1c9a21997feen%40googlegroups.com.
Error in permute.verticecs(graph, oldGraphID_2_newGraphID) :
At topology.c:2725 : Permute vertices: invalid permutation vector size, Invalid value
In addition: Warning message:
In topological.sort(graph, mode = “out”) :
At structural_properties.c:3346 :graph contains a cycle, partial result is returned
3) Next, I tried to compute autocov[i, t] one at a time, as you suggested. I think this is the proper way to feed the i and t indices into the function? I tried this:
calc_autcov <- nimbleFunction(
run = function(z = double(2), neighID = double(2), numN = double(1), i = integer(), t = integer()){
returnType(double(1))
result <- sum(z[neighID[i, 1:numN[i]], t-1]) / numN[i]
return(result)
})
Hi folks,
Sorry to dig out this old thread. I am new to Nimble and I am trying to run the autologistic dynocc model. I followed the tips from this thread but I get the following error (code below):
Error in topological.sort(graph, mode = "out") :
At core/properties/dag.c:114 : The graph has cycles; topological sorting is only possible in acyclic graphs, Invalid value
Any ideas what could be wrong?
Neil, were you able to successfully run the model in Nimble in the end? And if so, could you share the code with me?
Thank you very much,
Oriol
This is my attempt:
# Autocovariate Nimble function
calc_autocov <- nimbleFunction(
run = function(i = integer(), t = integer(), z = double(2), neighID = double(2), numN = double(1)){
returnType(double(0))
result <- sum(z[neighID[i, 1:numN[i]], t-1]) / numN[i]
return(result)
})
# NIMBLE model
dynocc_model <- nimble::nimbleCode( {
# Priors
psi1 ~ dunif(0, 1) # Initial occupancy
alpha.lpsi1 <- logit(psi1)
beta.lpsi1 ~ dnorm(0, 0.01)
phi.int ~ dunif(0, 1) # Persistence
alpha.lphi <- logit(phi.int)
beta.lphi ~ dnorm(0, 0.01)
gamma.int ~ dunif(0, 1) # Colonization
alpha.lgamma <- logit(gamma.int)
beta.lgamma ~ dnorm(0, 0.01)
p ~ dunif(0, 1) # Detection
# Likelihood
# Ecological submodel
for (i in 1:nsites){
z[i,1] ~ dbern( ilogit(alpha.lpsi1 + beta.lpsi1 * field[i]) )
for (t in 2:nyears){
autocov[i, t-1] <- calc_autocov(i,t,z[1:nsites,1:nyears], neighID[1:nsites, 1:8], numN[1:nsites])
logit(phi[i,t-1]) <- alpha.lphi + beta.lphi * autocov[i,t-1]
logit(gamma[i,t-1]) <- alpha.lgamma + beta.lgamma * autocov[i,t-1]
z[i,t] ~ dbern(z[i,t-1] * phi[i,t-1] + (1-z[i,t-1]) * gamma[i,t-1])
# Compute autocovariate and specify its effects on phi and gamma
}
}
# Observation model
for (i in 1:nsites){
for (j in 1:nsurveys){
for (t in 1:nyears){
y[i,j,t] ~ dbern(z[i,t] * p)
}
}
}
}
)
# Remove Nas from neighID data
neighID[is.na(neighID)]<-nsites+1
bdata <- list(y = y_nimble, nsites = nsites, nsurveys = nsurveys, nyears = nyears,
neighID = neighID, numN = numN,
field=as.vector(field) )
# Initial values
zst <- array(1, dim = c(nsites, nyears))
inits <- function(){ list(z = zst)}
# Parameters monitored
params <- c("alpha.lpsi1", "beta.lpsi1", "alpha.lgamma", "beta.lgamma",
"alpha.lphi", "beta.lphi", "p") # could also monitor "z"
# MCMC settings
na <- 1000 ; ni <- 2000 ; nt <- 2 ; nb <- 1000 ; nc <- 3
out1_nimble <-
nimbleMCMC(code = dynocc_model,
constants = bdata, inits = inits, monitors = params,
nburnin = nb, niter = ni, thin = nt, nchains = nc)
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/d381c8c7-56aa-4c55-b97b-57603925edf6n%40googlegroups.com.
Hi Daniel,
Thank you very much for your answer. Your explanations are very clear.
I modified the nimble function so autocov[i,t-1] depends only on z[1:nsites,t-1]. Now the model seems to run without errors but it takes forever to compile using nimbleMCMC. Any ideas on how to speed up the compilation?
Thank you again,
Oriol
Hi everyone,Just following up on this thread because I'm getting somewhat similar errors related to loop indexing as Neil back in 2021.I am trying to loop through sites (i) and time periods (t), where sites have irregular numbers of time periods. Lines 108-109 in the attached code read:for(i in 1:nsite){
for(t in 2:totalt[i]){}}'totalt' is a vector of length 'nsite'.If I replace this with the following, the model builds with no error:for(i in 1:nsite){
for(t in 2:min(totalt)){}}So I'm pretty certain there's something strange happening with totalt[i]. I have 'totalt' as a constant in the model, and there are no 0s in 'totalt'. I'm a bit baffled by this error and am having a hard time troubleshooting. I have attached code in case there is not something obviously off about this set-up. I have also attached most of the data, except 'counts' because it is 24 MB.Thanks so much as always. Having this Google group as a resource is so amazing.Best,Abby Keller
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/2004e728-731e-4e64-84f9-45b25be91a68n%40googlegroups.com.