ensign.cp_decomp.CPDecomp

class CPDecomp[source]

Represents the results of a CP decomposition.

See also

ensign.sptensor.SPTensor

Sparse tensor class

Attributes
rankint

Rank of decomposition.

orderint

Order of decomposed tensor.

sptensorSPTensor

SPTensor that was decomposed.

weightsnumpy.ndarray

1D array of length rank containing weights for each component of the decomposition.

factorslist of numpy.ndarray

List of 2D factor matrices accessed by mode_id. Each factor matrix has shape = (mode_size, rank) and dtype = "float64". All values in a factor matrix lie inside the closed interval [-1, 1]. Each column of a factor matrix represents a single component.

factors_initlist of numpy.ndarray

List of 2D factor matrices as initialized for the decomposition. Only saved if requested by the decomposition call.

labelslist of list of str, optional

An optional list of per-mode index labels accessed by mode_id. Each list of labels corresponds to the labels for each index of the mode. Suppose we have a mode with mode_id = 3 and "Yes", "No", "Maybe" mapped to indices 0-2. For this mode, labels[3] is equal to ["Yes", "No", "Maybe"]. Decompositions are not required to have labels.

mode_nameslist of str, optional

Each mode’s name accessed by mode_id. Decompositions are not required to have mode names.

mode_sizeslist of int

The number of indices in each mode accessed by mode_id.

streaming_dataless_fitndarray

Used by decomposition algorithms in a streaming setting to determine final fit.

metricsdict

Dictionary with keys: [time, fit, cosine_sim, norm_scaling, cp_total_iter] representing the time taken to run the decomposition, the final fit of the decomposition, the cosine similarity of the decomposition to the original tensor, the scale factor used to normalize the decompositions, and the number of optimization steps used to reach the final decomposition values, respectively.

cpd_backtracklist of lists of int

One entry per component. Each list contains tensor entries that contributed to the corresponding component. If CPDecomp object has two components, and the first one tracks to tensor entries 0 and 2 and the second tracks to tensor entries 1 and 3, then the backtrack will be [[0,2], [1,3]]. Only exists if requested in the decomposition call.

Methods

compute_cpd_backtrack(self[, out_dir])

Computes CP Decomposition backtracking information.

__init__(self)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self)

Initialize self.

compute_cpd_backtrack(self[, out_dir])

Computes CP Decomposition backtracking information.