# 再現可能なベンチマーク／Възпроизводим бенчмарк／Reproducible benchmark — v1.5.0

**時刻ずれと実際の水素損失の区別（ディスペンサー配管、ラインインベントリ込みの質量収支・例示モデル）**
**Разминаване на часовниците срещу реална загуба на водород (линия на диспенсър, масов баланс с количеството газ в тръбата · примерен модел)**
**Clock misalignment vs. real hydrogen loss (dispenser line, line-inventory mass balance · illustrative model)**

Files / ファイル / Файлове: `mass_balance_clock.py` (Python 3, standard library only), `mass_balance_clock.mjs` (Node.js ≥ 18 or browser, ES module), `expected_output.json`, `SHA256SUMS.txt`.

```
python3 mass_balance_clock.py > out.json     # ~10 min
node mass_balance_clock.mjs   > out.json     # ~40 s
cmp out.json expected_output.json            # must be byte-identical (same seeds, PRNG, arithmetic and evaluation order)
```

All results are from an **illustrative model** (例示 / примерен модел). They are not properties of any real station, meter or alarm setting.

## English

**Question.** When can an outlet clock offset be told apart from a real leak in a line-inventory mass balance — and when it cannot, which additional information makes a reliable decision possible? Showing that one detector "wins" is not the goal; a negative result is an acceptable conclusion.

**Model.** R_W(t) = ∫_{t−W}^{t}(q_in − q_out) ds − [m_line(t) − m_line(t−W)], m_line = V·ρ(p,T), Abel–Noble ρ = p/(R·T + b·p) (b = 7.6921×10⁻³ m³/kg [90]), checked against NIST (Leachman EOS) [88][89]. W = 25 × 0.2 s = 5 s. Meter lags (flow τ 0.3 s, temperature τ 5 s), per-station fixed meter errors (±1.5 %, OIML R 139-1 class-2 **meter** [76]), Irwin–Hall noise. Timing faults kept separate: clock offset δ and drift; jitter (±0.1 s uniform per sample); late packets as **hold-last-value**; physical meter lag (τ_out = 1 s). Ordinary faults: frozen outlet meter (10 s), frozen pressure gauge (30 s), inlet meter-bias step (+2 %).

**Detectors.** A0 (flows only), A (inventory-corrected), B1/B2 (fixed first-order timing allowance u·|Δq|, u = 0.2/0.4 s — an approximation, not a bound), B3 (state-dependent u_t = 0.1 + 0.3·s(t), s from |Δq|, |Δp|, |Δm_line| over the window), C (1 s blocks, Bayesian recursive least squares on [1, Q, dQ/dt, dm_line/dt], two one-sided CUSUMs, κ = 0.5, frozen during ramps) [92][94], B4 (two-stage: B2 at a stage-1 threshold passing 20 % of clean calibration fills, then C) [93], B5 (GLR over a leak and an admissible outlet alignment of −2…+2 samples (±0.4 s) with a 0.1 s first-order remainder; one-sided positive/negative channels; 2-sample decision delay; "insufficient information" = no alarm only because an admissible offset explains the residual) [94]. EKF / profile likelihood [97][98] are **not** implemented (extension).

**Calibration protocol (explicit).** Thresholds are fixed in advance on clean (no-leak) calibration fills: seed 20261022, 100 other stations × 10 fills = 1000 fills per stratum, in each of the 7 declared clock-offset strata δ ∈ {−0.3, −0.2, −0.1, 0, 0.1, 0.2, 0.3} s. Threshold = max over strata of the (1 − 1 %) order statistic of the per-fill maximum statistic, i.e. an **equal nominal target on clean calibration data**. Test false-alarm rates are reported separately on other fills (seed 20261021, 50 stations × 8 = 400 fills per condition). For continuity, `thresholds0` / `res0` repeat the v1.4 protocol (δ = 0 stratum only). ROC points use thresholds at nominal targets 0.2–50 % and report the test FAR (`farTestWc` = worst declared test stratum, `farTest0` = δ = 0) and three outcomes per leak case: [any alarm, first alarm after onset, correct diagnosis (positive sign)].

