41class ExplainerContext;
82 double clip_min = -std::numeric_limits<double>::infinity();
83 double clip_max = std::numeric_limits<double>::infinity();
161 const std::vector<int64_t>& labels,
const std::vector<double>& epsilons,
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:248
Wraps an ordered chain of Modules, running them via Module::forward_traced to build a real Computatio...
Definition explainer_context.hpp:67
One JSON value: null, a boolean, a number, a string, an array or an object.
Definition json.hpp:22
Base class for every layer type (LinearModule, Conv2DModule, activations, ...).
Definition module.hpp:78
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
A small strict JSON value, parser and deterministic writer (RFC 8259).
Definition acquisition_functions.hpp:16
AttackResult Fgsm(const DifferentiableClassifier &model, const Tensor &input, const std::vector< int64_t > &labels, DeviceBackend *backend, const AttackOptions &options={}, bool targeted=false)
The fast gradient sign method: one step of size epsilon (options.steps, step_size and random_start ar...
AttackNorm
The norm an attack's budget is measured in.
Definition adversarial.hpp:65
AttackResult Pgd(const DifferentiableClassifier &model, const Tensor &input, const std::vector< int64_t > &labels, DeviceBackend *backend, const AttackOptions &options={}, bool targeted=false)
Projected gradient descent: random start, then steps steps, each projected onto the epsilon-ball arou...
RobustnessCurve RobustAccuracyCurve(const DifferentiableClassifier &model, const Tensor &input, const std::vector< int64_t > &labels, const std::vector< double > &epsilons, DeviceBackend *backend, const AttackOptions &options={})
Robust accuracy against untargeted PGD at each budget: how fast the accuracy falls as the attacker ge...
JsonValue ToJson(const AttackResult &result, const AttackOptions &options)
The result as a pulsatrix.attack.v1 document, without the adversarial inputs.
DifferentiableClassifier ClassifierFrom(ExplainerContext &context)
Differentiates through an ExplainerContext's autograd, as the gradient explainers do; the model's par...
Settings for Fgsm() and Pgd().
Definition adversarial.hpp:68
AttackNorm norm
Definition adversarial.hpp:71
uint64_t seed
Definition adversarial.hpp:79
bool random_start
PGD: start at a uniformly random point of the ball (the L2 ball for L2), as Madry et al....
Definition adversarial.hpp:78
double clip_max
Definition adversarial.hpp:83
double epsilon
The budget: every adversarial input is within epsilon of its original.
Definition adversarial.hpp:70
double clip_min
The valid range of each input element, such as [0, 1] for pixels; every adversarial input is clipped ...
Definition adversarial.hpp:82
int64_t steps
PGD: the number of steps.
Definition adversarial.hpp:73
double step_size
PGD: the step size; 0 means 2.5 epsilon / steps, Madry et al.'s choice.
Definition adversarial.hpp:75
One attack's result.
Definition adversarial.hpp:87
std::vector< bool > success
Untargeted: the adversarial input isn't classified as its label. Targeted: it is classified as its ta...
Definition adversarial.hpp:95
bool targeted
Definition adversarial.hpp:107
double clean_accuracy
Untargeted: the fraction classified correctly before it.
Definition adversarial.hpp:106
std::vector< int64_t > adversarial_predicted
Definition adversarial.hpp:92
std::vector< double > perturbation
Each perturbation's size in the attack's norm: at most epsilon, up to rounding.
Definition adversarial.hpp:100
double robust_accuracy
Untargeted: the fraction classified correctly after the attack.
Definition adversarial.hpp:104
Tensor adversarial
The adversarial inputs, the input's shape, on the input's device.
Definition adversarial.hpp:89
double success_rate
The fraction of inputs the attack succeeded on.
Definition adversarial.hpp:102
std::vector< double > adversarial_loss
Definition adversarial.hpp:98
std::vector< double > clean_loss
The cross-entropy of each label (the target's, when targeted) before and after.
Definition adversarial.hpp:97
std::vector< int64_t > clean_predicted
Each input's predicted class before and after the attack.
Definition adversarial.hpp:91
A classifier the attacks can differentiate: forward maps an (N, ...) input to (N, C) logits; backward...
Definition adversarial.hpp:49
std::function< Tensor(const Tensor &)> backward
Definition adversarial.hpp:51
std::function< Tensor(const Tensor &)> forward
Definition adversarial.hpp:50
RobustAccuracyCurve()'s result.
Definition adversarial.hpp:144
int64_t steps
Definition adversarial.hpp:148
AttackNorm norm
Definition adversarial.hpp:146
int64_t n
Definition adversarial.hpp:147
std::vector< RobustnessPoint > points
Definition adversarial.hpp:150
double clean_accuracy
Definition adversarial.hpp:149
std::string attack
Definition adversarial.hpp:145
One budget's result on a robustness curve.
Definition adversarial.hpp:133
double robust_accuracy
The fraction of inputs still classified correctly after PGD.
Definition adversarial.hpp:136
double flip_rate
Of the inputs classified correctly before the attack, the fraction it flipped.
Definition adversarial.hpp:138
double mean_perturbation
The mean perturbation size of the successful attacks; 0 if there were none.
Definition adversarial.hpp:140
double epsilon
Definition adversarial.hpp:134
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).