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

Implements elastic-net attack #79

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Implements elastic-net attack #79

wants to merge 15 commits into from

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Aug 25, 2022

Derived from: https://arxiv.org/pdf/1709.04114.pdf

Here is a trivial scenario where we are merely perturbing the "logits" themselves so that the specified targets will be optimized for. Let's see that the longer we run the optimizer, the more the learned perturbation shrinks (while still amounting to a successful attack).

>>> from rai_toolbox.perturbations.solvers import elastic_net_attack
>>> logits = [[0.497, 0.503]]
>>> target = [0]

>>> for num_steps in [1, 10, 100]:
...     _, x_adv, _ = elastic_net_attack(
...         model=lambda x: x,
...         data=logits,
...         target=target,
...         beta=1e-3,
...         c=2,
...         steps=num_steps,
...         confidence=.01,
...         lr=0.5,
...     )
...     print(f"num-steps: {num_steps}\n{x_adv}")
num-steps: 1
tensor([[ 1.4960, -0.4960]])
num-steps: 10
tensor([[0.5062, 0.4938]])
num-steps: 100
tensor([[0.5018, 0.4982]])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant