Multivariate sample scores pair draws by row order, not by `sample_id`

オープン
#1,284 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
56/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
r
領域
data

調査の方向性

Start with score.forecast_multivariate_sample() and compare its row-order pairing with the ordering used by the quantile, nominal, and ordinal scoring methods. Reproduce the issue with the supplied forecast and shuffled rows, then inspect assert_forecast() to understand its sample checks. Done means joint draws are paired by sample_id (or consistently ordered with mismatched ID sets rejected) and the example scores identically after row shuffling.

索引モデルが issue の本文から書いたものです。

説明

as_forecast_multivariate_sample() takes a sample_id column, and a natural reading is that rows sharing a sample_id within a multivariate group form one joint draw. score() does not use it that way. In score.forecast_multivariate_sample(), the predictions for each forecast unit are collected in row order (predicted = list(predicted)), and the j-th prediction of every forecast unit in a group is treated as the same draw. sample_id is only used to count samples and to detect duplicates. So the same forecast gives a different score when its rows are in a different order.

Example: three draws that are joint across locations A and B. Each draw has the same value in both locations. Reversing the order of location B's rows changes the score, although the forecast is the same.

library(scoringutils)

# Three draws, each joint across locations A and B.
# Draw k has the same value in both locations.
forecast <- data.frame(
  model = "m",
  location = rep(c("A", "B"), each = 3),
  sample_id = rep(1:3, times = 2),
  observed = 10,
  predicted = c(1, 10, 20, 1, 10, 20)
)

# The same rows, with location B's rows in reverse order.
shuffled <- forecast[c(1, 2, 3, 6, 5, 4), ]

score(as_forecast_multivariate_sample(forecast, joint_across = "location"))$energy_score
#> [1] 2.985562
score(as_forecast_multivariate_sample(shuffled, joint_across = "location"))$energy_score
#> [1] 2.993827

With the shuffled rows, the first draw is scored as (A = 1, B = 20) instead of (A = 1, B = 1). The marginal distributions are unchanged, but the dependence between locations is not the one the forecaster submitted. Nothing warns about it, so data that is not sorted by sample_id within each forecast unit is silently scored as a different forecast.

The quantile, nominal and ordinal methods already order predictions by quantile_level or predicted_label before scoring (class-forecast-quantile.R:146, class-forecast-nominal.R:145, class-forecast-ordinal.R:151). The multivariate sample method has no equivalent.

Possible fixes:

  • Pair draws by sample_id within each multivariate group, and error when a sample_id is missing from some forecast units of the group. This also catches forecast units that have the same number of samples but different sample_ids. assert_forecast() checks only the number, so row order currently pairs those draws without warning.
  • Or, at minimum, order predictions by sample_id within each forecast unit before scoring, and document that every forecast unit in a group must have the same set of sample_ids.

Reproduced with scoringutils 2.3.0. The pairing by row order is also in score.forecast_multivariate_sample() on main (779d7d6).

We came across this in hubEvals (hubverse-org/hubEvals), which passes hub model output to as_forecast_multivariate_sample() and will order rows by sample ID on its side in the meantime.

主要言語
R
スター
68
フォーク
24
平均マージ
1時間 24分
マージ済み PR(30日)
2

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

epiforecasts/scoringutils のほかの issue

epiforecasts/scoringutils の issue をすべて見る

似ている issue

R の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。