Odds#
- class scio.scores.Odds(*, act_norm=None, mode='raw', epsilon=?, noise_samples=256, z_aggregation='sum', rng_seed=0)[source]#
Bases:
BaseScoreClassifOdds for classification.
- Parameters:
epsilon (
float) – \(L^{\infty}\) scale of uniformly sampled random perturbations.noise_samples (
int) – Number of random samples to compute log-preferences. Defaults to2**8.z_aggregation (
ZAggrLike) – SeeZAggr. Defaults to"sum".batch_size (
int) –Currently Not Implemented!
Necessary for computational reasons. Data and env-dependent. Use
0for unlimited. Defaults to2**13.rng_seed (
int, optional) – If provided, manual seed fortorch.Generator, used during calibration (in which case the random state is reset at everyfit()call). Defaults to0.mode – See
BaseScoreClassif.act_norm – See
BaseScore.
Warning
Current implementation is unbatched. This means it does not scale well for large number of random samples.
References
[RKH19]Kevin Roth, Yannic Kilcher, and Thomas Hofmann. The Odds are Odd: a statistical test for detecting adversarial examples. In Proceedings of the 36th International Conference on Machine Learning, volume 97, 5498–5507. 2019. URL: https://proceedings.mlr.press/v97/roth19a.html.
Hint
Below this point, the documentation is meant for development purposes only. Manual use of any listed member is highly discouraged. For usage, see Inferring with Confidence.
Useful methods defined here
logits_pref(samples, reference_idx)Compute logits difference to reference index.
uniform(*size, to)Sample uniformly random
Tensorin \([-1, 1]^{size}\).- static logits_pref(samples, reference_idx)[source]#
Compute logits difference to reference index.
In [RKH19] notations, corresponds to \(f_{y, z}\) for all \(z\) given
samples\(f\) andreference_idx\(y\).- Parameters:
samples (
Tensor) – Logits. Shape(n_samples, n_classes).reference_idx (
int) – Index of the reference to subtract.
- uniform(*size, to)[source]#
Sample uniformly random
Tensorin \([-1, 1]^{size}\).The output device and dtype are those of
to. The same applies to its shape ifsizeif empty.- Parameters:
*size (
int) – If provided, unpacked target size.to (
Tensor) – Tensor defining the target dtype and device. Also defines the target size if size is empty.