t3_entries_corewise_derivatives_hessian#

t3toolbox.backend.sampling_derivatives.t3_entries_corewise_derivatives_hessian(c, index, pp, core_pair, core_directions, order)#
def t3_entries_corewise_derivatives_hessian(
        c:                  NDArray,                # residual jet (omega^2 applied), shape=(order+1,)+W+C
        index:              NDArray,                # int, shape=(d,)+W -- the grid points
        pp:                 typ.Sequence[NDArray],  # perturbation vectors P, len=d, elm_shape=W+(Ni,)
        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))
        ],
        order:              int,                    # highest derivative order
) -> 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_derivatives_transpose() along core directions: the core-coordinate Hessian of theta -> <c, S(Phi(theta))> applied to theta_hat, for S the entry-derivative jets at the grid points index – the exact Hessian’s sampling term for entries_derivatives. Identical to t3_apply_corewise_derivatives_hessian() with the upward jet’s order 0 from slicing Tucker-core fibers at index and the ambient jet (e_index, P) (so the Tucker block scatters onto the indexed rows); at order = 0 the plain t3_entries_corewise_hessian(). Stacks, polymorphism and the mask-free contract as there; index semantics are numpy’s.

Examples

>>> import numpy as np
>>> import t3toolbox.backend.t3_constructors as t3k
>>> import t3toolbox.backend.sampling_derivatives as sd
>>> np.random.seed(0)                                                  # t3_corewise_randn draws from it
>>> rng = np.random.default_rng(0)
>>> shape, order, W = (4, 5, 3), 2, 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
>>> pp = [rng.standard_normal((W, N)) for N in shape]
>>> c = rng.standard_normal((order + 1, 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 = sd.t3_entries_corewise_derivatives_hessian(c, index, pp, theta, dirs, order)
>>> one = lambda cores: sd.t3_entries_corewise_derivatives_transpose(c, index, pp, cores, order,
...                                                                  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)

  • pp (t3toolbox.backend.common.typ.Sequence[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]])

  • order (int)

Return type:

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