t3_entries_corewise_hessian#

t3toolbox.backend.entries.t3_entries_corewise_hessian(c, index, core_pair, core_directions)#
def t3_entries_corewise_hessian(
        c:                  NDArray,                # residual (omega^2 applied), shape=W+C
        index:              NDArray,                # int, shape=(d,)+W
        core_pair:          typ.Tuple[
            typ.Sequence[NDArray],                  # tucker_cores of theta. len=d, elm_shape=C+(ni,Ni)
            typ.Sequence[NDArray],                  # tt_cores of theta.     len=d, elm_shape=C+(ri,ni,r(i+1))
        ],                                          # = TuckerTensorTrain.data
        core_directions:    typ.Tuple[
            typ.Sequence[NDArray],                  # Tucker directions theta_hat. len=d, elm_shape=K+C+(ni,Ni)
            typ.Sequence[NDArray],                  # TT directions theta_hat.     len=d, elm_shape=K+C+(ri,ni,r(i+1))
        ],
) -> typ.Tuple[
    typ.Tuple[NDArray, ...],                        # Tucker block of K theta_hat. len=d, elm_shape=K+C+(ni,Ni)
    typ.Tuple[NDArray, ...],                        # TT block of K theta_hat.     len=d, elm_shape=K+C+(ri,ni,r(i+1))
]:

The derivative of t3_entries_corewise_transpose() along core directions: the core-coordinate Hessian of theta -> <c, entries(Phi(theta), index)> applied to theta_hat – the exact Hessian’s sampling term for entries. Identical to t3_apply_corewise_hessian() with the upward xi / xi_dot from slicing Tucker-core fibers at index and the apply vectors replaced by the unit vectors e_index (so the Tucker block is the entry scatter). Stacks, polymorphism and the mask-free contract as there; index semantics are numpy’s (the module note).

Examples

>>> import numpy as np
>>> import t3toolbox.backend.t3_constructors as t3k
>>> import t3toolbox.backend.entries as t3e
>>> np.random.seed(0)                                                  # t3_corewise_randn draws from it
>>> rng = np.random.default_rng(0)
>>> shape, W = (4, 5, 3), 6
>>> theta = t3k.t3_corewise_randn(shape, (2, 3, 2), (1, 2, 2, 1))
>>> index = np.stack([rng.integers(0, N, size=W) for N in shape])     # (d,)+W grid points
>>> c = rng.standard_normal(W)
>>> dirs = (tuple(rng.standard_normal((2,) + u.shape) for u in theta[0]),
...         tuple(rng.standard_normal((2,) + g.shape) for g in theta[1]))
>>> KB, KG = t3e.t3_entries_corewise_hessian(c, index, theta, dirs)
>>> one = lambda cores: t3e.t3_entries_corewise_transpose(c, index, cores, sum_over_probes=True)
>>> shift = lambda h: tuple(tuple(x + h * dx[0] for x, dx in zip(xs, dxs)) for xs, dxs in zip(theta, dirs))
>>> fd = [(a - b) / 2e-4 for a, b in zip(sum(one(shift(1e-4)), ()), sum(one(shift(-1e-4)), ()))]
>>> bool(max(np.linalg.norm(k[0] - f) / np.linalg.norm(f) for k, f in zip(KB + KG, fd)) < 1e-6)
True
Parameters:
  • c (NDArray)

  • index (NDArray)

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

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

Return type:

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