ut3_probe_corewise_hessian#
- t3toolbox.backend.ut3_sampling.ut3_probe_corewise_hessian(ztildes, ww, data, core_directions)#
def ut3_probe_corewise_hessian( ztildes: typ.Union[typ.Sequence[NDArray], NDArray], # residuals (omega^2 applied), len=d, elm_shape=W+C+(Ni,); or packed ww: typ.Union[typ.Sequence[NDArray], NDArray], # probe vectors, len=d, elm_shape=W+(Ni,); or packed data: UT3Data, # the point theta, stack C core_directions: typ.Tuple[NDArray, NDArray], # bare raw direction supercores theta_hat, (d,)+K+C+(...) ) -> typ.Tuple[NDArray, NDArray]: # (Tucker, TT) blocks of K theta_hat, (d,)+K+C+(...), W summed
The uniform twin of
t3_probe_corewise_hessian(): the core-coordinate Hessian oftheta -> <z~, probe(Phi(theta))>applied totheta_hat, on supercores.thetais masked with its masks,theta_hatwith the SAME masks,ztildes/wwpacked toN, 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.probing as t3p >>> 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, W = (4, 5, 3), 6 >>> theta, direction = (t3.TuckerTensorTrain.randn(shape, (2, 3, 2), (1, 2, 2, 1)) for _ in range(2)) >>> ww, zt = ([rng.standard_normal((W, N)) for N in shape] for _ in range(2)) >>> 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_hessian(zt, ww, u, dirty) >>> ref = t3p.t3_probe_corewise_hessian(zt, ww, theta.data, direction.data) >>> 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:
- Return type: