Mlp #
CROWN/DeepPoly-style propagation for MLPs (vector in/out) using TorchLean tensors.
This file is a compact implementation that sits on top of:
NN.MLTheory.CROWN.Core(Box,AffineVec, andIBP.linear), and- TorchLean’s typed tensor layer (
Spec.Tensor).
What is implemented:
- Per-neuron ReLU linear relaxations derived from pre-activation bounds using the canonical
Runtime.Ops.ReLU.relaxScalarandRuntime.Ops.ReLU.relaxScalarLowerdefinitions. - IBP forward rules for ReLU, sigmoid, tanh, and Leaky ReLU.
- A two-layer ReLU MLP wrapper
TwoLayerMLPwith a simple end-to-end bounding API.
Scope boundaries in this MLP-focused module:
- General computation graphs. Use
NN.MLTheory.CROWN.Graphfor the graph-level certificate checker andNN.MLTheory.CROWN.Proofs.GraphCrownCertSoundnessfor the corresponding end-to-end soundness theorem. - Objective-dependent / backward CROWN slope optimization. The
certificate infrastructure for alpha-CROWN and alpha/beta-CROWN artifacts lives under
NN.MLTheory.CROWN.Cert.AlphaCROWNandNN.MLTheory.CROWN.Cert.AlphaBetaCROWN.
References:
- CROWN: Zhang et al., "Efficient Neural Network Robustness Certification with General Activation Functions", arXiv:1811.00866.
- auto_LiRPA: Xu et al., "Automatic Perturbation Analysis for Scalable Certified Robustness and Beyond", NeurIPS 2020, arXiv:2002.12920.
PyTorch analogues:
Column-wise scaling of a matrix by a vector: scale each column j by v[j].
Instances For
Elementwise positive part of a matrix: replace negative entries by 0.
Instances For
Elementwise negative part of a matrix: replace positive entries by 0.
Instances For
Extract the slope vector from a tensor of ReLU relaxations.
Instances For
Extract the bias vector from a tensor of ReLU relaxations.
Instances For
Interval Bound Propagation (IBP) utilities for vector-shaped activations.
These are executable transfer functions. Their soundness theorems instantiate the scalar type with
ℝ and use the corresponding monotonicity or activation-specific proof.
The linear-layer bound helper IBP.linear lives in NN.MLTheory.CROWN.Core.
Interval bounds for ReLU on a vector.
This is the standard elementwise interval evaluation:
relu([l,u]) = [relu(l), relu(u)].
Instances For
Re-export of the runtime-only monotone-activation IBP helper.
We keep this file compact and Mathlib-friendly for proofs, but we do not want to
maintain two copies of the same computational rule. Canonical implementation lives in:
NN.MLTheory.CROWN.Runtime.Ops.IBP.map_minmax.
Semantics (per component): given an interval [l,u], this returns
[min(f(l), f(u)), max(f(l), f(u))] (intended for monotone f).
Instances For
Interval bounds for sigmoid.
Instances For
Interval bounds for tanh.
Instances For
Interval bounds for leaky ReLU, including the zero kink on crossing intervals.
Instances For
Two-layer MLP payload used by this file.
Semantics: y = outputWeight * relu(hiddenWeight * x + hiddenBias) + outputBias.
PyTorch analogue: torch.nn.Sequential(Linear(inDim,hidDim), ReLU(), Linear(hidDim,outDim)).
- outputWeight : Spec.Tensor α (Spec.Shape.dim outDim (Spec.Shape.dim hidDim Spec.Shape.scalar))
Second layer weight matrix.
- outputBias : Spec.Tensor α (Spec.Shape.dim outDim Spec.Shape.scalar)
Second layer bias vector.
Instances For
Forward semantics for TwoLayerMLP (used to state soundness theorems).
Instances For
Build a TwoLayerMLP from two LinearSpec records.
Instances For
Compute an output interval box via pure IBP.
This is fast and, when BoundOps α supplies sound outward endpoint operations, typically looser
than CROWN/DeepPoly affine bounds.
Instances For
The lower and upper affine CROWN forms for this two-layer ReLU MLP.
The returned pair is (lower, upper). boundAffineCrown evaluates these forms on the input box and
takes the lower and upper endpoints.
Instances For
Single-pass affine (CROWN/DeepPoly-style) bounds for the 2-layer ReLU MLP.
This path is only the direct two-layer MLP version. The graph-level code is still the general CROWN API.
Instances For
End-to-end bound API exposed by this file.
This API returns the IBP bound. Its enclosure guarantee depends on the selected BoundOps
implementation; boundAffineCrown is the direct two-layer ReLU affine implementation.
Instances For
Theorems inspired by CROWN (Zhang et al., 2018, arXiv:1811.00866)
We record soundness properties of the relaxations and bound propagation. Proofs below require elementary order reasoning and case splits on signs, plus properties of mat-vec interval arithmetic.
Scalar ReLU relaxation soundness over ℝ (upper bound).
If x ∈ [l, u] and rp := ReLU.relax_scalar l u, then:
relu(x) <= rp.slope * x + rp.bias.
This is the standard CROWN/DeepPoly upper chord construction (arXiv:1811.00866).
Vectorized ReLU relaxation (pointwise upper bound) over ℝ.
If x ∈ [lo, hi] and rp := ReLU.relax_vector lo hi, then for every component i we have
relu(xᵢ) ≤ rpᵢ.slope * xᵢ + rpᵢ.bias.
Soundness of IBP.linear over ℝ.
If x ∈ xB and b ∈ bB, then W*x + b lies in the interval box computed by
IBP.linear W xB bB.
Soundness of pure IBP bounds for a 2-layer MLP over ℝ.
Soundness of the affine-bound wrapper for a 2-layer MLP over ℝ.
In this module bound_affine delegates to the IBP implementation, so this theorem is a direct
corollary of bound_ibp_sound.
Compute both IBP bounds and affine-CROWN bounds for a two-layer MLP around an ε-box.
The input set is the axis-aligned box centered at x_center with radius eps in each coordinate.
Instances For
Extract the scalar component t[i] from a vector-shaped tensor.
Instances For
Lower endpoint at index i from a vector box.
Instances For
Upper endpoint at index i from a vector box.
Instances For
Maximum upper bound among competitors k ≠ c.
Instances For
Certified margin lower bound: lowerAt c - maxCompetitorUpper c.
Instances For
Decide whether class c is certified by a positive margin.
Instances For
Return the argmax index of a concrete output vector (when n > 0), otherwise none.
This is a utility for pairing certified bounds with a predicted class.