Skip to content

Commit

Permalink
Add EPSILON to amp for numerical stability for division (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
earthgecko authored Nov 18, 2024
1 parent ecb3bcc commit 31d19a1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion alibi_detect/od/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def saliency_map(self, X: np.ndarray) -> np.ndarray:

fft = np.fft.fft(X)
amp = np.abs(fft)
log_amp = np.log(amp)
# For numerical stability for division to prevent divide by zero being encountered add EPSILON
log_amp = np.log(amp + EPSILON)
phase = np.angle(fft)
# split spectrum into bias term and symmetric frequencies
bias, sym_freq = log_amp[:1], log_amp[1:]
Expand Down

0 comments on commit 31d19a1

Please sign in to comment.