boundlab.expr.LpEpsilon#

class boundlab.expr.LpEpsilon[source]#

Bases: Expr

A noise symbol bounded by the \(\ell_p\)-norm constraint.

Represents a perturbation variable \(\boldsymbol{\epsilon}\) satisfying:

\[\|\boldsymbol{\epsilon}\|_p \leq 1\]

During backward propagation with direction "<=" or ">=", the contribution is \(\pm\|\mathbf{w}\|_q\) where \(\mathbf{w}\) is the materialized weight tensor and \(q\) is the dual norm of \(p\) defined by \(\frac{1}{p} + \frac{1}{q} = 1\).

Only EinsumOp weights are supported.

Methods

__init__

backward

Compute the dual-norm bound contribution.

bound_width

Compute the width of the bounds for this expression.

center

Compute the center of the bounds for this expression.

diag

expand

flatten

flip

gather

get_const

Return the concrete tensor if self is a pure constant expression, else None.

jacobian_ops_

Recursively compute Jacobian ops for affine expressions.

lb

Compute a lower bound for this expression.

narrow

permute

repeat

reshape

roll

scatter

squeeze

tile

to_string

Return string representation with child strings substituted.

transpose

ub

Compute an upper bound for this expression.

ublb

Compute both an upper bound and a lower bound for this expression.

unflatten

unsqueeze

with_children

Return a new expression with the same type and flags but new children.

zeros_set

__init__(*shape, name=None, p='inf')[source]#
property shape: torch.Size#

The shape of the output(s) produced by this expression.

with_children()[source]#

Return a new expression with the same type and flags but new children.

property children: tuple[()]#

The child expressions that serve as inputs to this expression.

backward(weights, direction)[source]#

Compute the dual-norm bound contribution.

Parameters:
  • weights (LinearOp) – A EinsumOp accumulated weight. Must be a EinsumOp instance.

  • direction (Literal['>=', '<=', '==']) – "<=" returns \(+\|\mathbf{w}\|_q\); ">=" returns \(-\|\mathbf{w}\|_q\); "==" returns None.

Returns:

(±norm, []) or None for "==".

Return type:

tuple[torch.Tensor, list] | None

property T: Expr#

Convenience for transpose of the last two dimensions.

__add__(other)#
__mul__(other)#

Element-wise multiplication (no broadcast).

bound_width()#

Compute the width of the bounds for this expression.

center()#

Compute the center of the bounds for this expression.

diag(diagonal=0)#
expand(*sizes)#
flatten(start_dim=0, end_dim=-1)#
flip(dims)#
gather(indices)#
get_const()#

Return the concrete tensor if self is a pure constant expression, else None.

Works for ConstVal and any AffineSum that has no symbolic children.

jacobian_ops_()#

Recursively compute Jacobian ops for affine expressions.

lb()#

Compute a lower bound for this expression.

narrow(dim, start, length)#
permute(*dims)#
repeat(*sizes)#
reshape(*shape)#
roll(shifts, dims)#
scatter(indices, output_shape)#
squeeze(dim=None)#
tile(*sizes)#
to_string()[source]#

Return string representation with child strings substituted.

transpose(dim0, dim1)#
ub()#

Compute an upper bound for this expression.

ublb()#

Compute both an upper bound and a lower bound for this expression.

unflatten(dim, sizes)#
unsqueeze(dim)#
zeros_set(output_shape)#
id: int#

Unique identifier for the expression, used for topological sorting.

flags: ExprFlags#

Flags indicating expression properties for optimization.