TorchLean API

NN.MLTheory.CROWN.Operators.Reduce

Reduction operator bounds #

This file defines simple IBP and affine transfer rules for common reductions over flattened vectors (sum/mean/max/min/prod). These rules are primarily intended for the graph-based verifier.

Non-smooth reductions (max/min) are treated conservatively (interval enclosures), and prod is treated as a bilinear-style operation (also conservatively).

Helper to extract scalar from dim-scalar tensor.

Instances For

    Compute sum of a 1D tensor.

    Instances For

      IBP for ReduceSum: sum of intervals = interval of sums. [Σ lo_i, Σ hi_i]

      Instances For

        IBP for ReduceMean: mean of intervals. [Σ lo_i / n, Σ hi_i / n]

        Instances For

          IBP for ReduceMax: max over intervals. lo = max of individual lower bounds (conservative but sound) hi = max of individual upper bounds

          Note: This is conservative. The true lower bound on max(x) is max(min_i x_i), but we use max(lo_i) which may be looser.

          Instances For

            IBP for ReduceMin: min over intervals. lo = min of individual lower bounds (tight) hi = min of individual upper bounds (conservative but sound)

            Instances For

              IBP for ReduceProd: product over intervals. This is more complex due to sign changes. For each element, compute all 4 corner products and take min/max.

              For n elements: Π[lo_i, hi_i] requires 2^n evaluations in general. We use a recursive interval multiplication approach.

              Instances For
                def NN.MLTheory.CROWN.Operators.Reduce.affReduceSum {α : Type} [Context α] {inDim : } (n : ) (aff : AffineVec α inDim n) :
                AffineVec α inDim 1

                Affine bounds for ReduceSum: y = Σ x_i = [1, 1, ..., 1] · x The affine form maps inDim to 1: A = [[sum of A rows]], c = [sum of c].

                Instances For
                  def NN.MLTheory.CROWN.Operators.Reduce.affReduceMean {α : Type} [Context α] {inDim : } (n : ) (aff : AffineVec α inDim n) :
                  AffineVec α inDim 1

                  Affine bounds for ReduceMean: y = (Σ x_i) / n = (1/n) * Σ x_i

                  Instances For

                    Derivative bounds for ReduceSum: ∂(Σ x_i)/∂x_j = 1 for all j. If input derivatives are in [dlo, dhi], output derivative = Σ d_i.

                    Instances For

                      Derivative bounds for ReduceMean: ∂(mean)/∂x_j = 1/n for all j.

                      Instances For

                        Derivative bounds for ReduceMax: non-smooth, uses subgradient. ∂max/∂x_i = 1 if x_i is the max, 0 otherwise. For intervals, we bound: derivative ∈ [0, 1] for argmax candidates.

                        Instances For

                          Derivative bounds for ReduceMin: similar to max but argmin.

                          Instances For

                            IBP for ReduceSum along axis 0 (sum over rows) for 2D: [rows, cols] → [1, cols]. Each output column j = Σ_i input[i,j].

                            Instances For

                              IBP for ReduceSum along axis 1 (sum over columns) for 2D: [rows, cols] → [rows, 1]. Each output row i = Σ_j input[i,j].

                              Instances For

                                ReduceSum output dimension is 1.

                                ReduceMean output dimension is 1.

                                ReduceMax output dimension is 1.

                                ReduceMin output dimension is 1.

                                ReduceProd output dimension is 1.

                                Affine reduce sum output dimension is 1.