fix: PhysicalFeatureExtractor 除零保护 — np.sign(0)=0 导致 inf
- 分母保护 np.sign(x)*1e-12 在 x=0 时变为 0,a/0 → inf - 改为固定 1e-12 兜底 + nan_to_num + clip 安全阀 - 同时修复 ratio 型和 ratio_single 型两处
This commit is contained in:
@ -502,12 +502,15 @@ class PhysicalFeatureExtractor(TransformerMixin, BaseEstimator, _ArrayAsFloat64)
|
||||
a = X[:, ia]; b = X[:, ib]
|
||||
if ftype == 'ratio':
|
||||
denom = a + b
|
||||
denom = np.where(np.abs(denom) < 1e-12, np.sign(denom) * 1e-12, denom)
|
||||
denom = np.where(np.abs(denom) < 1e-12, 1e-12, denom)
|
||||
feats.append(((a - b) / denom).reshape(-1, 1))
|
||||
else: # ratio_single
|
||||
denom = np.where(np.abs(b) < 1e-12, np.sign(b) * 1e-12, b)
|
||||
denom = np.where(np.abs(b) < 1e-12, 1e-12, b)
|
||||
feats.append((a / denom).reshape(-1, 1))
|
||||
return np.hstack(feats)
|
||||
out = np.hstack(feats)
|
||||
out = np.nan_to_num(out, nan=0.0, posinf=0.0, neginf=0.0)
|
||||
out = np.clip(out, -1e15, 1e15)
|
||||
return out
|
||||
|
||||
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user