Skip to content

Conversation

philipwosull
Copy link
Collaborator

Adding new sampling spaces, splitting methods, and smc weights among other things

Copy link
Member

@christopherkenny christopherkenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much closer. I've added more comments and some existing ones were not yet resolved. Thanks Philip.

std_err <- sd(run_means) / sqrt(max(chain) - 1) # be slightly conservative
}
}else{
cli::cli_abort("Can't do non-coda std errors for single MCMC chain!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be {.pkg coda}.

R/diagnostics.R Outdated
# ignore if not a supported algorithm
if(!algo %in% summary_supported_algs){
cli::cli_abort("{.fn summary} is not supported for the {toupper(algo)} algorithm.")
return(invisible(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return line doesn't ever get reached because it is after an abort.

all_splitting_methods <- sapply(all_run_info, function(x) x$split_method)
if(length(unique(all_splitting_methods)) != 1){
cli::cli_abort("{.fn summary} is not supported for plans sampled using different splitting methods")
return(invisible(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this return.

all_forward_kernel_params[[i]]$cut_k_used <- NULL
if(!identical(all_forward_kernel_params[[1]], all_forward_kernel_params[[i]])){
cli::cli_abort("{.fn summary} is not supported for plans sampled using different splitting parameters")
return(invisible(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one.


existing_col <- names(tidyselect::eval_select(rlang::enquo(existing_plan), x))
if (length(existing_col) == 0)
if (length(existing_col) == 0){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we just catching NULL or is this related to new features?

#' @param fn A function
#' @rdname constraints
#' @export
add_constr_custom_plan <- function(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait what's the difference between these two custom constraints now?

silent = silent
)

sampled_inidices <- sample.int(n = n_smc_nsims, size = chains, replace = F)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FALSE

control = list(),
adapt_k_thresh = .99) {

cli::cli_abort("redist_mergesplit_parallel is deprecated. Please call redist_mergesplit now.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be forwarding to the new redist_mergesplit with the special .Deprecated

# plans has n_precinct columns and n_sims rows
# map is a redist_map
# algorithm is one of "smc" or "mcmc"
# algorithm is one of "smc" or "mcmc" or "smc_ms
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing "

@@ -0,0 +1,29 @@
# C++ Redist Code Overview
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this file need to be added to the .Rbuildignore?

Copy link
Member

@CoryMcCartan CoryMcCartan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philipwosull when you run the formatter you have to match our existing formatting! 4-space indents among other things. That created a lot of diff noise that makes it hard to tell what substantively changed.

what is the status of devtools::check() at this point?

.Call(`_redist_calcPWDh`, x)
}

#'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to export these from c++ to R if they're not used by any package R code?

if we are going to keep them exported (f,rom c++) but internal, then I'd like to change the names, because people can still see these functions with ::: and the names are super verbose

std_err <- summary(mcmc)$statistics["Time-series SE"]
if (isTRUE(by_chain)) {
std_err <- std_err * sqrt(max(chain))
if(use_coda){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are also back to bad code formatting. Please fix the formatting throughout.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new summary() is incredibly long. Can we break this up into multiple functions? Not a blocker for internal use but I really worry about long-term maintainability

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still in this PR

Comment on lines -126 to -127
#' # One run with multiple cores
#' redist_smc(fl_map, 1000, ncores = 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is meant to demonstrate ncores not nproc. Add another example if you really want that, though I don't think we do want taht

weight_type = weight_type,
nproc = nproc,
ncores = ncores,
custom_size_split_list = list(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Papers:

- O'Sullivan, P., McCartan, C., & Imai, K. (Working Paper Forthcoming). Generalized Sequential Monte Carlo Sampling for Larger-scale Redistricting Problems.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(in preparation) would be the normal way to refer to this

#> Starting Chain 1
#> SEQUENTIAL MONTE CARLO
#> Sampling 500 99-unit maps with 4 districts and population between 760,827 and 762,350.
#> Using Graph Sampling space to sample 500 99-unit maps with 4 districts and population between 760827 and 762350.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philipwosull what did you find here? is it something to do with the format string?

Comment on lines +266 to +274
if (!missing(truncate)) {
cli::cli_abort("{.arg truncate} is deprecated. Do not use this argument.")
}
if (!missing(trunc_fn)) {
cli::cli_abort("{.arg truncate} is deprecated. Do not use this argument.")
}
if (!missing(final_infl)) {
cli::cli_abort("{.arg truncate} is deprecated. Do not use this argument.")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are hard deprecations then we should just remove them from the argument list!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christopherkenny I am fine with breaking changes for these args

@CoryMcCartan
Copy link
Member

@philipwosull when you get a chance, merge in main again which will hopefully get R CMD CHECK automatically running on here every time you push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants