moscot.backends.ott.output.OTTNeuralOutput.sparsify¶
- OTTNeuralOutput.sparsify(mode, value=None, batch_size=1024, n_samples=None, seed=None)¶
Sparsify the
transport_matrix
.This function sets all entries of the transport matrix below a certain threshold to \(0\) and returns a
MatrixSolverOutput
with sparsified transport matrix stored as acsr_matrix
.Warning
This function only serves for interfacing software which has to instantiate the transport matrix,
moscot
never uses the sparsified transport matrix.- Parameters:
mode (
Literal
['threshold'
,'percentile'
,'min_row'
]) –How to determine the value below which entries are set to \(0\). Valid options are:
’threshold’ -
value
is the threshold below which entries are set to \(0\).’percentile’ -
value
is the percentile in \([0, 100]\) of thetransport_matrix
. below which entries are set to \(0\).’min_row’ -
value
is not used, it is chosen such that each row has at least 1 non-zero entry.
batch_size (
int
) – How many rows to materialize when sparsifying thetransport_matrix
.n_samples (
Optional
[int
]) – Ifmode = 'percentile'
, determine the number of samples based on which the percentile is computed stochastically. Note this means that a matrix of shape [n_samples, min(transport_matrix.shape)] has to be instantiated. If None,n_samples
is set tobatch_size
.seed (
Optional
[int
]) – Random seed needed for sampling ifmode = 'percentile'
.
- Return type:
- Returns:
: Output with sparsified transport matrix.