Skip to content

Commit

Permalink
Merge pull request #506 from bethgelab/linf_clip
Browse files Browse the repository at this point in the history
changed Linf distance clipping to be pure clipping instead of downscaling
  • Loading branch information
jonasrauber committed Feb 23, 2020
2 parents 1a63b76 + 9f99245 commit 3999d43
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions foolbox/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def clip_perturbation(self, references: T, perturbed: T, epsilon: float) -> T:
"""
(x, y), restore_type = ep.astensors_(references, perturbed)
p = y - x
if self.p == ep.inf:
clipped_perturbation = ep.clip(p, -epsilon, epsilon)
return restore_type(x + clipped_perturbation)
norms = ep.norms.lp(flatten(p), self.p, axis=-1)
norms = ep.maximum(norms, 1e-12) # avoid divsion by zero
factor = epsilon / norms
Expand Down

0 comments on commit 3999d43

Please sign in to comment.