def transition_matrix(adata, vkey='<STR_LIT>', basis=None, backward=False, self_transitions=True, scale=<NUM_LIT:10>, perc=None,<EOL>use_negative_cosines=False, weight_diffusion=<NUM_LIT:0>, scale_diffusion=<NUM_LIT:1>, weight_indirect_neighbors=None,<EOL>n_neighbors=None, vgraph=None):
if vkey+'<STR_LIT>' not in adata.uns:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>graph = csr_matrix(adata.uns[vkey + '<STR_LIT>']).copy() if vgraph is None else vgraph.copy()<EOL>if self_transitions:<EOL><INDENT>confidence = graph.max(<NUM_LIT:1>).A.flatten()<EOL>ub = np.percentile(confidence, <NUM_LIT>)<EOL>self_prob = np.clip(ub - confidence, <NUM_LIT:0>, <NUM_LIT:1>)<EOL>graph.setdiag(self_prob)<EOL><DEDENT>T = np.expm1(graph * scale)  <EOL>if vkey + '<STR_LIT>' in adata.uns.keys():<EOL><INDENT>graph_neg = adata.uns[vkey + '<STR_LIT>']<EOL>if use_negative_cosines:<EOL><INDENT>T -= np.expm1(-graph_neg * scale)<EOL><DEDENT>else:<EOL><INDENT>T += np.expm1(graph_neg * scale)<EOL>T.data += <NUM_LIT:1><EOL><DEDENT><DEDENT>if '<STR_LIT>' in adata.uns.keys() and weight_indirect_neighbors is not None and weight_indirect_neighbors < <NUM_LIT:1>:<EOL><INDENT>direct_neighbors = adata.uns['<STR_LIT>']['<STR_LIT>'] > <NUM_LIT:0><EOL>direct_neighbors.setdiag(<NUM_LIT:1>)<EOL>w = weight_indirect_neighbors<EOL>T = w * T + (<NUM_LIT:1>-w) * direct_neighbors.multiply(T)<EOL><DEDENT>if backward: T = T.T<EOL>T = normalize(T)<EOL>if n_neighbors is not None:<EOL><INDENT>T = T.multiply(get_connectivities(adata, mode='<STR_LIT>', n_neighbors=n_neighbors, recurse_neighbors=True))<EOL><DEDENT>if perc is not None:<EOL><INDENT>threshold = np.percentile(T.data, perc)<EOL>T.data[T.data < threshold] = <NUM_LIT:0><EOL>T.eliminate_zeros()<EOL><DEDENT>if '<STR_LIT>' + str(basis) in adata.obsm.keys():<EOL><INDENT>dists_emb = (T > <NUM_LIT:0>).multiply(squareform(pdist(adata.obsm['<STR_LIT>' + basis])))<EOL>scale_diffusion *= dists_emb.data.mean()<EOL>diffusion_kernel = dists_emb.copy()<EOL>diffusion_kernel.data = np.exp(-<NUM_LIT> * dists_emb.data ** <NUM_LIT:2> / scale_diffusion ** <NUM_LIT:2>)<EOL>T = T.multiply(diffusion_kernel)  <EOL>if <NUM_LIT:0> < weight_diffusion < <NUM_LIT:1>:  <EOL><INDENT>diffusion_kernel.data = np.exp(-<NUM_LIT> * dists_emb.data ** <NUM_LIT:2> / (scale_diffusion/<NUM_LIT:2>) ** <NUM_LIT:2>)<EOL>T = (<NUM_LIT:1>-weight_diffusion) * T + weight_diffusion * diffusion_kernel<EOL><DEDENT>T = normalize(T)<EOL><DEDENT>return T<EOL>
Computes transition probabilities from velocity graph

    Arguments
    ---------
    adata: :class:`~anndata.AnnData`
        Annotated data matrix.
    vkey: `str` (default: `'velocity'`)
        Name of velocity estimates to be used.
    basis: `str` or `None` (default: `None`)
        Restrict transition to embedding if specified
    backward: `bool` (default: `False`)
        Whether to use the transition matrix to push forward (`False`) or to pull backward (`True`)
    scale: `float` (default: 10)
        Scale parameter of gaussian kernel.
    weight_diffusion: `float` (default: 0)
        Relative weight to be given to diffusion kernel (Brownian motion)
    scale_diffusion: `float` (default: 1)
        Scale of diffusion kernel. 

    Returns
    -------
    Returns sparse matrix with transition probabilities.