**Uncertainty.** `ci95` = Wilson (independence assumed, kept for reference); `ciBoot` / `correctCiBoot` = station-cluster bootstrap (B = 1000, seed 20261023); `comparisons` = paired differences with the same resamples. Statistical only; model error is probed separately (EOS mismatch: truth = NIST-interpolated density, estimator = Abel–Noble). TTD median/P90 are over **detected cases only**; `undeliveredMean` = mean hydrogen not delivered when a fill is shut down.

**Fixes vs v1.4.** (1) Sensitivity bug: v1.4 did not regenerate populations per variant (MPE 2 %/3 % gave identical results, B2 5 % leak 78.5 % for every MPE). v1.5 regenerates with the same seeds; with δ = 0 calibration B2 detects 5 % leaks in 54.5 % (2 %) and 34.5 % (3 %) of fills. The v1.4 statement that MPE 2/3 % does not change conclusions is withdrawn. 2 %/3 % are OIML **system** MPEs and are applied per meter only as a stress case. (2) ROC separates any alarm / first alarm after onset / correct diagnosis and uses separate negative test fills. (3) Wording: first-order allowance (not a bound); hold-last-value; 100 % alarms under meter lag show that these detectors fail, not fundamental indistinguishability; jitter implemented; drift: B2 was 39.75 % in v1.4 (not "≈100 %"). (4) Station-cluster bootstrap. (5) The "distinguishability map" is a **performance map of one classifier** (80 fills/cell, 50 stations, leak present from the start, whole-fill least squares) plus online detectors. (6) Added B3, B4, B5, C, EOS mismatch, value of added measurements, cost view.

**Results (primary calibration, 400 test fills per condition).**

| Condition | A0 | A | B1 | B2 | B3 | B4 | B5 | C |
|---|---|---|---|---|---|---|---|---|
| FA δ = 0 | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA δ = +0.1 s | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA δ = −0.1 s | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA δ = +0.2 s | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA δ = +0.3 s | 0 % | 0.5 % | 0 % | 0.5 % | 0.75 % | 0.25 % | 0 % | 0.25 % |
| FA δ = −0.3 s | 0.75 % | 1 % | 1.5 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA δ = +0.5 s | 76.25 % | 81.5 % | 100 % | 99.75 % | 99 % | 40 % | 8.25 % | 37 % |
| FA drift | 46.75 % | 57 % | 68.75 % | 35.75 % | 31.25 % | 26.75 % | 13.25 % | 28 % |
| FA jitter ±0.1 s | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA hold-last-value 5 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % | 0 % |
| FA meter lag τ 1 s | 100 % | 100 % | 100 % | 100 % | 100 % | 1.5 % | 100 % | 0.75 % |
| FA frozen outlet meter | 13.75 % | 13.5 % | 15.75 % | 17.25 % | 17 % | 22.25 % | 18 % | 30 % |
| FA frozen pressure gauge | 0 % | 1 % | 65.25 % | 99.5 % | 98.5 % | 92.5 % | 99.75 % | 95 % |
| FA meter-bias step | 0 % | 0 % | 0 % | 13 % | 3.5 % | 59.5 % | 24.25 % | 82 % |
| 2 % leak, δ 0 s: correct / 400 | 0 | 0 | 0 | 36 | 1 | 223 | 64 | 322 |
| 2 % leak, δ 0.2 s: correct / 400 | 0 | 0 | 0 | 36 | 1 | 227 | 64 | 326 |
| 5 % leak, δ 0 s: correct / 400 | 0 | 2 | 98 | 307 | 252 | 387 | 320 | 386 |
| 5 % leak, δ 0.2 s: correct / 400 | 0 | 0 | 0 | 305 | 250 | 386 | 320 | 387 |
| 2 % leak: TTD median (detected only) | — | — | — | 56.5 s | 153.0 s | 5.3 s | 41.7 s | 4.4 s |
| 2 % leak: mean mass lost | 34.2 g | 34.2 g | 34.2 g | 33.0 g | 34.2 g | 19.1 g | 31.4 g | 10.6 g |
| 5 % leak: mean mass lost | 85.5 g | 85.5 g | 85.5 g | 40.6 g | 50.0 g | 11.4 g | 34.9 g | 7.3 g |
| cal0 (δ = 0 only): 2 % leak correct / 400 | 57 | 280 | 65 | 66 | 64 | 256 | 64 | 360 |
| cal0: FA δ = +0.2 s | 95.5 % | 100 % | 13.75 % | 0 % | 0.25 % | 5.75 % | 0 % | 10 % |

