tv_gauge_residual#
- t3toolbox.backend.tv_operations.tv_gauge_residual(frame, variations, scale=None)#
def tv_gauge_residual( frame: typ.Tuple[ typ.Sequence[NDArray], # down_tucker_cores typ.Sequence[NDArray], # up_tt_cores typ.Sequence[NDArray], # left_tt_cores typ.Sequence[NDArray], # right_tt_cores ], variations: typ.Tuple[ typ.Sequence[NDArray], # tucker_variations typ.Sequence[NDArray], # tt_variations ], scale: typ.Optional[NDArray] = None, # operand scale, broadcastable to K+C (trailing axes), >= 0; None = own norm ) -> NDArray: # shape = variation stack_shape (K+C); per stack element (scalar/0-d when unstacked)
Max violation of the gauge conditions for a tangent vector, per stack element.
The gauged tangent space requires each tucker variation orthogonal to its down-core, and each left-interior tt variation orthogonal to its left-core (see
tv_orthogonal_gauge_projection()). Relative: the gauge gramsD V^T/L^T Hare divided by the coordinate norm of the WHOLE tangent (all variation cores, per stack element;D/Lare orthonormal, so the ratio is in[0, 1], a zero tangent is trivially gauged, and a single vanishing core – e.g. the first TT variation at a rank-1 bond – does not divide noise by noise). Returns the max over the checks, reduced over the non-stack axes (shape = the variation stackK+C); a caller thresholds it against a RELATIVE tolerance. (Until 2026-08-22 this was the absolutemax|D V^T|, which scales with the tangent: a correctly gauged tangent of norm>~1e8– or>~50on jax float32 – failed the safe-mode check, and a tiny ungauged one passed.)The operand scale (
scale). Relative-to-itself is the right yardstick for a tangent computed directly (a projection, a gradient), but not for one formed by cancellation:a - bof two gauged tangents that agree to1e-8(the finite-difference checkH_fd - H p) carries each operand’s roundoff gauge violation,~1e-16 * ||a||, over a norm of only~1e-8 * ||a||– self-relative~1e-8, a false failure at a1e-9tolerance. Pass the operands’ scale –max(||a||, ||b||)fora +- b,|c| * ||a||forc * a(per stack element; the norms fromcorewise_stack_norm()) – and the grams are divided bymax(||v||, scale)instead: a floor on the denominator, so passing a scale never makes the check stricter than the default andscale = 0is the default.scaleis broadcast against the stackK+Cby numpy’s trailing-axis rule (a scalar, aC-shaped or aK+C-shaped array); any other shape raises.scale=None(the default) is the self-relative residual, unchanged. The frontendT3Tangenttracks this for you (gauge_residual).Examples
Two gauged tangents that agree to
1e-8: their difference is gauged to roundoff relative to the operands, not relative to its own tiny norm:>>> import numpy as np >>> import t3toolbox.tucker_tensor_train as t3 >>> import t3toolbox.manifold as t3m >>> import t3toolbox.corewise as cw >>> import t3toolbox.backend.tv_operations as tvo >>> 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).variations.data # gauged to roundoff >>> b = cw.corewise_add(a, cw.corewise_scale(t3m.MANIFOLD.randn(frame).variations.data, 1e-8)) >>> diff = cw.corewise_sub(a, b) # norm ~1e-8 * ||a|| >>> print(float(tvo.tv_gauge_residual(frame.data, diff)) > 1e-9) # self-relative: noise / tiny norm True >>> s = np.maximum(cw.corewise_stack_norm(a, 0), cw.corewise_stack_norm(b, 0)) >>> print(float(tvo.tv_gauge_residual(frame.data, diff, scale=s)) < 1e-14) # relative to the operands True
- Parameters:
frame (t3toolbox.backend.common.typ.Tuple[t3toolbox.backend.common.typ.Sequence[NDArray], t3toolbox.backend.common.typ.Sequence[NDArray], t3toolbox.backend.common.typ.Sequence[NDArray], t3toolbox.backend.common.typ.Sequence[NDArray]])
variations (t3toolbox.backend.common.typ.Tuple[t3toolbox.backend.common.typ.Sequence[NDArray], t3toolbox.backend.common.typ.Sequence[NDArray]])
scale (t3toolbox.backend.common.typ.Optional[NDArray])
- Return type: