TuckerTensorTrain.apply_derivatives#
- t3toolbox.tucker_tensor_train.TuckerTensorTrain.apply_derivatives(ww, pp, order)#
def apply_derivatives( self, ww: Sequence[NDArray], # apply vectors X, len=d, elm_shape=W+(Ni,) pp: Sequence[NDArray], # perturbation vectors P, len=d, elm_shape=W+(Ni,) order: int, # highest derivative order ) -> NDArray: # shape=(order+1,)+W+C
Symmetric directional derivatives of applying this T3 in all modes, in one repeated direction.
The all-modes analogue of
probe_derivatives()(derivative analogue ofapply()):y^(t) = d^t/ds^t apply(X + s P)|_0fort=0..order(a scalar per stack element). Stacksorder + W + C.XandPshare the sample stackW.Examples
>>> import numpy as np >>> import t3toolbox.tucker_tensor_train as t3 >>> np.random.seed(0) >>> x = t3.TuckerTensorTrain.randn((14, 15, 16), (4, 5, 6), (1, 3, 2, 1)) >>> ww = (np.random.randn(14), np.random.randn(15), np.random.randn(16)) >>> pp = (np.random.randn(14), np.random.randn(15), np.random.randn(16)) >>> yj = x.apply_derivatives(ww, pp, 3) >>> print(yj.shape) # (order+1,) (4,) >>> print(bool(np.allclose(yj[0], x.apply(ww)))) # order 0 == apply True