TensorTKD

# Import statement

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

Representation of a tensor in the Tucker form (TKD).

Parameters
fmatlist[np.ndarray]

List of factor matrices for the Tucker representation of a tensor

core_valuesnp.ndarray

Core of the Tucker representation of a tensor

mode_nameslist[str]

List of names for the factor matrices

Attributes

_fmat

(list[np.ndarray]) Placeholder for a list of factor matrices for the Tucker representation of a tensor

_core_values

(np.ndarray) Placeholder for a core of the Tucker representation of a tensor

_modes

(list[Mode]) Description of the factor matrix for the corresponding mode

Raises
TensorTopologyError

If there is inconsistency in shapes of factor matrices and core values

Examples

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

>>> import numpy as np
>>> from hottbox.core import TensorTKD
>>> I, J, K = 5, 6, 7        # shape of the tensor in full form
>>> R_1, R_2, R_3 = 2, 3, 4  # multi-linear rank
>>> A = np.ones((I, R_1))
>>> B = np.ones((J, R_2))
>>> C = np.ones((K, R_3))
>>> fmat = [A, B , C]
>>> core_values = np.ones((R_1, R_2, R_3))
>>> tensor_tkd = TensorTKD(fmat, core_values)
>>> print(tensor_tkd)
    Tucker representation of a tensor with multi-linear rank=(2, 3, 4).
    Factor matrices represent properties: ['mode-0', 'mode-1', 'mode-2']
    With corresponding latent components described by (5, 6, 7) features respectively.
  1. Create tucker representation of a tensor with custom meta information

>>> import numpy as np
>>> from hottbox.core import TensorTKD
>>> I, J, K = 5, 6, 7        # shape of the tensor in full form
>>> R_1, R_2, R_3 = 2, 3, 4  # multi-linear rank
>>> A = np.ones((I, R_1))
>>> B = np.ones((J, R_2))
>>> C = np.ones((K, R_3))
>>> fmat = [A, B , C]
>>> core_values=np.ones((R_1, R_2, R_3))
>>> mode_names=["Year", "Month", "Day"]
>>> tensor_tkd = TensorTKD(fmat, core_values, mode_names)
>>> print(tensor_tkd)
    Tucker representation of a tensor with multi-linear rank=(2, 3, 4).
    Factor matrices represent properties: ['Year', 'Month', 'Day']
    With corresponding latent components described by (5, 6, 7) features respectively.

Methods

copy(self)

Produces a copy of itself as a new object

copy_modes(self, tensor)

Copy modes meta from tensor

reconstruct(self[, keep_meta])

Converts the Tucker 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_objectTensorTKD
copy_modes(self, tensor)[source]

Copy modes meta from tensor

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

Notes

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

property core

Core tensor of the Tucker representation of a tensor

Returns
core_tensorTensor
property fmat

List of factor matrices for the Tucker representation of a tensor

Returns
factor_matriceslist[np.ndarray]
property ft_shape

Shape of a TensorTKD in the full format

Returns
full_shapetuple
property mode_names

Description of the physical modes for a TensorTKD

Returns
list[str]
property modes

Meta data for the factor matrices

Returns
list[Mode]
property order

Order of a tensor represented through the TKD

Returns
orderint
property rank

Multi-linear rank of the Tucker representation of a tensor

Returns
ranktuple

Notes

Most often referred to as the Tucker rank

reconstruct(self, keep_meta=0)[source]

Converts the Tucker 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
selfTensorTKD
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
selfTensorTKD
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
selfTensorTKD
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
selfTensorTKD