ut3_sharing_residual#

t3toolbox.backend.sharing.ut3_sharing_residual(data, sharing)#
def ut3_sharing_residual(
        data:       typ.Tuple[
            NDArray,             # tucker_supercore, shape=(d,)+stack+(n,N)
            NDArray,             # tt_supercore,     shape=(d,)+stack+(r,n,r)
            typ.Sequence[int],   # shape, static int tuple
            typ.Tuple[NDArray, NDArray],  # (tucker_edge_mask, tt_edge_mask), HOST bool, static
        ],
        sharing:    typ.Sequence,   # len=d, static; one hashable group label per mode
) -> NDArray:  # shape = stack_shape; max relative factor deviation per stack element (0 == exactly tied)

The uniform twin of t3_sharing_residual(): per stack element, the max over groups and group modes of ||B_i - B_ref||_F / ||B_ref||_F on the MASKED factor content (padding is don’t-care garbage, so it is zeroed before comparing – two elements tied on their real content are tied regardless of their padding). Structural problems – invalid partition, unequal Tucker rank masks within a group – raise unconditionally.

Examples

>>> import numpy as np
>>> import t3toolbox.tucker_tensor_train as t3
>>> import t3toolbox.uniform_tucker_tensor_train as ut3
>>> import t3toolbox.backend.sharing as sharing
>>> np.random.seed(0)
>>> x = t3.TuckerTensorTrain.randn((6, 6, 5), (3, 3, 2), (1, 2, 2, 1))
>>> tk, tt = x.data
>>> tied = t3.TuckerTensorTrain((tk[0], tk[0], tk[2]), tt)   # tie modes 0, 1
>>> u = ut3.UniformTuckerTensorTrain.from_t3(tied)
>>> print(float(sharing.ut3_sharing_residual(u.data, (0, 0, 1))))
0.0
>>> u2 = ut3.UniformTuckerTensorTrain.from_t3(x)             # untied
>>> print(bool(sharing.ut3_sharing_residual(u2.data, (0, 0, 1)) > 0.1))
True
Parameters:
  • data (t3toolbox.backend.common.typ.Tuple[NDArray, NDArray, t3toolbox.backend.common.typ.Sequence[int], t3toolbox.backend.common.typ.Tuple[NDArray, NDArray]])

  • sharing (t3toolbox.backend.common.typ.Sequence)

Return type:

NDArray