# Import statement
from hottbox.core import TensorCPD
TensorCPD
(fmat, core_values, mode_names=None)[source]¶Representation of a tensor in the Kruskal form (CPD).
List of factor matrices for the CP representation of a tensor
Array of coefficients on the super-diagonal of a core for the CP representation of a tensor
List of names for the factor matrices
Attributes
_fmat |
(list[np.ndarray]) Placeholder for a list of factor matrices for the CP representation of a tensor |
_core_values |
(np.ndarray) Placeholder for an array of coefficients on the super-diagonal of a core for the CP representation of a tensor |
_modes |
(list[Mode]) Description of the factor matrix for the corresponding mode |
If there is inconsistency in shapes of factor matrices and core values
Examples
Create kruskal representation of a tensor with default meta information
>>> import numpy as np
>>> from hottbox.core import TensorCPD
>>> I, J, K = 5, 6, 7 # shape of the tensor in full form
>>> R = 4 # Kruskal rank
>>> A = np.ones((I, R))
>>> B = np.ones((J, R))
>>> C = np.ones((K, R))
>>> fmat = [A, B , C]
>>> core_values = np.arange(R)
>>> tensor_cpd = TensorCPD(fmat, core_values)
>>> print(tensor_cpd)
Kruskal representation of a tensor with rank=(4,).
Factor matrices represent properties: ['mode-0', 'mode-1', 'mode-2']
With corresponding latent components described by (5, 6, 7) features respectively.
Create kruskal representation of a tensor with custom meta information
>>> import numpy as np
>>> from hottbox.core import TensorCPD
>>> I, J, K = 5, 6, 7 # shape of the tensor in full form
>>> R = 4 # Kruskal rank
>>> A = np.ones((I, R))
>>> B = np.ones((J, R))
>>> C = np.ones((K, R))
>>> fmat = [A, B , C]
>>> core_values = np.arange(R)
>>> mode_names = ["Year", "Month", "Day"]
>>> tensor_cpd = TensorCPD(fmat, core_values, mode_names)
>>> print(tensor_cpd)
Kruskal representation of a tensor with rank=(4,).
Factor matrices represent properties: ['Year', 'Month', 'Day']
With corresponding latent components described by (5, 6, 7) features respectively.
Methods
|
Produces a copy of itself as a new object |
|
Copy modes meta from tensor |
|
Converts the CP representation of a tensor into a full tensor |
|
Drop index for the specified mode number |
|
Set default name for the specified mode number |
|
Set index for specified mode |
|
Rename modes of a tensor representation |
copy_modes
(self, tensor)[source]¶Copy modes meta from tensor
Notes
Most of the time this method should only be used by the decomposition algorithms
core
¶Core tensor of the CP representation of a tensor
fmat
¶List of factor matrices for the CP representation of a tensor
ft_shape
¶Shape of a TensorCPD
in the full format
mode_names
¶Description of the physical modes for a TensorCPD
modes
¶Meta data for the factor matrices
order
¶Order of a tensor represented through the CPD
rank
¶Rank of the CP representation of a tensor.
Notes
Most often referred to as the Kryskal rank
reconstruct
(self, keep_meta=0)[source]¶Converts the CP representation of a tensor into a full tensor
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
reset_mode_index
(self, mode=None)[source]¶Drop index for the specified mode number
Mode number which index to be dropped By default resets all indices
reset_mode_name
(self, mode=None)[source]¶Set default name for the specified mode number
Mode number which name to be set to default value By default resets names of all modes