-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_package.R
More file actions
93 lines (63 loc) · 2.01 KB
/
make_package.R
File metadata and controls
93 lines (63 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
library(devtools)
## NECESSARY:
## NEED TO HAVE DONE "build" bash command while on correct
## branch of nimble repository (currently: devel)
## create github actions testing
##library(usethis)
##use_github_action_check_standard()
setwd('~/github/nimble/nimbleHMC')
devtools::document('nimbleHMC')
devtools::build('nimbleHMC')
check('nimbleHMC')
suppressMessages(try(remove.packages('nimbleHMC'), silent = TRUE))
(tarFiles <- grep('\\.tar\\.gz', list.files(), value = TRUE))
(lastTarFile <- tarFiles[length(tarFiles)])
message('installing package version ', gsub('\\.tar\\.gz$', '', lastTarFile))
system(paste0('R CMD install ', lastTarFile))
##devtools::install('nimbleHMC')
q('no')
1
library(nimbleHMC)
library(testthat)
library(help=nimbleHMC)
sampler_langevin ## no longer exported, no documentation either
?sampler_langevin ## no longer exported, no documentation either
?langevin ## no longer exported, no documentation either
sampler_HMC
?sampler_HMC
?HMC
?hmc
citation('nimbleHMC')
nimbleOptions('enableDerivs')
##nimbleOptions(enableDerivs = TRUE)
##nimbleOptions('enableDerivs')
code <- nimbleCode({
b0 ~ dnorm(0, 0.001)
b1 ~ dnorm(0, 0.001)
sigma ~ dunif(0, 10000)
for(i in 1:N) {
mu[i] <- b0 + b1 * x[i]
y[i] ~ dnorm(mu[i], sd = sigma)
}
})
N <- 10
constants <- list(N = N, x = 1:N)
data <- list(y = 1:N)
inits <- list(b0=0, b1=10, sigma=100)
Rmodel <- nimbleModel(code, constants, data, inits, buildDerivs = TRUE)
conf <- configureMCMC(Rmodel)
conf$addSampler(target = c('b0', 'b1', 'sigma'), type = 'RW_block')
addHMC(conf, nodes = c('b0', 'b1', 'sigma'))
conf$printSamplers(byType = TRUE)
conf$printSamplers()
Rmcmc <- buildMCMC(conf)
Cmodel <- compileNimble(Rmodel)
Cmcmc <- compileNimble(Rmcmc, project = Rmodel)
##Cmcmc <- compileNimble(Rmcmc, project = Rmodel, showCompilerOutput = TRUE)
##printErrors()
set.seed(0)
samples <- runMCMC(Cmcmc, 10000)
samplesSummary(samples)
out <- nimbleHMC(Rmodel, niter = 2000, nchains = 2, WAIC = TRUE)
str(out$samples)
out$WAIC