hữu thuần phạm
unread,Jun 3, 2025, 11:57:28 AM6/3/25Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nimble-users
Hi everyone, I am new to nimble and when I try to run MCMC with my likelihood I have problem with compile. This is my code:
#define custom likelihood:
dkl<-nimbleFunction(
run = function(x = double(0),
delta = double(2),
X = double(2),
Y = double(2),
log = integer(0, default = 0)) {
n_x <- dim(X)[1]
n_y <- dim(Y)[1]
p <- dim(X)[2]
sum_x <- 0
for (i in 1:n_x) {
row_X <- matrix(X[i, 1:p], nrow = 1)
plus<-row_X%*%delta
sum_x<-sum_x+inprod(plus,row_X)
}
sum_y <- 0
for (i in 1:n_y) {
row_Y <- matrix(Y[i, 1:p], nrow = 1)
plus<-row_Y%*%delta
sum_y<-sum_y+inprod(plus,row_Y)
}
loglik <- -sum_x / n_x + log(sum_y / n_y)
returnType(double(0))
if (log) return(-loglik) else return(exp(-loglik))
}
)
#build model:
model_code<-nimbleCode({
psi~dunif(0,1)
#Prior
for (i in 1:numvar){
for (j in 1:numvar){
z[i,j]~dbern(psi)
delta[i,j]~dnorm(0,sd=10)
zdelta[i,j]<-z[i,j]*delta[i,j]
}
}
target ~ dkl(delta = zdelta[1:numvar, 1:numvar], X[1:n_x,1:numvar] ,Y[1:n_y,1:numvar])
})
#constant and init
constants<-list(numvar=dim(X)[2],n_x=dim(X)[1],n_y=dim(Y)[1])
Inits <- list(psi = 0.5,
delta =matrix( rnorm(constants$numvar*constants$numvar),constants$numvar,constants$numvar),
z = matrix(0,constants$numvar,constants$numvar))
data<-list(X=X,Y=Y)
#registration distribution
registerDistributions(list(
dkl=list(
BUGSdist='dkl(delta,X,Y)',
types=c('value=double(0)','delta=double(2)',
'X=double(2)','Y=double(2)')
)
))
#compile model
model<-nimbleModel(code=model_code,constants=constants,inits=Inits,data=data)
conf<-configureMCMC(model)
conf$addMonitors('z')
mcmcRJ<-buildMCMC(conf)
cmodel<-compileNimble(model)
CMCMRJ<-compileNimble(mcmcRJ,project=model)
samples<-runMCMC(CMCMRJ,niter=10000,nburnin=1000)
*******************
and in step cmodel<-compileNimble(model) I received this message: Failed to create the shared library when compile NIMBLE.
Can anyone know how to fix this problem?