File size: 709 Bytes
fc329a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Global split conformal prediction."""
import numpy as np
from .base import ConformalResult
from ._split_quantile import split_conformal_quantile


def global_split_conformal(
    R_cal: np.ndarray,
    R_test: np.ndarray,
    alpha: float,
) -> ConformalResult:
    """Standard split conformal with a single global threshold.
    
    Args:
        R_cal: calibration residuals (n_cal,)
        R_test: test residuals (n_test,)
        alpha: miscoverage level
    
    Returns:
        ConformalResult
    """
    q = split_conformal_quantile(R_cal, alpha)
    covered = R_test <= q
    radius = np.full_like(R_test, q, dtype=float)
    return ConformalResult(covered=covered, radius=radius, threshold=q)