ensign.sptensor.SPTensor

class SPTensor(order=0, nnz=0, mode_sizes=None, entries=None, mode_names=None, labels=None, spt_backtrack=None, queries=None, directory=None)[source]

Represents a sparse tensor.

Attributes
orderint

Order of sparse tensor.

nnzint

Number of nonzero tensor entries.

mode_sizeslist of int

The number of indices in each mode accessed by mode_id.

mode_nameslist of str

The name of each mode indexed by mode_id.

entriesPandas dataframe

2D dataframe of tensor entries. This dataframe has order + 1 columns and nnz rows. The first order columns represent 64-bit int tensor indices. The final column represents a float64 nonzero tensor entry corresponding to the tensor indices in its row.

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"]. SPTensors are not required to have labels.

spt_backtracklist of lists of tuples

An optional list with as many elements as non-zero tensor entries. Each element is a list containing tuples that indicate all file-line pairs in the CSV file that contributed to that entry. For example, given a tensor with three entries such that the first tracks to CSV 0, line 15 and CSV 1, line 7, the second tracks to CSV 0, line 45, and the third tracks to CSV 1, line 23, the list would be: [[(0,15), (1,7)], [(0,45)], [(1,23)]]

querieslist of list of strings

An optional list with as many elements as number of modes. Each of these lists has as many entries as non-zero tensor entries. Each entry is a string describing selection criteria for the bin corresponding to the given entry and mode. For example, in a tensor with float64, int64, and ip modes binned by round=1, log10, and ipsubnet=255.0.0.0, respectively, the list could be: [[“c1 >= 0.1 AND c1 < 0.2”, …], [“c2 >=10 AND c2 < 100”, …], [“c3 & 255.0.0.0 == 10.0.0.0”, …]]

Methods

write(self, outdir)

Writes a text representation of the sparse tensor to the given directory.

__init__(self, order=0, nnz=0, mode_sizes=None, entries=None, mode_names=None, labels=None, spt_backtrack=None, queries=None, directory=None)[source]

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

Methods

__init__(self[, order, nnz, mode_sizes, …])

Initialize self.

write(self, outdir)

Writes a text representation of the sparse tensor to the given directory.