# Path: common/framework.py
# class LpTask(TaskDefinition):
#     """Task definition for adversarial examples in L_{p} ball."""
# 
#     def __init__(self, norm, threshold):
#         """Initializes Lp task definition.
# 
#         Args:
#             norm: norm type to use. Interpretation is same as `ord` argument of `np.linalg.norm` function
#               when `np.linalg.norm` is used for vectors.
#         """
#         self.threshold = threshold
#         self.norm = norm
# 
#     def evaluate(self, defense, example_idx, true_label,
#                  src_example, adv_example,
#                  src_pred, adv_pred,
#                  src_detector, adv_detector):
#         # Verify that the label is now incorrect
#         if np.argmax(adv_pred) == true_label:
#             return False, "Label {} matches true label {}".format(np.argmax(adv_pred), true_label)
# 
#         # Verify that example is within the allowed Lp norm
#         distortion = np.linalg.norm((src_example - adv_example).flatten(), ord=self.norm)
#         if distortion > self.threshold + 1e-3:
#             return False, "Distortion {} exceeds bound {}".format(distortion, self.threshold)
# 
#         # Verify that it's not detected as adversarial
#         if adv_detector > defense.threshold:
#             return False, "Adversarial example rejected by detector with score {}.".format(adv_detector)
# 
#         return True, None


import numpy as np
from common.framework import LpTask
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Task definition for evaluator code."""



DATASET = 'cifar10'
L2_THRESHOLD = 0.5
LINF_THRESHOLD = 4.0 / 255.0


TASKS = {
    'attack_linf.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_linf_torch.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_linf_soln.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_linf_torch_soln.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_l2.py': LpTask(2, L2_THRESHOLD),
    'attack_l2_torch.py': LpTask(2, L2_THRESHOLD),
    'attack_l2_soln.py': LpTask(2, L2_THRESHOLD),

# Path: common/framework.py
# class LpTask(TaskDefinition):
#     """Task definition for adversarial examples in L_{p} ball."""
# 
#     def __init__(self, norm, threshold):
#         """Initializes Lp task definition.
# 
#         Args:
#             norm: norm type to use. Interpretation is same as `ord` argument of `np.linalg.norm` function
#               when `np.linalg.norm` is used for vectors.
#         """
#         self.threshold = threshold
#         self.norm = norm
# 
#     def evaluate(self, defense, example_idx, true_label,
#                  src_example, adv_example,
#                  src_pred, adv_pred,
#                  src_detector, adv_detector):
#         # Verify that the label is now incorrect
#         if np.argmax(adv_pred) == true_label:
#             return False, "Label {} matches true label {}".format(np.argmax(adv_pred), true_label)
# 
#         # Verify that example is within the allowed Lp norm
#         distortion = np.linalg.norm((src_example - adv_example).flatten(), ord=self.norm)
#         if distortion > self.threshold + 1e-3:
#             return False, "Distortion {} exceeds bound {}".format(distortion, self.threshold)
# 
#         # Verify that it's not detected as adversarial
#         if adv_detector > defense.threshold:
#             return False, "Adversarial example rejected by detector with score {}.".format(adv_detector)
# 
#         return True, None


# Path: defense_transform/task_definition.py
import numpy as np
from common.framework import LpTask

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Task definition for evaluator code."""



DATASET = 'cifar10'
L2_THRESHOLD = 0.5
LINF_THRESHOLD = 4.0 / 255.0


TASKS = {
    'attack_linf.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_linf_torch.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_linf_soln.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_linf_torch_soln.py': LpTask(np.inf, LINF_THRESHOLD),
    'attack_l2.py': LpTask(2, L2_THRESHOLD),
    'attack_l2_torch.py': LpTask(2, L2_THRESHOLD),
    'attack_l2_soln.py': LpTask(2, L2_THRESHOLD),

    'attack_l2_torch_soln.py': LpTask(2, L2_THRESHOLD),