TorchLean API

NN.MLTheory.Proofs.Verification.Robustness.MlpRobustness

MLP robustness: basic analytic lemmas #

This file collects small real-analysis facts used by robustness statements for spec-level MLPs.

Contents:

References #

Basic Lipschitz lemmas #

Fundamental property: ReLU satisfies $|\operatorname{ReLU}(x)-\operatorname{ReLU}(y)|\le|x-y|$.

theorem NN.MLTheory.Proofs.comp_lipschitz (f g : ) (h_f : ∀ (x y : ), |f x - f y| |x - y|) (h_g : ∀ (x y : ), |g x - g y| |x - y|) (x y : ) :
|(g f) x - (g f) y| |x - y|

Composition property for Lipschitz functions

theorem NN.MLTheory.Proofs.relu_comp_preserves (f : ) (h : ∀ (x y : ), |f x - f y| |x - y|) (x y : ) :
|max 0 (f x) - max 0 (f y)| |x - y|

Main result: ReLU composition preserves unit Lipschitz property

Tensor helpers #

Definition: A non-zero tensor has at least one non-zero entry

Instances For
    noncomputable def NN.MLTheory.Proofs.linearLayerFrobeniusBound {inDim outDim : } (layer : Spec.LinearSpec inDim outDim) :

    Frobenius-norm Lipschitz bound for a linear layer's weight matrix.

    Instances For
      theorem NN.MLTheory.Proofs.linear_layer_lipschitz_bound {inDim outDim : } (layer : Spec.LinearSpec inDim outDim) (h_weights_nonzero : layer.weights TorchLean.Tensor.full [outDim, inDim] 0) :
      L > 0, ∀ (x y : TorchLean.Tensor [inDim]), Proofs.tensorL2Dist (Spec.linearSpec layer x) (Spec.linearSpec layer y) L * Proofs.tensorL2Dist x y

      Linear layers are Lipschitz continuous with the Frobenius norm as a valid, possibly loose, bound.

      ReLU is 1-Lipschitz in the L2 distance, so activations never amplify an input perturbation.

      theorem NN.MLTheory.Proofs.mlp_lipschitz_complete_analysis {inDim hidDim outDim : } (l1 : Spec.LinearSpec inDim hidDim) (l2 : Spec.LinearSpec hidDim outDim) (h1_nonzero : l1.weights TorchLean.Tensor.full [hidDim, inDim] 0) (h2_nonzero : l2.weights TorchLean.Tensor.full [outDim, hidDim] 0) :
      lipschitzConstant > 0, ∀ (x y : TorchLean.Tensor [inDim]), Proofs.tensorL2Dist (Examples.mlpForward l1 l2 x) (Examples.mlpForward l1 l2 y) lipschitzConstant * Proofs.tensorL2Dist x y

      A two-layer MLP is Lipschitz, with a positive constant obtained as the product of the layer constants.

      The constant here is the naive product of operator norms, which is what makes it cheap: it needs no information about the input region. That is also why it is loose compared to the CROWN bounds in NN.MLTheory.CROWN, and the contrast is the reason both developments are kept.

      theorem NN.MLTheory.Proofs.mlp_is_lipschitz_continuous_l2 {inDim hidDim outDim : } (l1 : Spec.LinearSpec inDim hidDim) (l2 : Spec.LinearSpec hidDim outDim) (h1_nonzero : l1.weights TorchLean.Tensor.full [hidDim, inDim] 0) (h2_nonzero : l2.weights TorchLean.Tensor.full [outDim, hidDim] 0) :

      Repackage mlp_lipschitz_complete_analysis as a robustness-spec isLipschitzContinuous fact.

      This is the form expected by the certified-robustness lemmas in NN.MLTheory.Proofs.Verification.Robustness.LipschitzCertified.

      theorem NN.MLTheory.Proofs.mlp_output_drift_bound_on_ball {inDim hidDim outDim : } (l1 : Spec.LinearSpec inDim hidDim) (l2 : Spec.LinearSpec hidDim outDim) (h1_nonzero : l1.weights TorchLean.Tensor.full [hidDim, inDim] 0) (h2_nonzero : l2.weights TorchLean.Tensor.full [outDim, hidDim] 0) (x₀ : TorchLean.Tensor [inDim]) (perturbationRadius : ) :
      perturbationRadius > 0robustnessGuarantee > 0, ∀ (x : TorchLean.Tensor [inDim]), Proofs.tensorL2Dist x₀ x perturbationRadiusProofs.tensorL2Dist (Examples.mlpForward l1 l2 x₀) (Examples.mlpForward l1 l2 x) robustnessGuarantee * perturbationRadius

      Bound output drift on an input ball. This theorem does not by itself preserve a class label.

      Robustness statements for MLPs (ML theory layer).

      This file collects robustness definitions and theorems specialized to multi-layer perceptrons, used as a bridge between learning-theory specifications and concrete model classes.