T3Variations#

class t3toolbox.frame_variations_format.T3Variations#

Tuple containing variation cores for frame-variation representations of TuckerTensorTrains.

Components
  • tucker_variations = (V0, …, V(d-1)), elm_shape=stack_shape+(nDi, Ni)

  • tt_variations = (H0, …, H(d-1)), elm_shape=stack_shape+(rLi, nUi, rRi)

The variations should fit in the “holes” of a T3Frame.

See also

T3Frame

Examples

Build variations that fill the holes of a base point (so check_fv_pair accepts them):

>>> import numpy as np
>>> import t3toolbox.frame_variations_format as bvf
>>> ss = (2, 3)                                       # stack shape, shared by frame and variations
>>> up_tucker_cores = (np.ones(ss+(10, 14)), np.ones(ss+(11, 15)), np.ones(ss+(12, 16)))
>>> left_tt_cores = (np.ones(ss+(1, 10, 2)), np.ones(ss+(2, 11, 3)), np.ones(ss+(3, 12, 5)))
>>> right_tt_cores = (np.ones(ss+(2, 10, 4)), np.ones(ss+(4, 11, 5)), np.ones(ss+(5, 12, 1)))
>>> down_tt_cores = (np.ones(ss+(1, 9, 4)), np.ones(ss+(2, 8, 5)), np.ones(ss+(3, 7, 1)))
>>> frame = bvf.T3Frame(up_tucker_cores, down_tt_cores, left_tt_cores, right_tt_cores)
>>> tucker_shapes, tt_shapes = frame.variation_shapes  # the holes to fill
>>> tucker_variations = tuple(np.ones(ss + s) for s in tucker_shapes)
>>> tt_variations = tuple(np.ones(ss + s) for s in tt_shapes)
>>> variations = bvf.T3Variations(tucker_variations, tt_variations)
>>> print(variations.variation_shapes == frame.variation_shapes)   # fits the frame's holes exactly
True
tucker_variations: t3toolbox.backend.common.typ.Tuple[NDArray, Ellipsis]#
tt_variations: t3toolbox.backend.common.typ.Tuple[NDArray, Ellipsis]#
__rmul__#

Methods#

d()

shape()

stack_shape()

The full leading stack K + C shared by every variation core.

variation_shapes()

T3Variations shapes that fit with this T3Frame.

data()

to_jax()

Copy with all variation cores converted to jax arrays.

to_numpy()

Copy with all variation cores converted to numpy arrays.

copy()

Deep copy (copies every variation core).

contains_jax()

True if any variation core is a jax array.

size()

Number of elements of the represented dense tensor (prod(shape)).

data_size()

Number of stored core entries (size on disk).

__repr__()

validate()

Check rank and shape consistency of Tucker tensor train variations (T3Variations).

__post_init__()

unstack()

Unstack into an array-like tree.

stack(xx)

Stack array-like tree of T3Variations into a single T3Variation.

zeros(variation_shapes[, stack_shape, use_jax])

Zero variations of the given structure (additive identity).

randn(variation_shapes[, stack_shape, use_jax])

Variations with i.i.d. N(0,1) core entries (corewise, ungauged). See randn_like().

unit(variation_shapes, index[, stack_shape, use_jax])

Canonical unit variation: zero except a single core entry set to 1.

zeros_like(x)

Zero variations matching the structure (shapes + stack) of x (a T3Frame or T3Variations).

randn_like(x)

Random variations matching the structure (shapes + stack) of x (a T3Frame or T3Variations).

to_vector()

Flatten the variation cores to a 1D vector (the tangent's degrees of freedom).

from_vector(flat, variation_shapes[, stack_shape])

Inverse of to_vector(): rebuild variations of the given structure from a 1D vector.

save(file)

Save the variation cores to a .npz file (load with load()).

load(file[, use_jax])

Load variations saved by save().

reverse()

Reverse the mode order (corewise): reverse the tucker-variation order and reverse+transpose

sum_stack([axis])

Corewise sum over stack axes (a batch of variations -> their sum). axis indexes the stack

__add__(other)

Corewise sum (variations form a vector space).

__sub__(other)

Corewise difference.

__mul__(scalar)

Corewise scalar multiplication.

__neg__()

Corewise negation.

allclose(other[, rtol, atol])

True (per stack element) if other holds the same variations as self, corewise.