Validate bin edges for Piecewise Exponential CIF Loss to ensure at least two finite edges and correct starting point

This commit is contained in:
2026-01-18 20:54:47 +08:00
parent 6de2132e84
commit d13fa430b7

View File

@@ -10,6 +10,7 @@ Implements the comprehensive evaluation framework defined in evaluate_design.md:
import argparse import argparse
import json import json
import math
import os import os
import time import time
from pathlib import Path from pathlib import Path
@@ -1571,9 +1572,22 @@ def load_model_and_config(run_dir: str, device: str = 'cuda') -> Tuple:
lambda_reg=config.get('lambda_reg', 0.0), lambda_reg=config.get('lambda_reg', 0.0),
) )
elif config['loss_type'] == 'pwe_cif': elif config['loss_type'] == 'pwe_cif':
# Piecewise-exponential (PWE) requires a FINITE last edge.
# If bin_edges ends with +inf (default), drop it and train up to the last finite edge.
raw_edges = config.get(
'bin_edges', [0.0, 0.24, 0.72, 1.61, 3.84, 10.0, 31.0, float('inf')])
pwe_edges = [float(x) for x in raw_edges if math.isfinite(float(x))]
if len(pwe_edges) < 2:
raise ValueError(
"pwe_cif requires at least 2 finite bin edges (including 0). "
f"Got bin_edges={list(raw_edges)}"
)
if pwe_edges[0] != 0.0:
raise ValueError(
f"pwe_cif requires bin_edges[0]==0.0; got {pwe_edges[0]}"
)
loss_fn = PiecewiseExponentialCIFNLLLoss( loss_fn = PiecewiseExponentialCIFNLLLoss(
bin_edges=config.get( bin_edges=pwe_edges,
'bin_edges', [0.0, 0.24, 0.72, 1.61, 3.84, 10.0, 31.0]),
lambda_reg=config.get('lambda_reg', 0.0), lambda_reg=config.get('lambda_reg', 0.0),
) )
else: else: