lenskit.data.matrix#

Classes for working with matrix data.

Attributes#

Classes#

CSRStructure

Representation of the compressed sparse row structure of a sparse matrix,

COOStructure

Representation of the coordinate structure of a sparse matrix, without any

SparseIndexType

Data type for the index field of a sparse row. Indexes are just stored as

SparseIndexListType

Sparse index lists. These are the row type for structure-only sparse

SparseRowType

Data type for sparse rows stored in Arrow. Sparse rows are stored as lists

SparseRowArray

An array of sparse rows (a compressed sparse row matrix).

Functions#

fast_col_cooc(...)

Compute column co-occurrances (\(M^{\mathrm{T}}M\)) efficiently.

normalize_matrix(matrix, normalize)

Normalize rows of a matrix.

Module Contents#

lenskit.data.matrix.t#
lenskit.data.matrix.M#
lenskit.data.matrix.SPARSE_IDX_EXT_NAME='lenskit.sparse_index'#
lenskit.data.matrix.SPARSE_IDX_LIST_EXT_NAME='lenskit.sparse_index_list'#
lenskit.data.matrix.SPARSE_ROW_EXT_NAME='lenskit.sparse_row'#
lenskit.data.matrix.fast_col_cooc(rows:lenskit.data.types.NPVector [numpy.int32]|pyarrow.Int32Array , cols:lenskit.data.types.NPVector [numpy.int32]|pyarrow.Int32Array , shape:tuple [int ,int ], *, progress:lenskit.logging.Progress |None =None, include_diagonal:bool =True, ordered:bool =False, dense:Literal[True]) numpy.ndarray [tuple [int ,int ],numpy.dtype [numpy.float32]]#
lenskit.data.matrix.fast_col_cooc(rows:lenskit.data.types.NPVector [numpy.int32]|pyarrow.Int32Array , cols:lenskit.data.types.NPVector [numpy.int32]|pyarrow.Int32Array , shape:tuple [int ,int ], *, progress:lenskit.logging.Progress |None =None, include_diagonal:bool =True, ordered:bool =False, dense:Literal[False]=False) scipy.sparse.coo_array
lenskit.data.matrix.fast_col_cooc(rows:lenskit.data.types.NPVector [numpy.int32]|pyarrow.Int32Array , cols:lenskit.data.types.NPVector [numpy.int32]|pyarrow.Int32Array , shape:tuple [int ,int ], *, progress:lenskit.logging.Progress |None =None, include_diagonal:bool =True, ordered:bool =False, dense:bool =False) Any

Compute column co-occurrances (\(M^{\mathrm{T}}M\)) efficiently.

lenskit.data.matrix.normalize_matrix(matrix, normalize)#

Normalize rows of a matrix.

Parameters:
  • matrix (scipy.sparse.csr_array | numpy.typing.NDArray[numpy.floating [Any]]) – Sparse or dense matrix to normalize

  • normalize (Literal['unit', 'distribution'] | None) – Normalization mode ("unit" for L2, "distribution" for L1)

Returns:

Normalized matrix

Return type:

scipy.sparse.csr_array | numpy.typing.NDArray[numpy.floating[Any]]

Exported Aliases#

lenskit.data.matrix.run_accel_task()#

Re-exported alias for lenskit.parallel.run_accel_task().

lenskit.data.matrix.NPVector#

Re-exported alias for lenskit.data.types.NPVector.