probe_derivatives_model#
- t3toolbox.fitting.probe_derivatives_model(geometry, x, ww, pp, order, residual, weight=None, regularizer=None, hessian='gauss_newton', curvature_damping=None)#
def probe_derivatives_model( geometry, # MANIFOLD / COREWISE (or the UNIFORM_* twin for a uniform x) x: typ.Union[t3.TuckerTensorTrain, ut3.UniformTuckerTensorTrain], # the current point 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,) order: int, residual: typ.Sequence[NDArray], # RAW r = probe_derivatives(x) − y, len=d, elm_shape=(order+1)+W+C+(Ni,) weight: typ.Optional[typ.Any] = None, # residual weight ω[mode,order], (d,order+1) broadcast; None = 1 regularizer: typ.Any = None, # optional regularizer, e.g. optimizers.IdentityRegularizer(λ) hessian: str = 'gauss_newton', # or 'exact' (case-insensitive): the model's mode curvature_damping: typ.Optional[float] = None, # exact only: the lift damping; None = the geometry's ) -> LocalModel:
The
probe-derivatives local model – vector-valued (one free mode per probe), soresidualis a sequence ofdjets. Probe has both a mode and an order axis, soweightis the fullω[mode, order]matrix(d, order+1): a bare row(order+1,)= per-order (broadcast over modes), a column(d, 1)= per-mode (broadcast over orders), a matrix = both. The objective is½ Σ_i ‖ω_i ⊙ r_i‖²over thedper-mode residual jets.hessian='exact'builds the exact-Hessian model (LocalModel):LocalModel.hessian()adds the curvature term to the Gauss-Newton one.curvature_damping(exact only) is the damping of the lift from frame coordinates to core variations, relative to‖X‖_HS–Nonefor the geometry’s default (backend.geometry.DEFAULT_CURVATURE_DAMPING); a value withhessian='gauss_newton'or on a corewise geometry raises, as nothing would read it. The ragged manifold and corewise geometries, the uniform ones (a uniformx; per stack element the ragged model’s) and the shared wrappers of all four support it (on a shared manifold the curvature goes through the tied lift).Examples
On a noisy fit the exact model’s quadratic form is the objective’s second derivative along the retraction, where the Gauss-Newton one misses the curvature term:
>>> import numpy as np >>> import t3toolbox.tucker_tensor_train as t3 >>> import t3toolbox.manifold as t3m >>> import t3toolbox.fitting as fitting >>> np.random.seed(0) >>> shape, ranks = (4, 5, 6), ((2, 2, 2), (1, 2, 2, 1)) >>> ww, pp = [np.random.randn(20, N) for N in shape], [np.random.randn(20, N) for N in shape] >>> y = t3.TuckerTensorTrain.randn(shape, *ranks).probe_derivatives(ww, pp, 1) # data from another tensor >>> def model_at(x, hessian='gauss_newton'): ... r = [z - yi for z, yi in zip(x.probe_derivatives(ww, pp, 1), y)] ... return fitting.probe_derivatives_model(t3m.MANIFOLD, x, ww, pp, 1, r, hessian=hessian) >>> x = t3.TuckerTensorTrain.randn(shape, *ranks) >>> gn, exact = model_at(x), model_at(x, hessian='exact') >>> gn.is_exact, exact.is_exact (False, True) >>> p = exact.gradient * (1.0 / float(t3m.MANIFOLD.norm(exact.gradient))) # a unit tangent >>> f = lambda t: float(model_at(exact.retract(p * t)).objective_value) >>> fd = (f(1e-3) - 2 * f(0.0) + f(-1e-3)) / 1e-6 # d²/dt² f(retract(t p)) >>> bool(np.isclose(float(exact.quadratic(p)), fd, rtol=1e-4)) True >>> bool(np.isclose(float(gn.quadratic(p)), fd, rtol=1e-2)) False
hessian(p)is the matching action (⟨p, H p⟩ == quadratic(p)), the Gauss-Newton one plus the curvature term:>>> bool(np.isclose(float(p.corewise_inner(exact.hessian(p))), float(exact.quadratic(p)))) True >>> bool(np.allclose(float(p.corewise_inner(exact.hessian(p) - exact.gn_hessian(p))), ... float(exact.curvature_quadratic(p)))) True
The curvature term exists only on an exact model:
>>> gn.curvature_quadratic(p) Traceback (most recent call last): ValueError: LocalModel.curvature_quadratic needs an exact-mode model
- Parameters:
x (t3toolbox.backend.common.typ.Union[TuckerTensorTrain, UniformTuckerTensorTrain])
ww (t3toolbox.backend.common.typ.Sequence[NDArray])
pp (t3toolbox.backend.common.typ.Sequence[NDArray])
order (int)
residual (t3toolbox.backend.common.typ.Sequence[NDArray])
weight (t3toolbox.backend.common.typ.Optional[t3toolbox.backend.common.typ.Any])
regularizer (t3toolbox.backend.common.typ.Any)
hessian (str)
curvature_damping (t3toolbox.backend.common.typ.Optional[float])
- Return type: