Skip to content

Commit

Permalink
Add test for randomized n_step
Browse files Browse the repository at this point in the history
Also fix example code
  • Loading branch information
matt-graham committed Dec 5, 2024
1 parent 8f3913f commit 6d58bc6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/hamiltonian.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ log_density_ratio_hamiltonian <- function(
#'
#' # Proposal with number of steps randomly sampled uniformly from 5:10
#' sample_uniform_int <- function(lower, upper) {
#' lower + sample.int(upper - lower + 1) - 1
#' lower + sample.int(upper - lower + 1, 1) - 1
#' }
#' proposal <- hamiltonian_proposal(
#' target_distribution,
Expand Down
2 changes: 1 addition & 1 deletion man/hamiltonian_proposal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions tests/testthat/test-hamiltonian.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
hamiltonian_proposal_with_standard_normal_target <- function(n_step) {
hamiltonian_proposal_with_standard_normal_target <- function(
n_step, sample_n_step = NULL) {
function(scale = NULL, shape = NULL) {
hamiltonian_proposal(
target_distribution = standard_normal_target_distribution(),
n_step = n_step,
scale = scale,
shape = shape
shape = shape,
sample_n_step = sample_n_step
)
}
}
Expand Down Expand Up @@ -49,3 +51,13 @@ for (dimension in c(1L, 2L, 3L)) {
}
}
}

test_scale_and_shape_proposal(
hamiltonian_proposal_with_standard_normal_target(
n_step = c(1, 5),
sample_n_step = function(n) n[1] + sample.int(n[2] - n[1] + 1, 1) - 1
),
proposal_name = sprintf("Hamiltonian proposal with randomized n_step"),
dimensions = c(1L, 2L),
scales = c(0.5, 1., 2.)
)

0 comments on commit 6d58bc6

Please sign in to comment.