Closed pehkawn closed 11 months ago
Ok, so studying the "dyes" model, I get the impression readBUGSmodel()
don't understand where the for
loop ends. After adding ;
at the end of the small for
-loops on lines 42 and 66, parsing error is no longer returned. Interestingly, no parsing error is returned due to lack of semicolon behind the right braces for the for
-loops on lines 2-40 and 4-7.
Thanks for the report. The issue seems to be some odd behavior in R's parse
handling the syntax. I'm not seeing the problem on quick glance, but we'll dig deeper into this to try to fix for the next release.
Here's a reduced example that also fails:
model {
for(i in 1:N){
mu[i, 1] <- eta[i]
}
for(k in 1:4) {
u[k] <- 0.0
}
var.lam[2] <- 4.0 * psi[4]
}
Commenting out the var.lam[2]
definition avoids the failure.
Thank you for your reply. I did not find a particular issue with var.lam[2]
, if that's what you mean, and commenting out that particular line did not remove the parsing error. Commenting out all the variables in between the for
-loops did, however, remove the parsing error. For now, it seems the easiest solution is to add a semicolon behind the right braces.
Ok, narrowing this down further the issue seems to be with having a line that starts with "var" (or "data") following a for loop. So this is an issue with nimble not parse
.
This means the problem is with how we separate blocks (model vs. var vs data) of syntax in input files. I'll need to dig into mergeMultiLineStatements
to fix this.
Actually the issue was in processModelFile
. Our regex in defining modelBlockRegEx
was not sophisticated enough to realize that (var|data|const)
after a }
(e.g., from a for loop) was not the beginning of a block.
In branch fix_1351
I have a fix.
Fixed by PR #1369
I am currently testing some structural equation models from the book "Structural Equation Modeling: a Bayesian Approach" by Sik-Yum Lee (2007). The book provides WinBUGS codes and datasets for some of the models in the book, and I am currently trying to fit a model from chapter 6.6.2 using Nimble. The model has been tested, and works with WinBUGS, OpenBUGS and JAGS, where it runs without issue. (Since this model uses WinBUGS'
I()
function, this was changed toT()
to work with JAGS.) However, when I try read in the model in Nimble, using thereadBUGSmodel()
function, I get the following parsing error:The error indicates that there's a bracket or parenthesis missing, or similar. However, going through the file I can find no indication of such, and the code runs without issue in the aforementioned programs. Therefore I assume there must be something about the way
readBUGSmodel()
reads the file.R code:
BUGS code in file
ch6-JAGS-model.txt
: