pyALRA.core module

core.alra(A_norm, k=0, q=12, quantile_prob=0.001, random_state=1, svd_type=None)

Adaptive thresholded low-rank approximation (ALRA) for imputation of sparse data.

Parameters

A_normndarray or sparse matrix

Normalized input matrix.

kint, optional

Rank for approximation; if 0, automatically chosen (default 0).

qint, optional

Number of power iterations for randomized SVD (default 12).

quantile_probfloat, optional

Quantile threshold for adaptive thresholding (default 0.001).

random_stateint, optional

Random seed for reproducibility (default 1).

svd_typestr or None, optional

SVD method: ‘truncated’ or None for randomized SVD.

Returns

dict

Dictionary containing: - ‘A_norm_rank_k’: low-rank approximation matrix (rank k) - ‘A_norm_rank_k_cor’: thresholded low-rank matrix - ‘A_norm_rank_k_cor_sc’: scaled and thresholded matrix (final imputed matrix)

core.choose_k(A_norm, K=100, thresh=6, noise_start=80, q=12, random_state=1, svd_type=None)

Select the rank k for low-rank approximation based on singular value gap statistics.

Parameters

A_normndarray or sparse matrix

Normalized input matrix.

Kint, optional

Maximum number of singular values to consider (default 100).

threshfloat, optional

Threshold on number of standard deviations to detect significant singular value gap (default 6).

noise_startint, optional

Index to start noise singular values (default 80).

qint, optional

Number of power iterations for randomized SVD (default 12).

random_stateint, optional

Random seed for reproducibility (default 1).

svd_typestr or None, optional

SVD method: ‘truncated’ or None for randomized SVD.

Returns

dict

Dictionary with keys: - ‘k’: selected rank - ‘num_of_sds’: array of standardized singular value differences - ‘d’: singular values array

core.normalize_data(A)

Normalize data by library size and log-transform.

Parameters

Andarray or sparse matrix

Input matrix with cells as rows and genes as columns.

Returns

ndarray

Normalized and log-transformed matrix.

core.randomized_svd_py(A, K, q, random_state, svd_type=None)

Perform SVD with an option for randomized or truncated SVD.

Parameters

Andarray or sparse matrix

Input data matrix to decompose.

Kint

Number of singular values and vectors to compute.

qint

Number of power iterations (only applicable for randomized SVD).

random_stateint

Random seed for reproducibility.

svd_typestr or None, optional

If ‘truncated’, use TruncatedSVD; otherwise, use randomized SVD.

Returns

Undarray

Left singular vectors.

Sigmandarray

Singular values.

VTndarray

Right singular vectors transposed.