**Answer.** B3 does **not** recover small-leak detection (negative result). B4 does (2 %: 223/400 vs B2 36/400) and keeps false alarms ≤ 0.25 % inside the declared ±0.3 s range, and is more robust outside it (+0.5 s 40 % vs 99.75 %; meter lag 1.5 % vs 100 %), but raises alarms on 59.5 % of fills with a meter-bias step (it reads a meter fault as a leak) and detects a leak present from the start of the fill much less often (16 % at 2 % in the map). C alone is more sensitive still and more fault-prone (bias step 82 %). B5 is close to B2 at δ ≤ 0.3 s but robust at +0.5 s (8.25 %).

**Limitations.** Offset and leak interact: at δ = −0.3 s the offset residual adds to the leak residual, so "correct" detections of A0/A/B1 rise (2 %: A0 166/400) without any real gain in leak sensitivity; at +0.3 s they cancel (10 % leak: A0 29/400). The nominal target holds on calibration data; test FAR can exceed it (B1 1.5 % at δ = −0.3 s, A 1 %). A frozen pressure gauge breaks every inventory-corrected detector except A at its high threshold (B2–C 92.5–99.75 %). The leak does not affect pressure in this model, so an independent P/T confirmation cannot be evaluated. OFAT sensitivity only. The declared range ±0.3 s and all offsets are scenarios; source [65] does not establish thresholds for hydrogen equipment.

## 日本語（要点）

**問い：** 時刻ずれと漏えいはどの条件で区別できるか。区別できない条件では、どの追加情報が判定を可能にするか。特定の判定法が勝つことは目的ではなく、否定的な結果も結論として認めます。

**較正の手順：** すべての手法のしきい値を、評価とは別の種（20261022）・別の100ステーションの漏えいのない充填で、宣言した時刻ずれの7層（−0.3～+0.3 s、各1000回）のうち最も厳しい層で、1回以上の警報の割合が1％になるよう事前に決めます（漏えいのない較正データ上で等しい名目上の目標）。評価用の誤警報率は別の充填（種 20261021、400回）で報告します。v1.4 と同じ δ = 0 のみの較正（`res0`）も示します。

**判定法：** A0・A・B1・B2（一定の許容幅 u·|Δq|、一次近似であり上限ではない）、B3（状態依存の許容幅 u_t）、C（1 s ブロックの片側 CUSUM、正・負の2系統）［92］［94］、B4（2段階：B2 を低いしきい値で使い、C で確認）［93］、B5（漏えいと ±0.4 s の時刻ずれの GLR、「情報不足」を出力）［94］。EKF・プロファイル尤度［97］［98］は実装していません（発展課題）。

**v1.4 からの修正：** 感度分析で母集団が再生成されない誤りを修正（v1.4 の「MPE 2／3％でも結論は変わらない」は撤回。修正後、δ = 0 較正の B2 の5％漏えいの検知は 54.5％・34.5％）。ROC を3つの結果に分離。用語（一次近似、hold-last-value、計器の遅れは判定法の失敗）。ジッターを実装。ドリフトの記述を修正（v1.4 の B2 は 39.75％）。ステーション単位のブートストラップ。区別可能性マップを「特定の分類器の性能マップ」と改称。

**結論：** B3 は小さな漏えいの検知を改善しませんでした（否定的な結果）。B4 は改善し（2％で 223/400、B2 は 36/400）、宣言した範囲内の誤警報は 0.25％以下でしたが、計量器の誤差の段階変化で 59.5％が警報となり、開始時からの漏えいには弱くなります。

## Български (накратко)

**Въпрос:** при какви условия разминаването може да се различи от теч и, когато не може, каква допълнителна информация прави решението възможно. Целта не е определен метод да „спечели“; отрицателен резултат също е допустим извод.

