Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix min_epsilon of BoundaryAttack to receive a non-negative value #1262

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions art/attacks/evasion/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
num_trial: int = 25,
sample_size: int = 20,
init_size: int = 100,
min_epsilon: Optional[float] = None,
min_epsilon: float = 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_epsilon: float = 0,
min_epsilon: Union[float, int] = 0,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PEP 484,

when an argument is annotated as having type float, an argument of type int is acceptable

so I think only float is sufficient as in epsilon and delta.

verbose: bool = True,
) -> None:
"""
Expand Down Expand Up @@ -327,7 +327,7 @@ def _attack(
logger.warning("Adversarial example found but not optimal.")
return self._best_adv(original_sample, x_advs)

if self.min_epsilon is not None and self.curr_epsilon < self.min_epsilon:
if self.curr_epsilon < self.min_epsilon:
return x_adv

return x_adv
Expand Down Expand Up @@ -470,8 +470,8 @@ def _check_params(self) -> None:
if self.step_adapt <= 0 or self.step_adapt >= 1:
raise ValueError("The adaptation factor must be in the range (0, 1).")

if self.min_epsilon is not None and (isinstance(self.min_epsilon, float) or self.min_epsilon <= 0):
raise ValueError("The minimum epsilon must be a positive float.")
if not isinstance(self.min_epsilon, (float, int)) or self.min_epsilon < 0:
raise ValueError("The minimum epsilon must be non-negative.")

if not isinstance(self.verbose, bool):
raise ValueError("The argument `verbose` has to be of type bool.")