ut3_probe_corewise_derivatives_hessian#

t3toolbox.backend.ut3_sampling.ut3_probe_corewise_derivatives_hessian(ztildes, ww, pp, data, core_directions, order, chunk_size=sampling_derivatives.DEFAULT_CHUNK_SIZE)#
def ut3_probe_corewise_derivatives_hessian(
        ztildes:          typ.Sequence[NDArray],   # residual jets (omega^2 applied), len=d, elm_shape=(order+1,)+W+C+(Ni,)
        ww:               typ.Sequence[NDArray],   # probe vectors X,        len=d, elm_shape=W+(Ni,)
        pp:               typ.Sequence[NDArray],   # perturbation vectors P, len=d, elm_shape=W+(Ni,)
        data:             UT3Data,                 # the point theta, stack C
        core_directions:  typ.Tuple[NDArray, NDArray],  # bare raw direction supercores theta_hat, (d,)+K+C+(...)
        order:            int,                     # highest derivative order
        chunk_size:       typ.Optional[int] = sampling_derivatives.DEFAULT_CHUNK_SIZE,  # W-chunk size; None -> dense
) -> typ.Tuple[NDArray, NDArray]:                  # (Tucker, TT) blocks of K theta_hat, (d,)+K+C+(...), W summed

The uniform twin of t3_probe_corewise_derivatives_hessian(): the core-coordinate Hessian of theta -> <z~, S(Phi(theta))> applied to theta_hat, for S the probe-derivative jets, on supercores.

theta is masked with its masks, theta_hat with the SAME masks, ztildes / ww / pp packed to N; the polymorphic kernel runs on the supercores (its chunk_size W-chunks the assemblies), and the output is re-masked with theta’s masks. Per stack element the real block is the ragged two-hole of the real blocks, whatever the padding of theta, theta_hat, the residual or the sample holds.

Examples

With garbage in every padded slot of the direction, the real block is the ragged two-hole’s and the padding is exactly zero; the bare kernel on the unmasked direction is not (the mask is load-bearing):

>>> import numpy as np
>>> import t3toolbox.tucker_tensor_train as t3
>>> import t3toolbox.uniform_tucker_tensor_train as ut3
>>> import t3toolbox.backend.sampling_derivatives as sd
>>> import t3toolbox.backend.ut3_masking as ut3m
>>> import t3toolbox.backend.ut3_sampling as ut3s
>>> np.random.seed(0)
>>> rng = np.random.default_rng(0)
>>> shape, order, W = (4, 5, 3), 2, 6
>>> theta, direction = (t3.TuckerTensorTrain.randn(shape, (2, 3, 2), (1, 2, 2, 1)) for _ in range(2))
>>> ww, pp = ([rng.standard_normal((W, N)) for N in shape] for _ in range(2))
>>> zt = [rng.standard_normal((order + 1, W, N)) for N in shape]
>>> u = ut3.UniformTuckerTensorTrain.from_t3(theta, N=6, n=4, r=4).data
>>> ud = ut3.UniformTuckerTensorTrain.from_t3(direction, N=6, n=4, r=4).data
>>> pad = [1.0 - m for m in ut3m.ut3_apply_masks((np.ones_like(ud[0]), np.ones_like(ud[1]), ud[2], ud[3]))]
>>> dirty = (ud[0] + 1e3 * pad[0], ud[1] + 1e3 * pad[1])               # garbage in the direction's padding
>>> KB, KG = ut3s.ut3_probe_corewise_derivatives_hessian(zt, ww, pp, u, dirty, order)
>>> ref = sd.t3_probe_corewise_derivatives_hessian(zt, ww, pp, theta.data, direction.data, order)
>>> all(np.allclose(KG[i][:G.shape[0], :G.shape[1], :G.shape[2]], G) for i, G in enumerate(ref[1]))
True
>>> float(np.abs(KG * pad[1]).max()), float(np.abs(KB * pad[0]).max())   # the padding: exactly zero
(0.0, 0.0)
>>> import t3toolbox.backend.ut3_operations as ut3o
>>> pk = lambda v: ut3o.pack_if_ragged(v, 6)
>>> bare = sd.t3_probe_corewise_derivatives_hessian(pk(zt), pk(ww), pk(pp), ut3m.ut3_apply_masks(u), dirty, order)
>>> all(np.allclose(bare[1][i][:G.shape[0], :G.shape[1], :G.shape[2]], G) for i, G in enumerate(ref[1]))
False
Parameters:
  • ztildes (t3toolbox.backend.common.typ.Sequence[NDArray])

  • ww (t3toolbox.backend.common.typ.Sequence[NDArray])

  • pp (t3toolbox.backend.common.typ.Sequence[NDArray])

  • data (UT3Data)

  • core_directions (t3toolbox.backend.common.typ.Tuple[NDArray, NDArray])

  • order (int)

  • chunk_size (t3toolbox.backend.common.typ.Optional[int])

Return type:

t3toolbox.backend.common.typ.Tuple[NDArray, NDArray]