From 7ecdf6a2a0f882aa4fd7ce36bf89c656b058fe55 Mon Sep 17 00:00:00 2001 From: duxin Date: Wed, 29 Jul 2026 14:36:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20PhysicalFeatureExtractor=20=E9=99=A4?= =?UTF-8?q?=E9=9B=B6=20=E2=86=92=20=E8=AE=BE=E9=9B=B6=E8=80=8C=E9=9D=9E?= =?UTF-8?q?=E4=BA=BA=E4=B8=BA=E6=94=BE=E5=A4=A7?= 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 兜底又会制造极端比值(14080/1e-12=1.4e16) - 改为: 分母<1e-10 时直接设 ratio=0,不做人为放大 - 物理意义: 波段为零的像素,光谱比值无意义 --- src/preprocessing/spectral_Preprocessing.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/preprocessing/spectral_Preprocessing.py b/src/preprocessing/spectral_Preprocessing.py index 1b05560..64b7f9e 100644 --- a/src/preprocessing/spectral_Preprocessing.py +++ b/src/preprocessing/spectral_Preprocessing.py @@ -502,11 +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, 1e-12, denom) - feats.append(((a - b) / denom).reshape(-1, 1)) + valid = np.abs(denom) >= 1e-10 + vals = np.zeros_like(a, dtype=np.float64) + vals[valid] = (a[valid] - b[valid]) / denom[valid] + feats.append(vals.reshape(-1, 1)) else: # ratio_single - denom = np.where(np.abs(b) < 1e-12, 1e-12, b) - feats.append((a / denom).reshape(-1, 1)) + valid = np.abs(b) >= 1e-10 + vals = np.zeros_like(a, dtype=np.float64) + vals[valid] = a[valid] / b[valid] + feats.append(vals.reshape(-1, 1)) 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)