**Калибриране:** праговете на всички методи се определят предварително върху зареждания без теч (начална стойност 20261022, 100 други станции) в 7 слоя на декларираното разминаване (−0,3 до +0,3 s, по 1000), така че в най-лошия слой делът с поне една тревога да е 1 % (еднаква номинална цел върху чисти данни). Фалшивите тревоги се докладват отделно върху тестови зареждания (начална стойност 20261021, 400). Калибрирането от v1.4 (само δ = 0, `res0`) също е показано.

**Методи:** A0, A, B1, B2 (постоянен допуск u·|Δq| — приближение от първи ред, не граница), B3 (адаптивен допуск u_t), C (едностранни CUSUM в блокове от 1 s, положителен и отрицателен канал) [92][94], B4 (двустепенен: B2 с по-нисък праг, после C) [93], B5 (GLR за теч и разминаване ±0,4 s, с изход „недостатъчна информация“) [94]. EKF и профилно правдоподобие [97][98] не са реализирани (развитие).

**Поправки спрямо v1.4:** популациите в анализа на чувствителността вече се генерират наново (твърдението от v1.4, че при MPE 2/3 % изводите не се променят, се оттегля; при cal0 B2 открива теч 5 % в 54,5 % и 34,5 %). ROC с три изхода. Термини (приближение от първи ред, hold-last-value, закъснението на уреда е неуспех на детектора). Добавен джитър. Поправено твърдението за дрейфа (B2 във v1.4 — 39,75 %). Клъстерен бутстрап по станции. Картата е преименувана на карта на ефективността на конкретен класификатор.

**Извод:** B3 не подобрява откриването на малки течове (отрицателен резултат). B4 го подобрява (2 %: 223/400 срещу 36/400 при B2) при фалшиви тревоги до 0,25 % в декларирания диапазон, но дава 59,5 % тревоги при скок в грешката на разходомера и е по-слаб при теч от началото на зареждането.

## Sources / 出典 / Източници (numbering as in the project document)

- [65] M. Han, P. Crossley — Vulnerability of IEEE 1588 under Time Synchronization Attacks. IEEE PES GM 2019 (power systems; no hydrogen thresholds).
- [73][74][75] SAE J2601 training material; U.S. DOE FCTO webinar (60 g/s); CARB in-use study (2024).
- [76] OIML R 139-1:2018 — Compressed gaseous fuel measuring systems for vehicles, Part 1, Table 1.
- [88] NIST Chemistry WebBook, SRD 69 (normal hydrogen, retrieved 21 Oct 2026). [89] J. W. Leachman et al., J. Phys. Chem. Ref. Data 38 (2009) 721–748. [90] R. W. Schefer et al., Int. J. Hydrogen Energy 32 (2007) 2081–2093.
- [91] API RP 1130, Computational Pipeline Monitoring for Liquids, 2nd ed., 2022.
- [92] E. S. Page — Continuous Inspection Schemes. Biometrika 41 (1954) 100–115. https://doi.org/10.1093/biomet/41.1-2.100
- [93] A. Wald — Sequential Tests of Statistical Hypotheses. Ann. Math. Stat. 16 (1945) 117–186. https://doi.org/10.1214/aoms/1177731118
- [94] M. Basseville, I. V. Nikiforov — Detection of Abrupt Changes: Theory and Application. Prentice Hall, 1993.
- [95] L. Zhang, S. Wang, Y. Wang, C. Decès-Petit — Hydrogen Mass Balance of Hydrogen Refuelling Stations in British Columbia, Canada. NRC-EME-56557, 2023. https://doi.org/10.4224/40003216
- [96] L. Zhang et al. — Holistic Idle Periodic Evaluation method for mass balance monitoring at hydrogen refuelling stations. Int. J. Hydrogen Energy 97 (2025) 66–75 (bibliographic details only). https://doi.org/10.1016/j.ijhydene.2024.11.292
- [97] S. Särkkä — Bayesian Filtering and Smoothing. Cambridge University Press, 2013. [98] A. Raue et al. — Bioinformatics 25 (2009) 1923–1929.

License: MIT.
