omicverse.micro.MMvec.fit#
- MMvec.fit(adata_microbe, adata_metabolite, verbose=False)[source]#
Fit MMvec on paired microbe / metabolite count tables and return
self.Trains a low-rank latent-space model
logits[i, j] = U[i] · V[j] + β[j], where rows ofUare microbe embeddings, rows ofVare metabolite embeddings, and the loss is per-microbe negative log-likelihood of the sample-weighted metabolite distribution. The cooccurrence weightsW[i, j] = Σ_s X_mb[s, i] · X_mt[s, j] / Σ_s X_mt[s, :]capture which microbes covary with which metabolites across samples.Both AnnDatas must share
obs_namesin the same order (_check_paired enforces this). Training reports an early-stop validation loss every epoch whenval_frac > 0;patienceepochs without validation improvement stops training and restores the best checkpoint.- Parameters:
adata_microbe (AnnData) – Sample-aligned count tables.
adata_metabolite (AnnData) – Sample-aligned count tables.
verbose (bool, default False) – Print loss every
epochs // 10epochs.
- Returns:
self — fitted; access
microbe_embeddings_,metabolite_embeddings_,cooccurrence(),conditional_probabilities(),top_pairs(n).