From c2cd7214692be3fe81ebfc2c39e6735c52ee2ccc Mon Sep 17 00:00:00 2001 From: "Philip W. O'Sullivan" <97004864+philipwosull@users.noreply.github.com> Date: Fri, 20 Dec 2024 03:14:26 -0500 Subject: [PATCH 1/3] Update redist_ms.R Adds total number of prethinned sims, thin, and warmup sims for non-parallel mergesplit --- R/redist_ms.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/redist_ms.R b/R/redist_ms.R index 87c525a0..bd57013c 100644 --- a/R/redist_ms.R +++ b/R/redist_ms.R @@ -223,7 +223,10 @@ redist_mergesplit <- function(map, nsims, warmup_idx <- c(seq_len(1 + warmup %/% thin), ncol(algout$plans)) l_diag <- list( - runtime = as.numeric(t2_run - t1_run, units = "secs") + runtime = as.numeric(t2_run - t1_run, units = "secs"), + prethinned_sims = nsims, + thin = thin, + warmup = warmup ) From 91a153442c26f88d9609588e8ea8eb31cbf4a272 Mon Sep 17 00:00:00 2001 From: "Philip W. O'Sullivan" <97004864+philipwosull@users.noreply.github.com> Date: Fri, 20 Dec 2024 03:18:03 -0500 Subject: [PATCH 2/3] Update redist_ms_parallel.R Adds total number of prethinned sims, thin, and warmup sims for non-parallel mergesplit --- R/redist_ms_parallel.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/redist_ms_parallel.R b/R/redist_ms_parallel.R index a6a750ed..5fe7e386 100644 --- a/R/redist_ms_parallel.R +++ b/R/redist_ms_parallel.R @@ -216,7 +216,10 @@ redist_mergesplit_parallel <- function(map, nsims, chains = 1, t2_run <- Sys.time() algout$l_diag <- list( - runtime = as.numeric(t2_run - t1_run, units = "secs") + runtime = as.numeric(t2_run - t1_run, units = "secs"), + prethinned_sims = nsims, + thin = thin, + warmup = warmup ) algout$mh <- mean(as.logical(algout$mhdecisions)) From 800cb15908e8d26693471b77464ddff99ca8face Mon Sep 17 00:00:00 2001 From: "Philip W. O'Sullivan" <97004864+philipwosull@users.noreply.github.com> Date: Fri, 20 Dec 2024 03:21:15 -0500 Subject: [PATCH 3/3] Update merge_split.cpp Fixed issue with indexing bug when thin doesn't divide nsims nicely --- src/merge_split.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/merge_split.cpp b/src/merge_split.cpp index f0e1d814..2ac1f73c 100644 --- a/src/merge_split.cpp +++ b/src/merge_split.cpp @@ -30,12 +30,13 @@ Rcpp::List ms_plans(int N, List l, const uvec init, const uvec &counties, const int V = g.size(); int n_cty = max(counties); - int n_out = N/thin + 2; + int rounded_up_N_over_thin = std::ceil(static_cast(std::max(1, N-1))/thin); + int n_out = rounded_up_N_over_thin + 2; umat districts(V, n_out, fill::zeros); districts.col(0) = init; districts.col(1) = init; - Rcpp::IntegerVector mh_decisions(N/thin + 1); + Rcpp::IntegerVector mh_decisions(rounded_up_N_over_thin + 1); double mha; double tol = std::max(target - lower, upper - target) / target;