Compute Schur vectors

This example shows how to compute and plot the Schur vectors.

In CellRank, we work with the real Schur decomposition because the transition matrices we are concerned with are non symmetrical (think of the velocity flow). In general, for these matrices the eigendecomposition does not exist. You may still compute the top eigenvectors, however, these will in general be complex valued and hard to interpret. The Schur decomposition is the natural generalization of the eigendecomposition for non-symmetric matrices and it’s real variant ensures that the top Schur vectors are only real and may be interpreted in the context of metastabilities.

import cellrank as cr

adata = cr.datasets.pancreas_preprocessed("../example.h5ad")


AnnData object with n_obs × n_vars = 2531 × 2000
    obs: 'day', 'proliferation', 'G2M_score', 'S_score', 'phase', 'clusters_coarse', 'clusters', 'clusters_fine', 'louvain_Alpha', 'louvain_Beta', 'initial_size_unspliced', 'initial_size_spliced', 'initial_size', 'n_counts', 'velocity_self_transition', 'dpt_pseudotime'
    var: 'highly_variable_genes', 'gene_count_corr', 'means', 'dispersions', 'dispersions_norm', 'fit_r2', 'fit_alpha', 'fit_beta', 'fit_gamma', 'fit_t_', 'fit_scaling', 'fit_std_u', 'fit_std_s', 'fit_likelihood', 'fit_u0', 'fit_s0', 'fit_pval_steady', 'fit_steady_u', 'fit_steady_s', 'fit_variance', 'fit_alignment_scaling', 'velocity_genes'
    uns: 'clusters_colors', 'clusters_fine_colors', 'diffmap_evals', 'iroot', 'louvain_Alpha_colors', 'louvain_Beta_colors', 'neighbors', 'pca', 'recover_dynamics', 'velocity_graph', 'velocity_graph_neg', 'velocity_params'
    obsm: 'X_diffmap', 'X_pca', 'X_umap', 'velocity_umap'
    varm: 'PCs', 'loss'
    layers: 'Ms', 'Mu', 'fit_t', 'fit_tau', 'fit_tau_', 'spliced', 'unspliced', 'velocity', 'velocity_u'
    obsp: 'connectivities', 'distances'

First, we prepare the kernel using the high-level pipeline and the estimator.

k =
    adata, weight_connectivities=0.2, softmax_scale=4, show_progress_bar=False
g =

To compute the Schur vectors, simply run the code below. The parameter n_components controls how many vectors to compute. We can also specify prior initial distribution over all cells as initial_distribution, by default it is uniform.


Lastly, we plot the vectors in the UMAP embedding (default).

Schur vector 1, Schur vector 2, Schur vector 3

Note that above, only 3 vectors are shown, because the 1st Schur vector is a constant vector of ones. This can be verified visually by plotting the first Schur vector.

Schur vector 0


/home/docs/checkouts/ MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
  ax = pl.figure(None, figsize, dpi=dpi).gca(projection=projection)

Method also computes the Schur matrix, see Compute Schur matrix.

Total running time of the script: ( 0 minutes 21.552 seconds)

Estimated memory usage: 724 MB

Gallery generated by Sphinx-Gallery