TuckerTensorTrain.norm#
- t3toolbox.tucker_tensor_train.TuckerTensorTrain.norm(use_orthogonalization=True)#
def norm( self, use_orthogonalization: bool = True, # for numerical stability ):
Compute Hilbert-Schmidt (Frobenius) norm of this TuckerTensorTrain.
The Hilbert-Schmidt norm is defined with respect to the dense
N0 x ... x N(d-1)tensor that is represented by the TuckerTensorTrain.x.norm() = np.linalg.norm(x.to_dense())For corewise norm, see
t3toolbox.corewise.corewise_norm()- Parameters:
use_orthogonalization (bool, optional) – If True, compute norm by orthogonalizing (more stable). If False, compute norm with conventional zippering (faster, more suited for automatic differentiation). Default:
use_orthogonalization=True.- Returns:
result – Hilbert-Schmidt (Frobenius) norm of Tucker tensor train, ||x||_HS. If stacked,
result.shape=self.stack_shape. Otherwise, result is scalar.- Return type:
scalar or NDArray
See also
TuckerTensorTrain.__add__(),TuckerTensorTrain.__sub__(),TuckerTensorTrain.__neg__(),TuckerTensorTrain.__mul__(),TuckerTensorTrain.inner(),TuckerTensorTrain.sum()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), (2,3,2,2)) >>> print(np.allclose(x.norm(), np.linalg.norm(x.to_dense()))) True
Stacked –
norm()returns an array of shapestack_shape, one norm per slice:>>> 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), (2,3,2,2), stack_shape=(2,3)) >>> norms_x = x.norm(use_orthogonalization=True) >>> print(norms_x.shape) (2, 3) >>> x_dense = x.to_dense() >>> norms_x_dense = np.sqrt(np.sum(x_dense**2, axis=(-3,-2,-1))) >>> print(np.allclose(norms_x, norms_x_dense)) True