From 60403b7a3f171982ec18fd8c25ff3db0cc5914ae Mon Sep 17 00:00:00 2001 From: duxin Date: Wed, 29 Jul 2026 14:35:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20PhysicalFeatureExtractor=20=E9=99=A4?= =?UTF-8?q?=E9=9B=B6=E4=BF=9D=E6=8A=A4=20=E2=80=94=20np.sign(0)=3D0=20?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=20inf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 分母保护 np.sign(x)*1e-12 在 x=0 时变为 0,a/0 → inf - 改为固定 1e-12 兜底 + nan_to_num + clip 安全阀 - 同时修复 ratio 型和 ratio_single 型两处 --- src/preprocessing/spectral_Preprocessing.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/preprocessing/spectral_Preprocessing.py b/src/preprocessing/spectral_Preprocessing.py index f309c3b..1b05560 100644 --- a/src/preprocessing/spectral_Preprocessing.py +++ b/src/preprocessing/spectral_Preprocessing.py @@ -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 # ============================================================================