Skip to content

Add evaluate_compression function for assessing fidelity of compresse…#1

Merged
stemangiola merged 2 commits into
mainfrom
evaluate-accuracy
May 7, 2026
Merged

Add evaluate_compression function for assessing fidelity of compresse…#1
stemangiola merged 2 commits into
mainfrom
evaluate-accuracy

Conversation

@stemangiola

@stemangiola stemangiola commented May 7, 2026

Copy link
Copy Markdown
Owner
  • 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.

…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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) and print.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 thread DESCRIPTION
Comment on lines +29 to 31
rlang,
ranger
Suggests:
Comment thread R/evaluate.R
call. = FALSE)
}

if (!is.null(seed)) set.seed(seed)
Comment thread R/evaluate.R
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 thread README.md
Comment on lines +138 to +141
```r
fidelity <- evaluate_compression(comp, reference_draws = draws)
fidelity
#> <compression_fidelity>
Comment thread tests/testthat/test-evaluate.R Outdated
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.
@stemangiola stemangiola merged commit 53d966b into main May 7, 2026
7 checks passed
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.

2 participants