Skip to contents

Calculate cosine similarity between vector field and cell-neighbor latent state difference. This function matches scTour's cosine_similarity exactly. The calculation borrows the ideas from scvelo.

Usage

cosine_similarity(
  zs,
  vf,
  reverse = FALSE,
  n_neigh = 20,
  t = NULL,
  var_transform = FALSE,
  neighbor_indices = NULL
)

Arguments

zs

Latent space matrix (cells x latent_dim)

vf

Vector field matrix (cells x latent_dim)

reverse

Whether to reverse vector field direction (default: FALSE)

n_neigh

Number of neighbors (default: 20)

t

Time vector for time-aware neighbors (default: NULL)

var_transform

Variance-stabilizing transformation (default: FALSE)

neighbor_indices

Pre-computed neighbor indices matrix (optional)

Value

Sparse matrix of cosine similarities