From 8d033b36bebd11a372b3326285ac14fb4178cadf Mon Sep 17 00:00:00 2001 From: Matt Graham Date: Fri, 2 Aug 2024 17:51:47 +0100 Subject: [PATCH] Fix pre-commit errors in existing files --- R/barker.R | 14 ++++++-------- R/kernels.R | 6 +++--- _pkgdown.yml | 1 - tests/testthat/test-langevin.R | 3 ++- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/R/barker.R b/R/barker.R index eb0185e..d90312a 100644 --- a/R/barker.R +++ b/R/barker.R @@ -52,16 +52,14 @@ log_density_ratio_barker <- function( scale_and_shape) { sum( log1p_exp( - state$momentum() - * ( - Matrix::drop(Matrix::t(scale_and_shape)) - * state$gradient_log_density(target_distribution) + state$momentum() * Matrix::drop( + Matrix::t(scale_and_shape) * + state$gradient_log_density(target_distribution) ) ) - log1p_exp( - proposed_state$momentum() - * ( - Matrix::drop(Matrix::t(scale_and_shape)) - * proposed_state$gradient_log_density(target_distribution) + proposed_state$momentum() * Matrix::drop( + Matrix::t(scale_and_shape) * + proposed_state$gradient_log_density(target_distribution) ) ) ) diff --git a/R/kernels.R b/R/kernels.R index a983919..0aa5427 100644 --- a/R/kernels.R +++ b/R/kernels.R @@ -32,9 +32,9 @@ sample_metropolis_hastings <- function( sample_uniform = stats::runif) { proposed_state <- proposal$sample(state) log_accept_ratio <- ( - proposed_state$log_density(target_distribution) - - state$log_density(target_distribution) - + proposal$log_density_ratio(state, proposed_state) + proposed_state$log_density(target_distribution) - + state$log_density(target_distribution) + + proposal$log_density_ratio(state, proposed_state) ) accept_prob <- if (is.nan(log_accept_ratio)) 0 else min_1_exp(log_accept_ratio) if (sample_uniform(1) < accept_prob) { diff --git a/_pkgdown.yml b/_pkgdown.yml index bf2c1ed..3bfe232 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,3 @@ url: http://github-pages.ucl.ac.uk/rmcmc/ template: bootstrap: 5 - diff --git a/tests/testthat/test-langevin.R b/tests/testthat/test-langevin.R index 83bfc03..659d0fb 100644 --- a/tests/testthat/test-langevin.R +++ b/tests/testthat/test-langevin.R @@ -17,7 +17,8 @@ for (dimension in c(1L, 2L, 3L)) { sprintf( "Langevin involution is an involution (dimension %i, scale %.1f)", dimension, scale - ), { + ), + { target_distribution <- standard_normal_target_distribution() withr::with_seed(seed = default_seed(), { state <- chain_state(