Skip to content

1257: Match multivariate samples by sample_id - #1279

Draft
nikosbosse wants to merge 3 commits into
mainfrom
issue-1257-multivariate-sample-id
Draft

nikosbosse wants to merge 3 commits into
mainfrom
issue-1257-multivariate-sample-id

Conversation

@nikosbosse

@nikosbosse nikosbosse commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

CLAUDE:

Description

This PR closes #1257.

score() for multivariate sample forecasts built the joint samples by row position: the j-th row of each forecast in a group became the j-th joint sample, and sample_id was never used. The same data in a different row order therefore gave different (wrong) energy and variogram scores, without a warning. The example data only score correctly because they happen to be sorted.

Changes:

  • score.forecast_multivariate_sample() orders the samples of each forecast by sample_id before building the matrices, so samples with the same id are matched across the forecasts of a group. The order of the rows in the output is unchanged.
  • assert_forecast.forecast_multivariate_sample() now errors if the forecasts of a group do not have the same sample ids, since joint samples are then undefined. Sample ids may still differ between groups.
  • The constructor documentation and the multivariate vignette describe this; the vignette previously said that scoringutils "handles this appropriately".

Behaviour change to be aware of: data in which the forecasts of a group use different sample ids (for example ids that are unique across the whole data set) were accepted before and now raise an error. Their scores depended on row order before.

Checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have included the target issue or issues in the PR title as follows: issue-number: PR title
  • I have tested my changes locally. Full test suite: 0 failures, 1051 passes.
  • I have added or updated unit tests where necessary. New tests: scores are compared with scoringRules::es_sample() on ordered and shuffled data (also for the example data), and mismatching sample ids within a group raise an error. I ran them against the unfixed code first, where 6 expectations fail.
  • I have updated the documentation if required. Constructor docs and vignette updated.
  • I have built the package locally and run rebuilt docs using roxygen2. The affected Rd file was edited by hand to match the roxygen source, because my local roxygen2 (8.0.0) differs from the version in DESCRIPTION (8.1.0) and would rewrite unrelated files.
  • My code follows the established coding standards and I have run lintr::lint_package() to check for style issues introduced by my changes. Linted the changed files, no lints.
  • I have added a news item linked to this PR.
  • I have reviewed CI checks for this PR and addressed them as far as I am able.

Adversarial review

An independent agent reviewed the PR. On 200 random data sets (1-3 models, 2-4 locations, 5-20 samples, integer, character, factor and non-contiguous ids, shuffled rows, keyed tables) the branch matched scoringRules::es_sample() / vs_sample() every time, where main mismatched all 200. Validation time on 1e6 rows is unchanged, and typical operations on a valid object (head(), filtering) are not newly rejected.

Addressed:

  • Sorting the whole table by sample_id could change the order of the output rows. Samples are now ordered within each forecast, which keeps the output order (with a test).
  • The comment on the new check gave the wrong reason for sample ids being unique within a forecast unit.
  • Tests: no more in-place modification of test data; character sample ids and the reported group are now covered.

Not addressed here: missing predictions. Validation runs before rows with NA values are removed, so if different samples are missing in different forecasts of a group, the remaining samples are still paired by position. That is the subject of #1258 / PR #1280, which removes such incomplete forecasts before scoring. The two PRs touch the same function, so the second one to merge needs main merged in.

🤖 Generated with Claude Code

nikosbosse and others added 2 commits November 10, 2026 23:24
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.19%. Comparing base (779d7d6) to head (a405eea).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1279   +/-   ##
=======================================
  Coverage   99.18%   99.19%           
=======================================
  Files          41       41           
  Lines        2331     2347   +16     
=======================================
+ Hits         2312     2328   +16     
  Misses         19       19           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Multivariate scores depend on row order: sample_id is ignored when building joint samples

1 participant