-
Notifications
You must be signed in to change notification settings - Fork 65
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
Use adaptive hmc #779
Draft
njtierney
wants to merge
9
commits into
greta-dev:master
Choose a base branch
from
njtierney:adaptive-hmc-v3-i765
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Use adaptive hmc #779
+634
−37
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merge branch 'add-snaper-hmc' into adaptive-hmc-v2-i765 # Conflicts: # R/inference_class.R # tests/testthat/test_posteriors_geweke.R
…rror in trace_list_batches[[1]] : subscript out of bounds` - need to investigate further
…o do, but we are getting there!
library(greta)
#>
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#>
#> binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#>
#> %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#> eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#> tapply
library(tictoc)
x <- normal(0, c(0.1, 1, 10, 100))
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#>
m <- model(x)
tic()
draws_hmc <- mcmc(
model = m,
sampler = hmc()
)
#> running 4 chains simultaneously on up to 8 CPU cores
#>
#> warmup 0/1000 | eta: ?s warmup == 50/1000 | eta: 10s warmup ==== 100/1000 | eta: 5s warmup ====== 150/1000 | eta: 4s warmup ======== 200/1000 | eta: 3s warmup ========== 250/1000 | eta: 2s warmup =========== 300/1000 | eta: 2s warmup ============= 350/1000 | eta: 2s warmup =============== 400/1000 | eta: 2s warmup ================= 450/1000 | eta: 1s warmup =================== 500/1000 | eta: 1s warmup ===================== 550/1000 | eta: 1s warmup ======================= 600/1000 | eta: 1s warmup ========================= 650/1000 | eta: 1s warmup =========================== 700/1000 | eta: 1s warmup ============================ 750/1000 | eta: 1s warmup ============================== 800/1000 | eta: 0s warmup ================================ 850/1000 | eta: 0s warmup ================================== 900/1000 | eta: 0s warmup ==================================== 950/1000 | eta: 0s warmup ====================================== 1000/1000 | eta: 0s
#> sampling 0/1000 | eta: ?s sampling == 50/1000 | eta: 1s sampling ==== 100/1000 | eta: 1s sampling ====== 150/1000 | eta: 1s sampling ======== 200/1000 | eta: 1s sampling ========== 250/1000 | eta: 0s sampling =========== 300/1000 | eta: 0s sampling ============= 350/1000 | eta: 0s sampling =============== 400/1000 | eta: 0s sampling ================= 450/1000 | eta: 0s sampling =================== 500/1000 | eta: 0s sampling ===================== 550/1000 | eta: 0s sampling ======================= 600/1000 | eta: 0s sampling ========================= 650/1000 | eta: 0s sampling =========================== 700/1000 | eta: 0s sampling ============================ 750/1000 | eta: 0s sampling ============================== 800/1000 | eta: 0s sampling ================================ 850/1000 | eta: 0s sampling ================================== 900/1000 | eta: 0s sampling ==================================== 950/1000 | eta: 0s sampling ====================================== 1000/1000 | eta: 0s
toc()
#> 2.877 sec elapsed
par(mfrow = c(2, 4))
plot(draws_hmc, auto.layout = FALSE) tic()
draws_hmc_adapt <- mcmc(
model = m,
sampler = adaptive_hmc()
)
#> running 4 chains simultaneously on up to 8 CPU cores
#> sampling 0/1000 | eta: ?s sampling == 50/1000 | eta: 41s sampling ==== 100/1000 | eta: 20s sampling ====== 150/1000 | eta: 13s sampling ======== 200/1000 | eta: 9s sampling ========== 250/1000 | eta: 7s sampling =========== 300/1000 | eta: 5s sampling ============= 350/1000 | eta: 4s sampling =============== 400/1000 | eta: 4s sampling ================= 450/1000 | eta: 3s sampling =================== 500/1000 | eta: 2s sampling ===================== 550/1000 | eta: 2s sampling ======================= 600/1000 | eta: 2s sampling ========================= 650/1000 | eta: 1s sampling =========================== 700/1000 | eta: 1s sampling ============================ 750/1000 | eta: 1s sampling ============================== 800/1000 | eta: 1s sampling ================================ 850/1000 | eta: 0s sampling ================================== 900/1000 | eta: 0s sampling ==================================== 950/1000 | eta: 0s sampling ====================================== 1000/1000 | eta: 0s
toc()
#> 5.167 sec elapsed
plot(draws_hmc_adapt, auto.layout = FALSE) Created on 2025-03-12 with reprex v2.1.1
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #765