ut3_apply_corewise_derivatives_hessian#

t3toolbox.backend.ut3_sampling.ut3_apply_corewise_derivatives_hessian(c, ww, pp, data, core_directions, order)#
def ut3_apply_corewise_derivatives_hessian(
        c:                NDArray,                       # residual jet (omega^2 applied), shape=(order+1,)+W+C

        ww:               typ.Union[typ.Sequence[NDArray], NDArray],  # apply vectors X, len=d, elm_shape=W+(Ni,); or packed
        pp:               typ.Union[typ.Sequence[NDArray], NDArray],  # perturbation vectors P, likewise

        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
) -> typ.Tuple[NDArray, NDArray]:                        # (Tucker, TT) blocks of K theta_hat, (d,)+K+C+(...), W summed

The uniform twin of t3_apply_corewise_derivatives_hessian(): the core-coordinate Hessian of theta -> <c, S(Phi(theta))> applied to theta_hat, for S the apply-derivative jets, on supercores. theta is masked with its masks, theta_hat with the SAME masks, ww / pp packed to N, and the output re-masked; per stack element the real block is the ragged two-hole of the real blocks, whatever the padding 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:

>>> 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))
>>> c = rng.standard_normal((order + 1, W))
>>> 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_apply_corewise_derivatives_hessian(c, ww, pp, u, dirty, order)
>>> ref = sd.t3_apply_corewise_derivatives_hessian(c, 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)
Parameters:
  • c (NDArray)

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

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

  • data (UT3Data)

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

  • order (int)

Return type:

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