schist.inference._nested_model
Module Contents
Functions
|
Cluster cells into subgroups [Peixoto14]. |
- schist.inference._nested_model.nested_model(adata: anndata.AnnData, deg_corr: bool = True, tolerance: float = 1e-06, n_sweep: int = 10, beta: float = np.inf, n_init: int = 100, collect_marginals: bool = True, n_jobs: int = - 1, refine_model: bool = False, refine_iter: int = 100, max_iter: int = 100000, *, restrict_to: Optional[Tuple[str, Sequence[str]]] = None, random_seed: Optional[int] = None, key_added: str = 'nsbm', adjacency: Optional[scipy.sparse.spmatrix] = None, neighbors_key: Optional[str] = 'neighbors', directed: bool = False, use_weights: bool = False, save_model: Union[str, None] = None, copy: bool = False, dispatch_backend: Optional[str] = 'threads') Optional[anndata.AnnData]
Cluster cells into subgroups [Peixoto14].
Cluster cells using the nested Stochastic Block Model [Peixoto14], a hierarchical version of Stochastic Block Model [Holland83], performing Bayesian inference on node groups. NSBM should circumvent classical limitations of SBM in detecting small groups in large graphs replacing the noninformative priors used by a hierarchy of priors and hyperpriors.
This requires having ran
neighbors()
orbbknn()
first.- adata
The annotated data matrix.
- deg_corr
Whether to use degree correction in the minimization step. In many real world networks this is the case, although this doesn’t seem the case for KNN graphs used in scanpy.
- tolerance
Tolerance for fast model convergence.
- n_sweep
Number of iterations to be performed in the fast model MCMC greedy approach
- beta
Inverse temperature for MCMC greedy approach
- n_init
Number of initial minimizations to be performed. The one with smaller entropy is chosen
- refine_model
Wether to perform a further mcmc step to refine the model
- refine_iter
Number of refinement iterations.
- max_iter
Maximum number of iterations during minimization, set to infinite to stop minimization only on tolerance
- n_jobs
Number of parallel computations used during model initialization
- key_added
adata.obs key under which to add the cluster labels.
- adjacency
Sparse adjacency matrix of the graph, defaults to adata.uns[‘neighbors’][‘connectivities’] in case of scanpy<=1.4.6 or adata.obsp[neighbors_key][connectivity_key] for scanpy>1.4.6
- neighbors_key
The key passed to sc.pp.neighbors
- directed
Whether to treat the graph as directed or undirected.
- use_weights
If True, edge weights from the graph are used in the computation (placing more emphasis on stronger edges). Note that this increases computation times
- save_model
If provided, this will be the filename for the PartitionModeState to be saved
- copy
Whether to copy adata or modify it inplace.
- random_seed
Random number to be used as seed for graph-tool
- adata.obs[key_added]
Array of dim (number of cells) that stores the subgroup id (‘0’, ‘1’, …) for each cell.
- adata.uns[‘schist’][‘params’]
A dict with the values for the parameters resolution, random_state, and n_iterations.
- adata.uns[‘schist’][‘stats’]
A dict with the values returned by mcmc_sweep
- adata.obsm[‘CA_nsbm_level_{n}’]
A np.ndarray with cell probability of belonging to a specific group
- adata.uns[‘schist’][‘state’]
The NestedBlockModel state object