Add evaluate_compression function for assessing fidelity of compresse…#1
Merged
Conversation
…d posteriors - Introduced `evaluate_compression()` to quantify information loss in compressed posteriors using energy distance and classifier two-sample test (C2ST). - Updated documentation and vignettes to include usage examples and detailed explanations of the new metrics. - Added tests to ensure functionality and accuracy of the new evaluation method. - Enhanced pkgdown configuration to include a new vignette on evaluating compression fidelity.
There was a problem hiding this comment.
Pull request overview
Adds a new public API for evaluating how much fidelity is lost when compressing posteriors, along with documentation (README + vignette), tests, and pkgdown wiring so users can interpret and validate compression quality in a backend-agnostic way.
Changes:
- Introduces
evaluate_compression()(energy distance + C2ST) andprint.compression_fidelity. - Adds a new vignette and README section demonstrating “reproduction (%)” scoring and sanity checks.
- Adds unit tests covering object structure, metric behaviors, and the
ranger/kNN classifier paths.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
R/evaluate.R |
Implements evaluate_compression(), energy distance + C2ST metrics, and printing. |
tests/testthat/test-evaluate.R |
Adds test coverage for fidelity evaluation and classifier paths. |
vignettes/evaluate-compression.Rmd |
New vignette showing sanity checks and a correlation sweep. |
README.md |
Documents the new API and provides example output. |
DESCRIPTION |
Adds dependency entry related to classifier implementation. |
NAMESPACE |
Exports evaluate_compression() and registers S3 print method. |
man/evaluate_compression.Rd |
Generated documentation for the new function and print method. |
_pkgdown.yml |
Adds the new vignette to pkgdown articles list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
31
| rlang, | ||
| ranger | ||
| Suggests: |
| call. = FALSE) | ||
| } | ||
|
|
||
| if (!is.null(seed)) set.seed(seed) |
Comment on lines
+314
to
+321
| cv_folds <- max(2L, min(as.integer(cv_folds), n - 1L)) | ||
| folds <- sample(rep(seq_len(cv_folds), length.out = n)) | ||
|
|
||
| preds <- numeric(n) | ||
| for (k in seq_len(cv_folds)) { | ||
| test_idx <- which(folds == k) | ||
| train_idx <- which(folds != k) | ||
| if (length(test_idx) == 0L || length(train_idx) == 0L) next |
Comment on lines
+138
to
+141
| ```r | ||
| fidelity <- evaluate_compression(comp, reference_draws = draws) | ||
| fidelity | ||
| #> <compression_fidelity> |
Comment on lines
+153
to
+164
| test_that("ranger classifier path runs end-to-end", { | ||
| draws <- make_two_blob_draws() | ||
| comp <- compress_posterior(draws, method = "mclust", n_components = 2) | ||
|
|
||
| fid <- evaluate_compression( | ||
| comp, draws, | ||
| metric = "c2st", classifier = "ranger", | ||
| seed = 1L, max_n = 400L | ||
| ) | ||
| expect_equal(fid$metrics$c2st$classifier, "ranger") | ||
| expect_true(is.finite(fid$metrics$c2st$auc)) | ||
| }) |
- Added support for the `predict` function from the `stats` package in the `evaluate_compression` method. - Updated documentation to clarify the default classifier for the two-sample test (C2ST) as `ranger`, with an option for `knn`. - Revised vignettes and README to reflect changes in classifier usage and provide clearer examples. - Removed references to the deprecated "auto" classifier option in tests and documentation for consistency.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
evaluate_compression()to quantify information loss in compressed posteriors using energy distance and classifier two-sample test (C2ST).