tensap.tensor_algebra.tools package

Submodules

tensap.tensor_algebra.tools.truncator module

Module truncator.

class tensap.tensor_algebra.tools.truncator.Truncator(tolerance=1e-08, max_rank=inf, thresholding_type='hard', thresholding_parameter=None)

Bases: object

Class Truncator.

Attributes
tolerancefloat

The relative tolerance for the truncation.

max_rankint

The maximum rank for the truncation.

thresholding_typestr

The thresholding type (‘hard’ or ‘soft’).

thresholding_parameterfloat

The thresholding parameter.

Methods

hosvd(tensor)

Compute the truncated hosvd of tensor.

hsvd(tensor[, tree, is_active_node])

Compute the truncated svd in tree-based tensor format of tensor.

svd(tensor)

Compute the truncated svd of an order-2 tensor.

trunc_svd(matrix[, tolerance, power])

Compute the truncated svd of the matrix x with relative precision self.tolerance (or tolerance if provided) in Schatten p-norm (with p given by the input power) and maximal rank self.max_rank.

truncate(tensor)

Compute the truncation of the tensor with relative precision self.tolerance and maximal rank self.max_rank.

ttsvd(tensor)

Compute the truncated svd in tensor-train format of tensor.

hosvd(tensor)

Compute the truncated hosvd of tensor.

Parameters
tensornp.ndarray or tensap.FullTensor or tensap.TreeBasedTensor

The tensor to truncate.

Returns
outtensap.CanonicalTensor or tensap.TreeBasedTensor

The truncated tensor.

Raises
ValueError

If the input tensor is of the wrong type.

hsvd(tensor, tree=None, is_active_node=None)

Compute the truncated svd in tree-based tensor format of tensor.

Parameters
tensortensap.FullTensor or tensap.TreeBasedTensor

The tensor to truncate.

treetensap.DimensionTree, optional

The tree of the output tree-based tensor. The default is None, indicating if tensor is a tensap.TreeBasedTensor to take tensor.tree.

is_active_nodenumpy.ndarray, optional

Logical array indicating if the nodes are active.. The default is None, indicating if tensor is a tensap.TreeBasedTensor to take tensor.is_active_node.

Returns
outtensap.TreeBasedTensor

The truncated tensor in tree-based tensor format.

Raises
ValueError

If the wrong value of the atttribude _hsvd_type is provided.

NotImplementedError

If the method is not implemented for the format.

svd(tensor)

Compute the truncated svd of an order-2 tensor.

Parameters
tensornumpy.ndarray or tensap.FullTensor or tensorflow.Tensor or
tensap.TreeBasedTensor

The tensor to truncate.

Returns
outtensap.CanonicalTensor or tensap.TreeBasedTensor

The truncated tensor.

Raises
NotImplementedError

If the method is not implemented.

trunc_svd(matrix, tolerance=None, power=2)

Compute the truncated svd of the matrix x with relative precision self.tolerance (or tolerance if provided) in Schatten p-norm (with p given by the input power) and maximal rank self.max_rank.

Parameters
matrixnumpy.ndarray

The matrix to truncate.

tolerancefloat, optional

The relative tolerance for the truncation. The default is self.tolerance.

powerint or ‘inf’ or float(‘inf’) or numpy.inf, optional

The integer p of the Schatten-p norm (1 <= p <= inf, p = 2 for Frobenius). The default is 2.

Returns
tensap.CanonicalTensor

The truncated matrix.

truncate(tensor)

Compute the truncation of the tensor with relative precision self.tolerance and maximal rank self.max_rank.

Parameters
tensornumpy.ndarray or tensap.FullTensor or tensorflow.Tensor or
tensap.TreeBasedTensor

The tensor to truncate.

Returns
outtensap.CanonicalTensor or tensap.TreeBasedTensor

The truncated tensor.

Raises
NotImplementedError

If the decomposition is not implemented for the tensor format.

ValueError

If the tensor is of order 1.

ttsvd(tensor)

Compute the truncated svd in tensor-train format of tensor.

Parameters
tensortensap.FullTensor or tensap.TreeBasedTensor

The tensor to truncate.

Returns
tensap.TreeBasedTensor

The truncated tensor in tree-based tensor format with a linear tree.

Module contents