Re: Using nimbleRcall and the example given in the documentation

22 views
Skip to first unread message
Message has been deleted

Daniel Turek

unread,
Jul 15, 2024, 9:04:10 AM (7 days ago) Jul 15
to Jimmy Hickey, nimble-users
Jimmy, thanks for your use of nimble, and also posting your question.  I'm pleased to report that yes, I do believe there's something simple that you're missing.  In all instances of the numbers above, including the highlighted cases, z does indeed hold x+2.  For the first highlighted example, for instance,

-0.6264538 + 2 = 1.373546

From the highlighting, I'm guessing you were just overlooking the leading negative signs, and I think we're on solid ground that things are working as you expect.  Please keep in touch with any other questions that come up.

Cheers,
Daniel


On Mon, Jul 15, 2024 at 1:53 AM Jimmy Hickey <jimmyj...@gmail.com> wrote:
Hello all!

I am trying to use nimbleRcall for the first time and am having trouble with the example given in help("nimbleRcall").

I have simplified the example given in the documentation below to illustrate the point easier. My understanding of the code is that z should hold x+2 for every iteration, but in some cases (highlighted) it does not. Please let me know if there is something simple that I am missing! I would like to understand this more closely before moving onto more complicated uses of the function.

Thank you so much for the help!
Jimmy

library(nimble)

add2 <- function(x) {
  x + 2
}

nimble_add2 <- nimbleRcall(
  prototype = function(
    x = double(0)
    ){},
   returnType = double(0),
  Rfun = 'add2')

demoCode <- nimbleCode({
  x ~ dnorm(0,1)
  z <- nimble_add2(x)
})

demoModel <- nimbleModel(demoCode, inits = list(x = 1),
                         check = FALSE, calculate = FALSE)


mcmcConf <- configureMCMC(demoModel, monitors = c("x", "z"))
Rmcmc <- buildMCMC(mcmcConf)
Cmcmc <- compileNimble(demoModel)
Cmcmc <- compileNimble(Rmcmc, project = demoModel)

set.seed(1)
Cmcmc$run(niter = 10, nburnin = 0)
as.matrix(Cmcmc$mvSamples)



x z [1,] -0.6264538 1.373546 [2,] 0.1836433 2.183643 [3,] -0.8356286 1.164371 [4,] 1.5952808 3.595281 [5,] 0.3295078 2.329508 [6,] -0.8204684 1.179532 [7,] 0.4874291 2.487429 [8,] 0.7383247 2.738325 [9,] 0.5757814 2.575781 [10,] -0.3053884 1.694612


--
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/ca755d86-14a6-47bb-beeb-b5b8df641623n%40googlegroups.com.
Message has been deleted

Jimmy Hickey

unread,
Jul 15, 2024, 9:39:06 AM (7 days ago) Jul 15
to nimble-users
Whoops, that's a silly mistake! Thanks, Daniel! I have tried to remove the original post since there wasn't an issue.
Reply all
Reply to author
Forward
0 new messages