Skip to content
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

Exclude draws #336

Merged
merged 11 commits into from
Jan 15, 2024
Merged

Exclude draws #336

merged 11 commits into from
Jan 15, 2024

Conversation

n-kall
Copy link
Collaborator

@n-kall n-kall commented Jan 11, 2024

Summary

Adds an exclude option to subset_draws that will remove the matched draws. Addresses #333

TODO:

Tests

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

@codecov-commenter
Copy link

codecov-commenter commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (627d2e8) 95.00% compared to head (aafaf7d) 95.15%.
Report is 4 commits behind head on master.

❗ Current head aafaf7d differs from pull request most recent head f919ba1. Consider uploading reports for the commit f919ba1 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #336      +/-   ##
==========================================
+ Coverage   95.00%   95.15%   +0.15%     
==========================================
  Files          47       47              
  Lines        3744     3757      +13     
==========================================
+ Hits         3557     3575      +18     
+ Misses        187      182       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

This is how benchmark results would change (along with a 95% confidence interval in relative change) if e84ad9d is merged into master:

  •   :ballot_box_with_check:as_draws_array: 105ms -> 99.9ms [-15.58%, +5.36%]
  • ❗🐌as_draws_df: 34.6ms -> 80.6ms [+131.02%, +135.52%]
  •   :ballot_box_with_check:as_draws_list: 182ms -> 181ms [-0.87%, +0.37%]
  •   :rocket:as_draws_matrix: 30.2ms -> 29.4ms [-4.33%, -0.4%]
  •   :ballot_box_with_check:as_draws_rvars: 154ms -> 155ms [-1.13%, +1.81%]
  •   :ballot_box_with_check:summarise_draws_100_variables: 716ms -> 713ms [-0.99%, +0.17%]
  •   :ballot_box_with_check:summarise_draws_10_variables: 78.8ms -> 78.8ms [-0.6%, +0.47%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 15aaa65 is merged into master:

  •   :ballot_box_with_check:as_draws_array: 98.7ms -> 98.9ms [-0.6%, +0.97%]
  • ❗🐌as_draws_df: 31.3ms -> 79.8ms [+148.27%, +161.95%]
  • ❗🐌as_draws_list: 180ms -> 184ms [+1.33%, +2.86%]
  •   :ballot_box_with_check:as_draws_matrix: 28.7ms -> 29.2ms [-2.35%, +5.97%]
  •   :ballot_box_with_check:as_draws_rvars: 153ms -> 152ms [-2.11%, +1.17%]
  •   :ballot_box_with_check:summarise_draws_100_variables: 710ms -> 711ms [-0.83%, +1.1%]
  •   :ballot_box_with_check:summarise_draws_10_variables: 79ms -> 78ms [-3.37%, +0.64%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@n-kall
Copy link
Collaborator Author

n-kall commented Jan 11, 2024

I tried to change as little code as necessary to implement this. But I think this is now ready for review

Copy link
Collaborator

@paul-buerkner paul-buerkner left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. I have left a few rather small comments I think

#' iterations, or draws be allowed? If `TRUE` (the default) only
#' unique chains, iterations, and draws are selected regardless of
#' how often they appear in the respective selecting arguments.
#' @param exclude (logical) Should the selected subset be excluded?
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not just selection of draws but of variables etc. too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

R/subset_draws.R Outdated
@@ -55,6 +61,22 @@ subset_draws.draws_matrix <- function(x, variable = NULL, iteration = NULL,
iteration <- check_iteration_ids(iteration, x, unique = unique)
chain <- check_chain_ids(chain, x, unique = unique)
draw <- check_draw_ids(draw, x, unique = unique)

if (exclude) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please input check exclude via as_one_logical

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Keep forgetting to do this. I now added input checking into the check_* functions, as is done with the the other arguments regex and unique. This does mean that the inputs are not checked if all draw, iteration, variable, chain are NULL though

R/subset_draws.R Outdated
@@ -55,6 +61,22 @@ subset_draws.draws_matrix <- function(x, variable = NULL, iteration = NULL,
iteration <- check_iteration_ids(iteration, x, unique = unique)
chain <- check_chain_ids(chain, x, unique = unique)
draw <- check_draw_ids(draw, x, unique = unique)

if (exclude) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

given that this code needs to be repeated for every draws format? Should we perhaps have exclude handled inside check_existing_variables, check_iteration_ids etc? I think this would be cleaner actually

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I changed this

Copy link

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 03e88ac is merged into master:

  •   :ballot_box_with_check:as_draws_array: 100ms -> 100ms [-0.21%, +0.98%]
  • ❗🐌as_draws_df: 35.2ms -> 82.7ms [+130.4%, +139.98%]
  •   :ballot_box_with_check:as_draws_list: 182ms -> 181ms [-1.58%, +0.1%]
  •   :ballot_box_with_check:as_draws_matrix: 30.7ms -> 29.6ms [-7.62%, +0.26%]
  •   :ballot_box_with_check:as_draws_rvars: 156ms -> 156ms [-1.25%, +1.48%]
  •   :ballot_box_with_check:summarise_draws_100_variables: 714ms -> 711ms [-1.21%, +0.2%]
  •   :ballot_box_with_check:summarise_draws_10_variables: 78.8ms -> 79ms [-0.42%, +0.93%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link

This is how benchmark results would change (along with a 95% confidence interval in relative change) if e055c0a is merged into master:

  •   :ballot_box_with_check:as_draws_array: 101ms -> 100ms [-4.9%, +2.61%]
  • ❗🐌as_draws_df: 36.8ms -> 82.4ms [+95.73%, +151.47%]
  •   :ballot_box_with_check:as_draws_list: 184ms -> 183ms [-2.18%, +0.5%]
  •   :ballot_box_with_check:as_draws_matrix: 29.8ms -> 29.4ms [-5.26%, +2.1%]
  •   :ballot_box_with_check:as_draws_rvars: 157ms -> 155ms [-2.89%, +0.57%]
  •   :rocket:summarise_draws_100_variables: 719ms -> 714ms [-1.13%, -0.19%]
  •   :ballot_box_with_check:summarise_draws_10_variables: 78.6ms -> 78.5ms [-0.7%, +0.44%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link

This is how benchmark results would change (along with a 95% confidence interval in relative change) if aafaf7d is merged into master:

  •   :ballot_box_with_check:as_draws_array: 100ms -> 100ms [-1.4%, +1.51%]
  • ❗🐌as_draws_df: 31.4ms -> 81ms [+153.84%, +161.5%]
  •   :ballot_box_with_check:as_draws_list: 184ms -> 183ms [-2.28%, +0.98%]
  •   :ballot_box_with_check:as_draws_matrix: 28.9ms -> 28.8ms [-2.89%, +2.09%]
  •   :ballot_box_with_check:as_draws_rvars: 155ms -> 154ms [-2.93%, +1.04%]
  •   :ballot_box_with_check:summarise_draws_100_variables: 718ms -> 717ms [-0.91%, +0.71%]
  • ❗🐌summarise_draws_10_variables: 78.3ms -> 78.8ms [+0.01%, +1.21%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@n-kall
Copy link
Collaborator Author

n-kall commented Jan 15, 2024

@paul-buerkner I think I addressed your comments now, also added more tests

@paul-buerkner
Copy link
Collaborator

Perfect. Thank you!

@paul-buerkner paul-buerkner merged commit a63b894 into stan-dev:master Jan 15, 2024
9 of 10 checks passed
@n-kall n-kall deleted the exclude_draws branch January 16, 2024 10:54
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