# cellrank.tl.transition_matrix¶

cellrank.tl.transition_matrix(adata, backward=False, vkey='velocity', xkey='Ms', gene_subset=None, mode='deterministic', backward_mode='transpose', softmax_scale=None, weight_connectivities=0.2, density_normalize=True, key=None, **kwargs)[source]

Compute a transition matrix based on a combination of RNA Velocity and transcriptomic similarity.

To learn more about the way in which the transition matrices are computed, see cellrank.tl.kernels.VelocityKernel for the velocity-based transition matrix and cellrank.tl.kernels.ConnectivityKernel for the transcriptomic-similarity-based transition matrix.

Parameters
• adata (anndata.AnnData) – Annotated data object.

• backward (bool) – Direction of the process.

• vkey (str) – Key from adata.layers to access the velocities.

• xkey (str) – Key in adata.layers where expected gene expression counts are stored.

• gene_subset (Optional[Iterable]) – List of genes to be used to compute transition probabilities. By default, genes from adata.var['velocity_genes'] are used.

• mode (str) –

How to compute transition probabilities. Valid options are:

• ’deterministic’ - deterministic computation that doesn’t propagate uncertainty.

• ’monte_carlo’ - Monte Carlo average of randomly sampled velocity vectors.

• ’stochastic’ - second order approximation, only available when jax is installed.

• ’sampling’ - sample 1 transition matrix from the velocity distribution.

• backward_mode (str) –

How to compute the backward transitions. Valid options are:

• ’transpose’ - compute transitions from neighboring cells j to cell i.

• ’negate’ - negate the velocity vector.

• softmax_scale (Optional[float]) – Scaling parameter for the softmax. If None, it will be estimated using 1 / median(correlations). The idea behind this is to scale the softmax to counteract everything tending to orthogonality in high dimensions.

• weight_connectivities (Optional[float]) – Weight given to transcriptomic similarities as opposed to velocities. Must be in [0, 1].

• density_normalize (bool) – Whether to use density correction when computing the transition probabilities based on connectivities. Density correction is done as by [Haghverdi16].

• key (Optional[str]) – Key used when writing transition matrix to adata. If None, the key is set to ‘T_bwd’ if backward is True, else ‘T_fwd’.

• **kwargs – Keyword arguments for cellrank.tl.kernels.VelocityKernel.compute_transition_matrix().

Returns

A kernel expression object containing the computed transition matrix.

Updates the adata with the following fields:

• .obsp['{key}'] - the transition matrix.

• .uns['{key}_params'] - parameters used for calculation.

Return type

cellrank.tl.KernelExpression