apply_derivatives_model#
- t3toolbox.fitting.apply_derivatives_model(geometry, x, ww, pp, order, residual, weight=None, regularizer=None, hessian='gauss_newton', curvature_damping=None)#
def apply_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, # highest derivative order residual: NDArray, # RAW r = apply_derivatives(x) − y, shape (order+1)+W+C weight: typ.Optional[typ.Any] = None, # ORDER-only residual weight ω, (order+1,); 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 local model of an
apply-derivatives least-squares objective atx: the symmetric directional derivatives (orders0..order) of the all-modes apply, in directionP.The all-modes apply contracts every mode into a scalar, so
weightis order-only (a per-mode weight is a structural error – mode weighting is defined only for probe; seeprobe_derivatives_model()).hessian='exact'builds the exact model, its curvature term the apply-derivative two-hole atomega^2 r(t3_apply_corewise_derivatives_hessian()).Examples
>>> 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) >>> x = t3.TuckerTensorTrain.randn((6, 7, 8), (2, 3, 2), (1, 2, 2, 1)) >>> ww = [np.random.randn(15, N) for N in (6, 7, 8)] # 15 samples >>> pp = [np.random.randn(15, N) for N in (6, 7, 8)] # one direction P per sample >>> r = np.random.randn(4, 15) # RAW residual jet, (order+1, W) for order 3
A per-order weight
ωbalances the wildly-different-magnitude orders – it weights the objective½‖ω⊙r‖²inside the kind; the gradient stays a gauged Riemannian tangent, and the Gauss-Newton quadratic formpᵀHp = ‖J p‖²agrees with the Hessian action:>>> model = fitting.apply_derivatives_model(t3m.MANIFOLD, x, ww, pp, 3, r, weight=[1.0, 0.5, 0.3, 0.2]) >>> print(model.gradient.is_gauged()) True >>> p = t3m.MANIFOLD.randn(model.frame) >>> bool(np.allclose(float(model.gn_quadratic(p)), float(p.corewise_inner(model.gn_hessian(p))))) True
- 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 (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: