UniformTuckerTensorTrain.randn#
- static t3toolbox.uniform_tucker_tensor_train.UniformTuckerTensorTrain.randn(shape, tucker_ranks, tt_ranks, stack_shape=(), use_jax=False)#
def randn( shape: Sequence[int], # (N0,...,N(d-1)) tucker_ranks: typ.Union[int, Sequence[int], NDArray], # int|len-d|(d,)+stack tt_ranks: typ.Union[int, Sequence[int], NDArray], # int|len-(d+1)|(d+1,)+stack stack_shape: Sequence[int] = (), use_jax: bool = False, ) -> 'UniformTuckerTensorTrain':
Uniform Tucker tensor train with random N(0,1) supercores (padded regions masked to zero).
tucker_ranks/tt_ranksaccept a scalar, a per-mode sequence, or a full(d,)+stack/(d+1,)+stackarray – the latter setting per-stack-element ranks (the variety) while keeping one padded supercore shape, which a ragged round-trip cannot express.Examples
>>> import numpy as np >>> import t3toolbox.uniform_tucker_tensor_train as ut3 >>> np.random.seed(0) >>> x = ut3.UniformTuckerTensorTrain.randn((5, 6, 7), (3, 4, 2), (1, 3, 2, 1), stack_shape=(2,)) >>> print(x.shape, x.stack_shape) (5, 6, 7) (2,) >>> print(np.reshape(x.tucker_ranks, (3, 2))[:, 0].tolist()) # uniform across the stack here [3, 4, 2] >>> print(bool(np.any(x.tucker_supercore != 0.0))) # random, not zeros True
Per-stack-element ranks (the variety): a full
(d,)+stackarray gives each stack element its own ranks under one padded shape.>>> tucker_ranks = np.array([[2, 4], [3, 5], [2, 3]]) # (d=3, stack=2) >>> tt_ranks = np.array([[1, 1], [2, 4], [2, 3], [1, 1]]) # (d+1=4, stack=2) >>> xv = ut3.UniformTuckerTensorTrain.randn((6, 7, 8), tucker_ranks, tt_ranks, stack_shape=(2,)) >>> print(np.asarray(xv.tucker_ranks).tolist()) # ranks genuinely differ per element [[2, 4], [3, 5], [2, 3]] >>> print(xv.n, xv.r) # one padded shape: n=max, r=max 5 4
- Parameters:
- Return type: