|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _dsp_get_significant_positions(self, capsule: np.ndarray, b_idx: int, threshold: float = 1e-3) -> List[SpatialPosition]: |
|
|
"""Select positions with significant amplitude using an adaptive, band-specific cutoff. |
|
|
|
|
|
Steps: |
|
|
1) Collect amplitudes for the requested band's slice. |
|
|
2) Drop values <= `threshold` (absolute noise floor). |
|
|
3) Set adaptive cutoff tau = max(threshold, percentile(nz, 85)). |
|
|
4) Return positions with amplitude >= tau. |
|
|
""" |
|
|
amps: List[float] = [] |
|
|
for pos in self.encoder.positions: |
|
|
amps.append( |
|
|
float( |
|
|
np.abs( |
|
|
capsule[pos.m + self.encoder.M, pos.n + self.encoder.N, b_idx] |
|
|
) |
|
|
) |
|
|
) |
|
|
|
|
|
if not amps: |
|
|
return [] |
|
|
|
|
|
a = np.asarray(amps, dtype=float) |
|
|
nz = a[a > threshold] |
|
|
if nz.size == 0: |
|
|
tau = threshold |
|
|
else: |
|
|
tau = max(threshold, float(np.percentile(nz, 85))) |
|
|
|
|
|
positions: List[SpatialPosition] = [] |
|
|
for i, pos in enumerate(self.encoder.positions): |
|
|
if a[i] >= tau: |
|
|
positions.append(pos) |
|
|
return positions |
|
|
|
|
|
|
|
|
try: |
|
|
DualStreamProcessor._get_significant_positions = _dsp_get_significant_positions |
|
|
except NameError: |
|
|
|
|
|
pass |
|
|
|