pegasus.nmf¶
- pegasus.nmf(data, n_components=20, features='highly_variable_features', space='log', init='nndsvdar', algo='halsvar', mode='batch', tol=0.0001, use_gpu=False, alpha_W=0.0, l1_ratio_W=0.0, alpha_H=0.0, l1_ratio_H=0.0, fp_precision='float', n_jobs=- 1, random_state=0)[source]¶
Perform Nonnegative Matrix Factorization (NMF) to the data using Frobenius norm. Steps include select features and L2 normalization and NMF and L2 normalization of resulting coordinates.
The calculation uses nmf-torch package.
- Parameters
data (
pegasusio.MultimodalData
) – Annotated data matrix with rows for cells and columns for genes.n_components (
int
, optional, default:50
.) – Number of Principal Components to get.features (
str
, optional, default:"highly_variable_features"
.) – Keyword indata.var
to specify features used for nmf.max_value (
float
, optional, default:None
.) – The threshold to truncate data symmetrically after scaling. IfNone
, do not truncate.space (
str
, optional, default:log
.) – Choose fromlog
andexpression
.log
works on log-transformed expression space;expression
works on the original expression space (normalized by total UMIs).init (
str
, optional, default:nndsvdar
.) – Method to initialize NMF. Options are ‘random’, ‘nndsvd’, ‘nndsvda’ and ‘nndsvdar’.algo (
str
, optional, default:halsvar
) – Choose frommu
(Multiplicative Update),hals
(Hierarchical Alternative Least Square),halsvar
(HALS variant, use HALS to mimicbpp
and can get better convergence for sometimes) andbpp
(alternative non-negative least squares with Block Principal Pivoting method).mode (
str
, optional, default:batch
) – Learning mode. Choose frombatch
andonline
. Notice thatonline
only works whenbeta=2.0
. For other beta loss, it switches back tobatch
method.tol (
float
, optional, default:1e-4
) – The toleration used for convergence check.use_gpu (
bool
, optional, default:False
) – IfTrue
, use GPU if available. Otherwise, use CPU only.alpha_W (
float
, optional, default:0.0
) – A numeric scale factor which multiplies the regularization terms related to W. If zero or negative, no regularization regarding W is considered.l1_ratio_W (
float
, optional, default:0.0
) – The ratio of L1 penalty on W, must be between 0 and 1. And thus the ratio of L2 penalty on W is (1 - l1_ratio_W).alpha_H (
float
, optional, default:0.0
) – A numeric scale factor which multiplies the regularization terms related to H. If zero or negative, no regularization regarding H is considered.l1_ratio_H (
float
, optional, default:0.0
) – The ratio of L1 penalty on W, must be between 0 and 1. And thus the ratio of L2 penalty on H is (1 - l1_ratio_H).fp_precision (
str
, optional, default:float
) – The numeric precision on the results. Choose fromfloat
anddouble
.n_jobs (int, optional (default: -1)) – Number of threads to use. -1 refers to using all physical CPU cores.
random_state (
int
, optional, default:0
.) – Random seed to be set for reproducing result.
- Return type
None
- Returns
None
.Update
data.obsm
–data.obsm["X_nmf"]
: Scaled NMF coordinates of shape(n_cells, n_components)
. Each column has a unit variance.data.obsm["H"]
: The coordinate factor matrix of shape(n_cells, n_components)
.
Update
data.uns
–data.uns["W"]
: The feature factor matrix of shape(n_HVFs, n_components)
.data.uns["nmf_err"]
: The NMF loss.data.uns["nmf_features"]
: Record the features used to perform NMF analysis.
Examples
>>> pg.nmf(data)