fv_aligned_padded_frame#
- t3toolbox.frame_variations_format.fv_aligned_padded_frame(x_old, tucker_ranks, tt_ranks, hint, project=None, sharing=None, oversampling=ALIGN_OVERSAMPLING, oversampled_passes=ALIGN_OVERSAMPLED_PASSES, max_passes=ALIGN_MAX_PASSES, tol=ALIGN_TOL, alternate=ALIGN_ALTERNATE, seed=ZERO_FRAME_SEED, use_jit=False)#
def fv_aligned_padded_frame( x_old: 't3.TuckerTensorTrain', # the old point; rank 0 = the zero tensor tucker_ranks: typ.Sequence[int], # len=d, target tt_ranks: typ.Sequence[int], # len=d+1, target hint: typ.Any, # TuckerTensorTrain / dense array, or anything with `project` project: typ.Optional[typ.Callable] = None, # project(frame.data, hint) -> variations data; None = by the hint's class sharing: typ.Optional[typ.Sequence] = None, # len=d group labels; None = unshared oversampling: int = ALIGN_OVERSAMPLING, # the backend's named defaults oversampled_passes: int = ALIGN_OVERSAMPLED_PASSES, max_passes: int = ALIGN_MAX_PASSES, tol: float = ALIGN_TOL, alternate: bool = ALIGN_ALTERNATE, seed: int = ZERO_FRAME_SEED, use_jit: bool = False, # jax inputs: a memoized jitted step in the host loop ) -> typ.Tuple[ 'T3Frame', # the aligned padded frame at the target ranks typ.Tuple[NDArray, ...], # movements, one per pass ]:
The padded frame of
x_oldat larger ranks, its new directions aligned with a hint.Purpose. At a zero-padded rank increase the point
x_oldgains zero slots, and its orthonormal frame needs new directions in every rank store (the four families of frame cores; see The frame-variations representation (and why the cores are numbered as they are), “Four rank stores”). Any completion represents the same point, but the tangent space – and so the first Newton step from it – depends on the choice. This function biases the completion toward a HINT: a tensor whose tangent projection should be as large as possible.optimizers.newton_cg(padded_from=x_old)uses the misfit gradient as the hint; here the hint is yours. The user guide is The aligned padded frame.Method. A fixed-point iteration on projections. It starts from the hint-free padded frame (
T3Frame.padded()). Each pass projects the hint onto the current frame’s tangent space and, at every store, replaces the new slots by the leading new directions of that projection’s content there, given the other stores’ current completions, with the old slots held fixed (align_padded()is one pass). The schedule:oversampled_passespasses at the target ranks plusoversampling;one truncating pass to the target;
then two-colour pairs: a
('D', 'L')pass (the down and left stores) and a('U', 'R')pass (the up and right stores), the other colour transported. A simultaneous update can cycle with period 2, which the pairs avoid.
The loop stops after a pair whose two movements are both below
tol, or atmax_passesin all. The movement of a pass is how far the new slots turned: the largest, over the stores, of‖g_old − P⁺P⁺ᵀ g_old‖_F.What the fixed point satisfies. At a fixed point, every store’s completion spans the leading new directions of its own content, given the other stores’ completions, so one more pass moves nothing. The completions are then a stationary point of the captured hint energy
‖Π_{T(F)} hint‖²(proved for matrices, measured on T3s) but generally not a maximum of it: rotating one store’s completion alone never lowers that energy and generically raises it at second order. In measurements on small trees, they are a strict local maximum of the cone merit, one of many. Updating any single store alone moves nothing either; the first example shows both. The cone merit is the share of the hint’s normal part that the new directions represent on one side of every edge; its best value does not depend on which side. See the math notedocs/padded_frame_cone.pdf.Properties.
No global guarantee. The merit has many strict local maxima in the measurements (an excursion across several edges is captured only when every edge it crosses is aligned with it), and the one reached depends on the start and the schedule. Oversampling sees such excursions through each edge and usually helps (see the second example).
Representation dependence. The hint-free start is a function of
x_old’s frame AS REPRESENTED, slot signs included: its Gaussian seeds do not flip with a slot’s sign, and bases chosen differently at singular-value ties (at3svdoutput, a shared point) give different starts. Different BLAS builds can therefore give different hint-free starts. The aligned output does not have this dependence, up totol.Uninformative hints. Where the hint has no content at an edge (its projection there has rank below the new slots), the remaining directions are an arbitrary valid completion.
The old slots are bitwise
x_old’s frame, and the frame representsx_oldzero-padded.
Parameters.
hint: aTuckerTensorTrain(projected bytv_project_t3_onto_tangent_space) or a dense array ofx_old’s shape (tv_project_dense_onto_tangent_space). Anything else needsproject(frame_data, hint), returning raw variation data. AUniformTuckerTensorTrainhint must be converted first (hint.to_t3()); passing one raises aTypeErrornaming the conversion.oversamplingandoversampled_passes: passes at wider working ranks before the truncation. The phase is skipped when the working ranks give the target’s stores.max_passes: the cap, the truncating pass included.0returns the hint-free start.tol: the pair stop. The default0.05is a coarse alignment; with a smalltolthe cap is often the effective stop.alternate: the two-colour switch.Falseruns simultaneous all-store passes, stopping on one movement.seed: the hint-free start’s seed streams.use_jit: see the gotchas.Returns
(frame, movements): the alignedT3Frameand one movement per pass run (each of shapeC). When the target adds nothing tox_old’s structure, the frame isx_old’s and there are no passes.
Gotchas.
Eager jax is expensive. On jax arrays without
use_jit, every new structure compiles hundreds of operations one by one: about 22 s for the first step at d = 4, and 8,000–9,500 process memory mappings per alignment. A rank continuation that aligns eagerly at every level can reach Linux’svm.max_map_countafter about seven levels and abort inside XLA. With jax inputs, passuse_jit=True: each step becomes a memoized jitted program, two to four per level. numpy inputs need nothing.max_passescounts the truncating pass, and the stop is tested on pairs only, never on the truncating pass.A NaN movement never stops the loop.
Zero passes at the zero tensor give the hint-free start, which is not
fv_zero_point_frame’s frame. So innewton_cg,g0_reference='cone'withcone_max_passes=0is a different reference from'zero'.
x_oldis reduced to minimal ranks first. A structurally zerox_old(any Tucker or interior TT rank 0) is the zero tensor, with an empty frame.Examples
Align a padded frame with a hint, and check what the fixed point satisfies:
>>> import numpy as np >>> import t3toolbox.tucker_tensor_train as t3 >>> import t3toolbox.frame_variations_format as bvf >>> import t3toolbox.manifold as t3m >>> np.random.seed(0) >>> shape, old, target = (5, 6, 5, 6), ((2, 2, 2, 2), (1, 2, 2, 2, 1)), ((3, 4, 4, 3), (1, 3, 4, 3, 1)) >>> x_old = t3.TuckerTensorTrain.randn(shape, *old) >>> hint = t3.TuckerTensorTrain.randn(shape, (5, 6, 5, 6), (1, 5, 25, 6, 1)) >>> captured = lambda F: float(t3m.MANIFOLD.norm(t3m.MANIFOLD.project_ambient(F, hint))) # ‖Π_T(F) hint‖ >>> F, movements = bvf.fv_aligned_padded_frame(x_old, *target, hint, tol=1e-10, max_passes=300) >>> F.down_ranks, len(movements) < 300 # stopped on tol, not on the cap ((3, 4, 4, 3), True)
One more pass moves nothing, and neither does a pass updating any one store alone (
align_paddedis one pass; the stores not inupdateare transported): each completion already spans the leading directions of its content.>>> tangent = t3m.MANIFOLD.project_ambient(F, hint) >>> bool(float(tangent.align_padded(*old)[1]) < 1e-8) True >>> [bool(float(tangent.align_padded(*old, update=(store,))[1]) < 1e-8) for store in ('D', 'U', 'L', 'R')] [True, True, True, True]
The aligned frame’s tangent space holds far more of the hint than the hint-free start’s:
>>> captured(F) > 2 * captured(bvf.T3Frame.padded(x_old, *target)) True
Oversampling helps at an equal (small) number of passes. Here, on a d = 5 point and a low-rank hint, two passes with the first one oversampled capture well over 1.2 times what two passes at the target ranks capture (the margin held for every start seed tried):
>>> np.random.seed(0) >>> y_old = t3.TuckerTensorTrain.randn((5,) * 5, (2,) * 5, (1, 2, 2, 2, 2, 1)) >>> y_hint = t3.TuckerTensorTrain.randn((5,) * 5, (4,) * 5, (1, 4, 6, 6, 4, 1)) >>> y_target = ((3,) * 5, (1, 3, 3, 3, 3, 1)) >>> y_captured = lambda F: float(t3m.MANIFOLD.norm(t3m.MANIFOLD.project_ambient(F, y_hint))) >>> F0, _ = bvf.fv_aligned_padded_frame(y_old, *y_target, y_hint, oversampling=0, max_passes=2, tol=0.0) >>> F5, _ = bvf.fv_aligned_padded_frame(y_old, *y_target, y_hint, oversampling=5, max_passes=2, tol=0.0) >>> y_captured(F5) > 1.2 * y_captured(F0) True
- Parameters:
x_old (TuckerTensorTrain)
tucker_ranks (t3toolbox.backend.common.typ.Sequence[int])
tt_ranks (t3toolbox.backend.common.typ.Sequence[int])
hint (t3toolbox.backend.common.typ.Any)
project (t3toolbox.backend.common.typ.Optional[t3toolbox.backend.common.typ.Callable])
sharing (t3toolbox.backend.common.typ.Optional[t3toolbox.backend.common.typ.Sequence])
oversampling (int)
oversampled_passes (int)
max_passes (int)
tol (float)
alternate (bool)
seed (int)
use_jit (bool)
- Return type:
t3toolbox.backend.common.typ.Tuple[T3Frame, t3toolbox.backend.common.typ.Tuple[NDArray, …]]