TuckerTensorTrain.norm ====================== .. py:method:: t3toolbox.tucker_tensor_train.TuckerTensorTrain.norm(use_orthogonalization = True) .. code-block:: python 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 :func:`t3toolbox.corewise.corewise_norm` :param use_orthogonalization: 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``. :type use_orthogonalization: bool, optional :returns: **result** -- Hilbert-Schmidt (Frobenius) norm of Tucker tensor train, ||x||_HS. If stacked, ``result.shape=self.stack_shape``. Otherwise, result is scalar. :rtype: scalar or NDArray .. seealso:: :py:meth:`.TuckerTensorTrain.__add__`, :py:meth:`.TuckerTensorTrain.__sub__`, :py:meth:`.TuckerTensorTrain.__neg__`, :py:meth:`.TuckerTensorTrain.__mul__`, :py:meth:`.TuckerTensorTrain.inner`, :py:meth:`.TuckerTensorTrain.sum` .. rubric:: 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 shape ``stack_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