T3Tangent.gauge_residual#

t3toolbox.manifold.T3Tangent.gauge_residual()#
def gauge_residual(self) -> NDArray:  # shape = variation stack K+C (scalar/0-d when unstacked)

Max gauge-condition violation relative to the tangent’s scale, per stack element (shape = variation stack K+C; atol-independent; cached).

The expensive part of is_gauged() – a fixed tangent reused across an inner loop (e.g. the safe-mode GAUGE precondition of ManifoldGeometry.inner()) is contracted once.

The scale. A tangent computed directly (a projection, a gradient, a constructor) is measured against its own coordinate norm. A tangent built by arithmetic is measured against its operands’ scale (max(||a||, ||b||) for a +- b, |c| ||a|| for c a, per stack element, recursively; stack_tangents() stacks them) – the floor max(||v||, operand scale), so it is never stricter than self-relative. That is the yardstick roundoff obeys: a - b of two gauged tangents agreeing to 1e-8 (a finite-difference check) inherits each operand’s ~1e-16 ||a|| gauge noise over a norm of only ~1e-8 ||a||, which self-relative would call ungauged. A tiny tangent that is ungauged by itself (not by cancellation) is still caught when checked itself; inside an arithmetic result the yardstick is the operands’ (a division by a small step scales it up too), so certify a computed tangent’s gauge on that tangent, not on a difference. The operand scale is recorded only when the arithmetic runs with checks active (safe mode, eager) and it is not part of the jax pytree: a tangent built under safety.unsafe()/a trace, or rebuilt by jax.tree_util (a jit round-trip), is measured self-relative – the conservative default. Backend twin: tv_gauge_residual() (its scale=).

Examples

>>> import numpy as np
>>> import t3toolbox.tucker_tensor_train as t3
>>> import t3toolbox.manifold as t3m
>>> np.random.seed(0)
>>> frame = t3m.MANIFOLD.frame(t3.TuckerTensorTrain.randn((5, 6, 7), (2, 3, 2), (1, 2, 2, 1)))
>>> a = t3m.MANIFOLD.randn(frame)
>>> b = a + 1e-8 * t3m.MANIFOLD.randn(frame)       # agrees with a to 1e-8, both gauged
>>> print(bool(t3m.MANIFOLD.norm(b - a) < 1e-7))   # safe mode accepts the near-cancelling difference
True
>>> print(bool((b - a).gauge_residual < 1e-14))    # gauged to roundoff, relative to the operands
True

A tiny tangent that is ungauged in its own right still fails:

>>> u = 1e-6 * t3m.COREWISE.randn(frame)          # raw coordinates: not gauged
>>> print(bool(u.is_gauged()), bool((a + u - a).is_gauged()))
False False
Return type:

NDArray