TensorTT

# Import statement

from hottbox.core import TensorTT
class TensorTT(core_values, mode_names=None)[source]

Representation of a tensor in the Tensor Train form (TT).

Parameters
core_valueslist[np.ndarray]

List of cores for the Tensor Train representation of a tensor.

mode_nameslist[str]

List of names for the physical modes

Attributes

_core_values

(list[np.ndarray]) Placeholder for a list of cores for the Tensor Train representation of a tensor.

_modes

(list[Mode]) Description of the physical modes

Raises
TensorTopologyError

If there is inconsistency in shapes of core values

Examples

  1. Create tensor train representation of a tensor with default meta information

>>> import numpy as np
>>> from hottbox.core import TensorTT
>>> I, J, K = 5, 6, 7          # shape of the tensor in full form
>>> R_1, R_2 = 3, 4            # tt-rank
>>> core_0 = np.ones((I, R_1))
>>> core_1 = np.ones((R1, J, R2))
>>> core_2 = np.ones((R2, K))
>>> core_values = [core_0, core_1, core_2]
>>> tensor_tt = TensorTT(core_values)
>>> print(tensor_tt)
    Tensor train representation of a tensor with tt-rank=(3, 4).
    Shape of this representation in the full format is (5, 6, 7).
    Physical modes of its cores represent properties: ['mode-0', 'mode-1', 'mode-2']
  1. Create tensor train representation of a tensor with custom meta information

>>> import numpy as np
>>> from hottbox.core import TensorTT
>>> I, J, K = 5, 6, 7  # shape of the tensor in full form
>>> R_1, R_2 = 3, 4    # tt-rank
>>> core_0 = np.ones((I, R_1))
>>> core_1 = np.ones((R_1, J, R_2))
>>> core_2 = np.ones((R_2, K))
>>> core_values = [core_0, core_1, core_2]
>>> mode_names = ["Year", "Month", "Day"]
>>> tensor_tt = TensorTT(core_values, mode_names)
>>> print(tensor_tt)
    Tensor train representation of a tensor with tt-rank=(3, 4).
    Shape of this representation in the full format is (5, 6, 7).
    Physical modes of its cores represent properties: ['Year', 'Month', 'Day']

Methods

copy(self)

Produces a copy of itself as a new object

copy_modes(self, tensor)

Copy modes meta from tensor

core(self, i)

Specific core of the TensorTT representation

reconstruct(self[, keep_meta])

Converts the TT representation of a tensor into a full tensor

reset_mode_index(self[, mode])

Drop index for the specified mode number

reset_mode_name(self[, mode])

Set default name for the specified mode number

set_mode_index(self, mode_index)

Set index for specified mode

set_mode_names(self, mode_names)

Rename modes of a tensor representation

copy(self)[source]

Produces a copy of itself as a new object

Returns
new_objectTensorTT
copy_modes(self, tensor)[source]

Copy modes meta from tensor

Parameters
tensor{Tensor, TensorCPD, TensorTKD, TensorTT}
Returns
selfTensorTT

Notes

Most of the time this method should only be used by the decomposition algorithms

core(self, i)[source]

Specific core of the TensorTT representation

Parameters
iint

Should not exceed the order of TensorTT.order representation

Returns
core_tensorTensor
property cores

All cores of the TensorTT representation

Returns
core_listlist[Tensor]
property ft_shape

Shape of a TensorTT in the full format

Returns
full_shapetuple
property mode_names

Description of the physical modes for a TensorTT

Returns
list[str]
property modes

Meta data for the factor matrices

Returns
list[Mode]
property order

Order of a tensor represented through the TT

Returns
orderint
property rank

Rank of the TT representation of a tensor

Returns
ranktuple

Notes

Most often referred to as the TT rank

reconstruct(self, keep_meta=0)[source]

Converts the TT representation of a tensor into a full tensor

Parameters
keep_metaint

Keep meta information about modes of the given tensor. 0 - the output will have default values for the meta data 1 - keep only mode names 2 - keep mode names and indices

Returns
tensorTensor
reset_mode_index(self, mode=None)[source]

Drop index for the specified mode number

Parameters
modeint

Mode number which index to be dropped By default resets all indices

Returns
selfTensorTT
reset_mode_name(self, mode=None)[source]

Set default name for the specified mode number

Parameters
modeint

Mode number which name to be set to default value By default resets names of all modes

Returns
selfTensorTT
set_mode_index(self, mode_index)[source]

Set index for specified mode

Parameters
mode_indexdict

New indices for the factor matrices in form of a dictionary. Key defines the mode whose index to be changed. Value contains a list of new indices for this mode.

Returns
selfTensorTT
set_mode_names(self, mode_names)[source]

Rename modes of a tensor representation

Parameters
mode_namesdict

New names for the tensor modes in form of a dictionary The name of the mode defined by the Key of the dict will be renamed to the corresponding Value

Returns
selfTensorTT