tt_sketch.drm
- class tt_sketch.drm.dense_gaussian_drm.DenseGaussianDRM(rank: Union[Tuple[int, ...], int], shape: Tuple[int, ...], transpose: bool, seed: Optional[int] = None, **kwargs)[source]
Dense Gaussian DRM.
The DRM is stored as a list of matrices, one for each mode.
- sketch_dense(tensor)
Return list of dense DRMs. Of shape
(np.prod(tensor.shape[ :mu+1]), rank[mu])
- sketch_sparse(tensor)
Computes list of sketching matrices sampled into a vector using the indices of
tensorfor each unfolding. Shape of each vector isv[mu] = (rank[mu], tensor.nnz). This way the contraction betweentensorand the sketching matrix is of formnp.dot(tensor.entries, v[mu])
- sketch_tt(tensor)
List of contractions of form \(Y_\mu^\top\mathcal{T}^{\leq\mu}\) where \(Y_\mu\) is the DRM, and \(\mathcal T^{\leq\mu}\) the contraction of the first \(\mu\) cores of
tensor.Returns array of shape
(tensor.rank[mu], drm.rank[mu])
- sketching_mats: List[ndarray[Any, dtype[float64]]]
- class tt_sketch.drm.sparse_gaussian_drm.SparseGaussianDRM(rank: Union[Tuple[int, ...], int], shape: Tuple[int, ...], transpose: bool, seed: Optional[int] = None, **kwargs)[source]
‘Sparse’ Gaussian DRM
Mathematically equivalent
DenseGaussianDRM, but entries of the DRM are computed lazily/on-demand using a hashing algorithm. This makes it computationally feasible for very sparse tensors.- rank: Tuple[int, ...]
- sketch_sparse(tensor)
Computes list of sketching matrices sampled into a vector using the indices of
tensorfor each unfolding. Shape of each vector isv[mu] = (rank[mu], tensor.nnz). This way the contraction betweentensorand the sketching matrix is of formnp.dot(tensor.entries, v[mu])
- class tt_sketch.drm.sparse_sign_drm.SparseSignDRM(rank: Union[Tuple[int, ...], int], shape: Tuple[int, ...], transpose: bool, seed: Optional[int] = None, num_non_zero_per_row: Optional[Tuple[int, ...]] = None, **kwargs)[source]
Sparse DRM where each row is a vector with fixed number of +/-1 entries.
The number of nonzero entries are determined by
num_non_zero_per_row. LikeSparseGaussianDRM, entries are computed lazily/on-demand using a hashing algorithm.- rank: Tuple[int, ...]
- sketch_sparse(tensor)
Computes list of sketching matrices sampled into a vector using the indices of
tensorfor each unfolding. Shape of each vector isv[mu] = (rank[mu], tensor.nnz). This way the contraction betweentensorand the sketching matrix is of formnp.dot(tensor.entries, v[mu])
- class tt_sketch.drm.tensor_train_drm.TensorTrainDRM(rank: Union[Tuple[int, ...], int], shape: Tuple[int, ...], transpose: bool, seed: Optional[int] = None, **kwargs)[source]
Tensor train DRM. Sketches with partial contractions of a fixed TT.
- cores: List[ndarray[Any, dtype[float64]]]
- sketch_cp(tensor)
List of contractions of form \(Y_\mu^\top\mathcal{T}^{\leq\mu}\) where \(Y_\mu\) is the DRM, and \(\mathcal T^{\leq\mu}\) the contraction of the first \(\mu\) cores of
tensor.Returns array of shape
(tensor.rank[mu], drm.rank[mu])
- sketch_dense(tensor)
Return list of dense DRMs. Of shape
(np.prod(tensor.shape[ :mu+1]), rank[mu])
- sketch_sparse(tensor)
Computes list of sketching matrices sampled into a vector using the indices of
tensorfor each unfolding. Shape of each vector isv[mu] = (rank[mu], tensor.nnz). This way the contraction betweentensorand the sketching matrix is of formnp.dot(tensor.entries, v[mu])
- sketch_tt(tensor)
List of contractions of form \(Y_\mu^\top\mathcal{T}^{\leq\mu}\) where \(Y_\mu\) is the DRM, and \(\mathcal T^{\leq\mu}\) the contraction of the first \(\mu\) cores of
tensor.Returns array of shape
(tensor.rank[mu], drm.rank[mu])
- sketch_tucker(tensor)
List of contractions of form \(Y_\mu^\top(U_1\otimes\cdots\otimes U_\mu)\) where
Y_\muis the DRM, and \(U_\mu\) denotes the factors of the Tucker decomposition.Returns array of shape
(np.prod(tensor.rank[:mu]), drm.rank[mu])
- tt_sketch.drm.fast_lazy_gaussian.hash_int_c()
Use simple hashing for generating random numbers from indices deterministically. See https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key
- tt_sketch.drm.fast_lazy_gaussian.inds_to_normal()
Converts a list of indices into the associated entries of gaussian matrix
- tt_sketch.drm.fast_lazy_gaussian.inds_to_sparse_sign()
Converts a list of indices into the non-zero entries of a sparse sign matrix