Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node not recognized when double brackets on the lhs in JAGS #35

Open
audrey-b opened this issue May 9, 2022 · 2 comments
Open

node not recognized when double brackets on the lhs in JAGS #35

audrey-b opened this issue May 9, 2022 · 2 comments

Comments

@audrey-b
Copy link
Owner

audrey-b commented May 9, 2022

The Bug

When a node is defined on the left hand side using embedded square brackets, such as a[i[1]], it is not recognized as a node and cannot be monitored.

A Reprex

Here, node a cannot be monitored:

sims::sims_simulate("
    a[i[1]] ~ dnorm(0,1)
    b ~ dnorm(0,1)", 
  constants = list(i=c(1,2,3)))

$b
[1] -0.9078546

$i
[1] 1 2 3

an nlists object of an nlist object with 2 numeric elements

Here, node a is monitored, which is the desired behavior:

sims::sims_simulate("
    a[1] ~ dnorm(0,1)
    b ~ dnorm(0,1)")

$a
[1] -0.644611

$b
[1] 0.09873857

an nlists object of an nlist object with 2 numeric elements```
@joethorley
Copy link
Collaborator

@audrey-b - Interesting I didn't know this was a possibility! I'm pretty snowed under are you able to fix in a pull request?

@audrey-b
Copy link
Owner Author

I spent a couple hours trying to figure it out yesterday but did not succeed, so I will leave it at it for now. I'm not well versed in regex. It seems like the issue is within the internal function stochastic_nodes_pattern, which currently uses

index <- "\\[[^\\]]*\\]"

to extract nodes that have 0 or 1 of: a bracket [ followed by anything but a bracket ], and then followed with a closing bracket ]. This results in discarding nodes that have nested brackets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants