TorchLean API

NN.MLTheory.LearningTheory.Robustness.Spec

NN.MLTheory.Robustness.Spec #

Scalar-polymorphic definitions of norms/distances and basic robustness vocabulary on TorchLean's shape-indexed tensors.

Robustness specifications (polymorphic) #

This file defines a small vocabulary for specifying robustness properties of tensor-valued functions.

All definitions are scalar-polymorphic in α via [Context α], so the same spec can be instantiated for:

We keep this module definition-focused: whether these norms/distances satisfy the usual metric laws depends on additional algebraic/order assumptions on α, and those theorems belong in dedicated proof developments.

The Float specializations of these definitions live in NN.MLTheory.Robustness.Runtime.

Verified bounds/certificates are proved in dedicated developments (e.g. Lipschitz bounds in NN.Proofs.Analysis.Lipschitz, and certified robustness procedures in NN.MLTheory.CROWN).

References #

Norms on spec tensors #

L∞ norm of a shape-indexed tensor.

If you flatten the tensor entries into a vector tᵢ, this is maxᵢ |tᵢ|.

Instances For

    L2 (Euclidean) norm of a shape-indexed tensor.

    If you flatten the tensor entries into a vector tᵢ, this is sqrt (∑ᵢ tᵢ²).

    Instances For

      Distances and balls #

      def NN.MLTheory.Robustness.Spec.tensorDistance {α : Type} [Context α] (norm : {s : Spec.Shape} → Spec.Tensor α sα) {s : Spec.Shape} (t1 t2 : Spec.Tensor α s) :
      α

      Distance induced by a tensor norm:

      dist(t1,t2) = ‖t1 - t2‖.

      Instances For
        @[simp]
        theorem NN.MLTheory.Robustness.Spec.tensor_distance_eq_norm_sub_spec {α : Type} [Context α] (norm : {s : Spec.Shape} → Spec.Tensor α sα) {s : Spec.Shape} (t1 t2 : Spec.Tensor α s) :
        tensorDistance (fun {s : Spec.Shape} => norm) t1 t2 = norm (t1.subSpec t2)
        def NN.MLTheory.Robustness.Spec.tensorBall {α : Type} [Context α] (norm : {s : Spec.Shape} → Spec.Tensor α sα) {s : Spec.Shape} (center : Spec.Tensor α s) (ε : α) :

        Closed ε-ball around center for the given norm:

        { t | dist(center,t) ≤ ε }.

        Instances For

          Continuity / robustness specifications #

          def NN.MLTheory.Robustness.Spec.isLipschitzContinuous {α : Type} [Context α] {s₁ s₂ : Spec.Shape} (f : Spec.Tensor α s₁Spec.Tensor α s₂) (norm₁ norm₂ : {s : Spec.Shape} → Spec.Tensor α sα) (L : α) :

          Lipschitz continuity (global), phrased using tensor_distance.

          If f is L-Lipschitz and tensor_distance norm₁ x₀ x ≤ ε, then tensor_distance norm₂ (f x₀) (f x) ≤ L*ε.

          Instances For
            def NN.MLTheory.Robustness.Spec.isLocallyLipschitz {α : Type} [Context α] {s₁ s₂ : Spec.Shape} (f : Spec.Tensor α s₁Spec.Tensor α s₂) (norm₁ norm₂ : {s : Spec.Shape} → Spec.Tensor α sα) (x₀ : Spec.Tensor α s₁) (ε L : α) :

            Local Lipschitz continuity within the ε-ball around x₀.

            Instances For
              def NN.MLTheory.Robustness.Spec.isAdversariallyRobust {α : Type} [Context α] {s₁ s₂ : Spec.Shape} (f : Spec.Tensor α s₁Spec.Tensor α s₂) (norm₁ norm₂ : {s : Spec.Shape} → Spec.Tensor α sα) (x₀ : Spec.Tensor α s₁) (ε δ : α) :

              Adversarial robustness at a point x₀.

              f is (ε,δ)-robust at x₀ if every input within distance ε of x₀ maps to an output within distance δ of f x₀.

              Instances For
                def NN.MLTheory.Robustness.Spec.isCertifiedRobust {α : Type} [Context α] {s : Spec.Shape} (classifier : Spec.Tensor α s) (norm : {s : Spec.Shape} → Spec.Tensor α sα) (x₀ : Spec.Tensor α s) (ε : α) :

                Certified robustness for a classifier: the prediction is constant on the ε-ball around x₀.

                For neural networks, classifier is typically argmax on a logits tensor.

                Instances For
                  def NN.MLTheory.Robustness.Spec.isUniformlyRobust {α : Type} [Context α] {s₁ s₂ : Spec.Shape} (f : Spec.Tensor α s₁Spec.Tensor α s₂) (norm₁ norm₂ : {s : Spec.Shape} → Spec.Tensor α sα) (dataset : List (Spec.Tensor α s₁)) (ε δ : α) :

                  Uniform adversarial robustness over a finite list of inputs.

                  Instances For
                    def NN.MLTheory.Robustness.Spec.isContractive {α : Type} [Context α] {s : Spec.Shape} (f : Spec.Tensor α sSpec.Tensor α s) (norm : {s : Spec.Shape} → Spec.Tensor α sα) (contraction_factor : α) :

                    Contraction mapping under a norm: f shrinks distances by contraction_factor < 1.

                    This is a standard sufficient condition for convergence of iterated dynamics and robustness of fixed points.

                    Instances For
                      def NN.MLTheory.Robustness.Spec.sensitivity {α : Type} [Context α] {s₁ s₂ : Spec.Shape} (f : Spec.Tensor α s₁Spec.Tensor α s₂) (norm₁ norm₂ : {s : Spec.Shape} → Spec.Tensor α sα) (x perturbation : Spec.Tensor α s₁) :
                      α

                      Sensitivity ratio for a specific additive perturbation.

                      This is the local “output change divided by input change” quantity:

                      ‖f(x) - f(x + perturbation)‖ / ‖perturbation‖.

                      Instances For