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

Implement sample-wise accuracy to check success of multiple attacks #48

Closed
maurapintor opened this issue Mar 7, 2024 · 0 comments · Fixed by #49
Closed

Implement sample-wise accuracy to check success of multiple attacks #48

maurapintor opened this issue Mar 7, 2024 · 0 comments · Fixed by #49
Assignees
Labels
enhancement New feature or request

Comments

@maurapintor
Copy link
Collaborator

The new class would add a new metric that takes a list of dataloader (resulting from multiple attack runs) and produce a compound metric that evaluates the worst-case prediction over the trials.

The trick is to collect all y_preds from the different loaders, and when computing the accuracy, add a minimum over the "correctness" of the predictions.

Example:

# stack predictions vertically
y_pred = [
    [1, 2, 3],
    [1, 2, 5],
    ]
y_true = [1, 2, 3]

# expected result:  [correct, correct, wrong]

This is the implementation:

correct = (y_pred.type(y_true.dtype).cpu() == y_true.cpu())

# result: 
# [[1, 1, 1],
#  [1, 1, 0]]

# take worst case
correct = correct.min(dim=0).values

# result: [1, 1, 0] -> sum for accuracy

A new metric will be added in metrics.classification.

@maurapintor maurapintor self-assigned this Mar 7, 2024
@maurapintor maurapintor added the enhancement New feature or request label Mar 7, 2024
@maurapintor maurapintor linked a pull request Mar 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant