-
Notifications
You must be signed in to change notification settings - Fork 4
Kuiper cleanup 3/n - Remove kuiper_distribution
#162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
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
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 23, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 23, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 23, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Differential Revision: D91298776
4b76d2a to
968bfa5
Compare
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 23, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 23, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Differential Revision: D91298776
1aa052f to
5eb48b4
Compare
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
5eb48b4 to
2667aa1
Compare
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: Pull Request resolved: facebookincubator#162 * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
2667aa1 to
8f9dd83
Compare
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
8f9dd83 to
7acce8a
Compare
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
…lue (facebookincubator#160) Summary: Introduces a cleaner public API for Expected Cumulative Calibration Error (ECCE) metrics. The new ecce(), ecce_sigma(), and ecce_pvalue() functions provide simplified interfaces to the existing kuiper calibration functionality, making the API more intuitive for users who want to compute calibration errors without needing to understand the underlying Kuiper test implementation details. Deprecation of old versions of the functions will come in follow up diffs. ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: TaXxER Differential Revision: D91235672
Summary: Removes the public `kuiper_calibration` function and updates internal callers to use the new ECCE API or lower-level functions directly. ### Changes **Removed:** - `kuiper_calibration()` - wrapper function that computed Kuiper calibration distance **Refactored:** - `kuiper_test()` - now calls `ecce_sigma()` directly instead of `kuiper_calibration(..., normalization_method="kuiper_standard_deviation")` [Note: this function will be removed in a future commit] - `ecce()` - now calls `kuiper_calibration_per_segment(...).item()` directly instead of going through `kuiper_calibration()` - `ecce_sigma()` - now calls `kuiper_calibration_per_segment(...).item()` directly instead of going through `kuiper_calibration()` ### Rationale This is part of a cleanup series migrating from the legacy "kuiper" naming to the cleaner "ECCE" (Expected Cumulative Calibration Error) API. The `kuiper_calibration` function was just a thin wrapper that called `kuiper_calibration_per_segment().item()`, so callers now use that pattern directly. ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91235674
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
7acce8a to
8d93aca
Compare
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
flinder
added a commit
to flinder/MCGrad-1
that referenced
this pull request
Jan 26, 2026
) Summary: * Remove the function `kuiper_distribution` and replace with private helper `_ecce_cdf` * Add public helper `ecce_pvalue_from_sigma()` to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logic * Rename constants `KUIPER_STATISTIC_MIN/MAX` to `ECCE_SIGMA_MIN/MAX` * Refactor all internal usages (`kuiper_test`, `ecce_pvalue`, `MulticalibrationError.p_value`, `MulticalibrationError.segment_p_values`) to use the new helpers * Update external call site in swisscheese `mce.py` to use `ecce_pvalue_from_sigma` ------------------------------------- Target API design ------------------------------------- ``` ┌─────────────────────────────────────────────────────────────────────────────────┐ │ ECCE API ARCHITECTURE │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ PUBLIC API (User-Facing) ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ ┌─────────────┐ ┌──────────────┐ ┌──────────────────────────┐ ║ │ │ ║ │ ecce() │ │ ecce_sigma() │ │ ecce_pvalue() │ ║ │ │ ║ │ │ │ │ │ │ ║ │ │ ║ │ Unnormalized│ │ Normalized │ │ P-value for │ ║ │ │ ║ │ calibration │───▶│ by std dev │───▶│ calibration test │ ║ │ │ ║ │ error │ │ (sigma) │ │ │ ║ │ │ ║ └──────┬──────┘ └──────┬───────┘ └────────────┬─────────────┘ ║ │ │ ║ │ │ │ ║ │ │ ╚══════════╪══════════════════╪═════════════════════════╪══════════════════╝ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌──────────────────────────┐ │ │ │ │ │ ecce_pvalue_from_sigma()│ │ │ │ │ │ (public helper) │ │ │ │ │ └────────────┬─────────────┘ │ │ │ │ │ │ │ ┌──────────┴──────────────────┴────────────────────────┴───────────────────┐ │ │ │ PRIVATE HELPERS │ │ │ ├──────────────────────────────────────────────────────────────────────────┤ │ │ │ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _calculate_cumulative_ │ │ _ecce_cdf() │ │ │ │ │ │ differences() │ │ │ │ │ │ │ │ │ │ CDF for Brownian motion │ │ │ │ │ │ Core computation of weighted │ │ range (for p-value calc) │ │ │ │ │ │ cumulative differences │ │ │ │ │ │ │ └───────────────┬────────────────┘ └─────────────────────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌────────────────────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_per_segment() │ │ _ecce_standard_deviation() │ │ │ │ │ │ │ │ │ │ │ │ │ │ Vectorized ECCE computation │ │ Wrapper → calls per_segment│ │ │ │ │ │ for multiple segments │ │ version with .item() │ │ │ │ │ └────────────────────────────────┘ └──────────────┬──────────────┘ │ │ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │ │ _ecce_standard_deviation_ │ │ │ │ │ │ per_segment() │ │ │ │ │ │ │ │ │ │ │ │ Variance-based std dev │ │ │ │ │ │ for multiple segments │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ╔═══════════════════════════════════════════════════════════════════════════╗ │ │ ║ MulticalibrationError Class ║ │ │ ╠═══════════════════════════════════════════════════════════════════════════╣ │ │ ║ ║ │ │ ║ Computes calibration metrics across multiple data segments ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Cached Properties │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_ecces_absolute ──────────▶ _ecce_per_segment() │ ║ │ │ ║ │ (ECCE per segment) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_sigmas ──────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (std dev per segment) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ sigma_0 ─────────────────────────▶ _ecce_standard_deviation_ │ ║ │ │ ║ │ (global std dev) per_segment() │ ║ │ │ ║ │ │ ║ │ │ ║ │ p_value ─────────────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (min p-value across segments) │ ║ │ │ ║ │ │ ║ │ │ ║ │ segment_p_values ────────────────▶ ecce_pvalue_from_sigma() │ ║ │ │ ║ │ (p-value per segment) (vectorized) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ║ ┌─────────────────────────────────────────────────────────────────────┐ ║ │ │ ║ │ Derived Metrics │ ║ │ │ ║ ├─────────────────────────────────────────────────────────────────────┤ ║ │ │ ║ │ │ ║ │ │ ║ │ mce = max(segment_ecces_absolute) │ ║ │ │ ║ │ mce_sigma_scale = max(segment_ecces_absolute / segment_sigmas) │ ║ │ │ ║ │ mce_relative = mce / ecce_0 (normalized by global ECCE) │ ║ │ │ ║ │ │ ║ │ │ ║ └─────────────────────────────────────────────────────────────────────┘ ║ │ │ ║ ║ │ │ ╚═══════════════════════════════════════════════════════════════════════════╝ │ │ │ └─────────────────────────────────────────────────────────────────────────────────┘ ``` Reviewed By: Lorenzo-Perini Differential Revision: D91298776
|
This pull request has been merged in 9cfdca1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Summary:
Remove the function
kuiper_distributionand replace with private helper_ecce_cdfAdd public helper
ecce_pvalue_from_sigma()to compute p-value from sigma-scaled ECCE statistic, encapsulating the min/max checking logicRename constants
KUIPER_STATISTIC_MIN/MAXtoECCE_SIGMA_MIN/MAXRefactor all internal usages (
kuiper_test,ecce_pvalue,MulticalibrationError.p_value,MulticalibrationError.segment_p_values) to use the new helpersUpdate external call site in swisscheese
mce.pyto useecce_pvalue_from_sigmaTarget API design
Differential Revision: D91298776