oversampled_ranks ================= .. py:function:: t3toolbox.backend.ranks.oversampled_ranks(shape, tucker_ranks, tt_ranks, p, sharing = None) .. code-block:: python def oversampled_ranks( shape: typ.Sequence[int], # len=d tucker_ranks: typ.Union[typ.Sequence[int], NDArray], # len=d, or HOST int (d,)+C tt_ranks: typ.Union[typ.Sequence[int], NDArray], # len=d+1, or HOST int (d+1,)+C p: int, # the rank increment, p >= 0 (structural) sharing: typ.Optional[typ.Sequence] = None, # len=d group labels; None = unshared ) -> typ.Tuple[ typ.Union[typ.Tuple[int, ...], NDArray], # tucker ranks: int tuple for sequences, HOST int (d,)+C for arrays typ.Union[typ.Tuple[int, ...], NDArray], # tt ranks: int tuple for sequences, HOST int (d+1,)+C for arrays ]: Oversampled working ranks: ``+p`` on every Tucker rank and interior bond, structurally minimal, never below the input. Returns the elementwise maximum of the input ranks and ``compute_minimal_ranks(shape, n + p, (1, r1 + p, ..., r(d-1) + p, 1), sharing)``. The reduction is the structural one (integer arithmetic, no SVD), with the shared notion under ``sharing``, so a sharing group keeps one Tucker rank. Consequences, all structural: * a minimal input gives a minimal output (the reduction is monotone, so the maximum is the reduced ``+p`` ranks), and ``p = 0`` returns a minimal input unchanged; * the output is never below the input -- a non-minimal input keeps its slack, so a working structure built from these ranks never undercuts the structure it oversamples. This is the one home of the working-rank rule of the padded start (iterate at the oversampled ranks, then truncate to the target). Integer sequences give Python-int tuples. HOST integer arrays ``(d,)+C`` / ``(d+1,)+C`` -- ranks per stack element, as :py:func:`compute_minimal_ranks` takes them -- give HOST integer arrays of the same shapes, every element its own sequence call. Boundary bonds above 1 (an unsquashed T3 sum) are kept as given, but the interior caps are computed as for boundary bonds 1 -- conservative. A negative or non-integer ``p`` is a ``ValueError``, as are wrong lengths and arrays of different stacks; non-integer ranks are a ``TypeError``. .. rubric:: Examples ``+p`` where the structure has room for it, capped where it does not (``N0 = 3``; the last interior bond is capped by ``N2 = 4`` through the boundary bond): >>> import t3toolbox.backend.ranks as ranks >>> ranks.oversampled_ranks((3, 10, 4), (2, 3, 2), (1, 2, 2, 1), 1) ((3, 4, 3), (1, 3, 3, 1)) >>> ranks.oversampled_ranks((3, 10, 4), (2, 3, 2), (1, 2, 2, 1), 5) ((3, 8, 4), (1, 3, 4, 1)) ``p = 0`` returns a minimal input unchanged, and a non-minimal input keeps its slack (here Tucker rank 5 at ``N0 = 3``) -- the output is never below the input: >>> ranks.oversampled_ranks((3, 10, 4), (2, 3, 2), (1, 2, 2, 1), 0) ((2, 3, 2), (1, 2, 2, 1)) >>> ranks.oversampled_ranks((3, 10, 4), (5, 3, 2), (1, 2, 2, 1), 1) ((5, 4, 3), (1, 3, 3, 1)) With sharing, a group keeps one Tucker rank. Modes 0 and 2 tied: the group ceiling adds the per-mode ceilings, so the tied rank grows to 3 although mode 0's bond product is ``1 * 2``; unshared, the same input grows only to 2 there: >>> ranks.oversampled_ranks((8, 3, 8), (2, 1, 2), (1, 1, 1, 1), 1, sharing=('a', 'b', 'a')) ((3, 2, 3), (1, 2, 2, 1)) >>> ranks.oversampled_ranks((8, 3, 8), (2, 1, 2), (1, 1, 1, 1), 1) ((2, 2, 2), (1, 2, 2, 1)) Ranks per stack element (columns of ``(d,)+C`` arrays, here ``C = (2,)``) are oversampled element by element: >>> import numpy as np >>> tucker, tt = ranks.oversampled_ranks((3, 10, 4), np.array([[2, 2], [3, 5], [2, 1]]), ... np.array([[1, 1], [2, 2], [2, 1], [1, 1]]), 1) >>> print(tucker.tolist(), tt.tolist()) [[3, 3], [4, 6], [3, 2]] [[1, 1], [3, 3], [3, 2], [1, 1]] >>> print(ranks.oversampled_ranks((3, 10, 4), (2, 5, 1), (1, 2, 1, 1), 1)) # the second column alone ((3, 6, 2), (1, 3, 2, 1))