From Cell-Level Velocities to Graph Transitions
A velocity vector describes a local direction of change in a cell’s expression coordinates. A neighbor graph provides a finite set of observed cells that could serve as nearby destinations. Projecting velocity onto this graph means comparing the predicted direction of change from a cell with the observed displacement from that cell to each of its graph neighbors, then converting those comparisons into relative transition scores.
The scores are useful because a continuous vector does not itself identify which observed cell is a plausible next point. Restricting comparisons to graph neighbors makes the calculation local. The result depends, however, on the coordinate system, the graph, and the scoring rule. It should be read as a direction-based ranking among candidate neighbors, not automatically as a literal probability of a cell’s future state.
The earlier material on velocity vectors in expression space establishes the cell-level velocity representation. Here, the task is to compare that vector with displacements to neighboring cells, using a consistent representation for both.
Definition and Assumptions
The cosine lies between \(-1\) and \(1\). A positive value indicates that the displacement has a component in the velocity direction; zero indicates perpendicular vectors; a negative value indicates an opposing direction. Since cosine similarity uses normalized vectors, it measures alignment, not the distance to the neighbor or the magnitude of the velocity.
The calculation requires several conditions. First, \(v_i\) and \(d_{ij}\) must be expressed in the same coordinate system, with compatible feature scaling. If coordinates have been transformed, velocities must be transformed consistently. Second, the graph must contain locally plausible candidates: the score compares only neighbors supplied to it and cannot recover a candidate omitted from the graph. Third, \(v_i\) and each \(d_{ij}\) used in the cosine must be nonzero. A zero vector has no direction, so its cosine is undefined. Finally, the temperature \(\tau\) must be chosen and reported: it determines how sharply scores concentrate on the best-aligned neighbors.
Why the Softmax Gives Relative Scores
The exponential makes larger cosine similarities receive larger positive weights, and division by their sum makes the weights add to one over the neighbors. In computation, it is safer to subtract the largest cosine before exponentiating. Let \(m_i=\max_{k\in N(i)}c_{ik}\). Then
This is algebraically identical to the original definition: each numerator and the denominator has been multiplied by the same positive factor, \(\exp(-m_i/\tau)\). Because \(c_{ij}-m_i\leq 0\), no exponential exceeds one, reducing the risk of numerical overflow. Subtracting the maximum does not alter the normalized scores.
The temperature governs concentration. For two neighbors with cosine values \(c_1\) and \(c_2\), their score ratio is
Thus, a smaller \(\tau\) magnifies cosine differences, while a larger \(\tau\) makes scores more even. This parameter changes the distribution of scores, not the underlying cosine similarities.
Worked Example: Three Neighbors in Two Dimensions
Suppose a hypothetical cell has velocity \(v_i=(1,1)\), and its three candidate neighbor displacements are \(d_{i1}=(2,0)\), \(d_{i2}=(1,1)\), and \(d_{i3}=(-1,1)\). Take \(\tau=0.2\). All vectors are nonzero and are assumed to use the same two-dimensional coordinates.
The cosine similarities are
The largest cosine is \(m_i=1\). Using maximum-subtracted exponentials, the unnormalized weights are
Their sum is approximately \(1.2379\). Dividing each weight by that sum gives \(T_{i1}\approx0.1868\), \(T_{i2}\approx0.8078\), and \(T_{i3}\approx0.0054\). These scores sum to approximately one, up to rounding. The perfectly aligned displacement receives the largest score; the perpendicular displacement receives a small but nonzero score.
Coordinate Choice and Projection
In practice, the coordinates may be a selected expression space or a lower-dimensional representation. If a linear map \(A\) changes coordinates, a consistent comparison uses transformed positions \(z_i=Ax_i\), transformed velocities \(u_i=Av_i\), and transformed displacements \(z_j-z_i=A(x_j-x_i)\). Computing cosine similarity after this transformation can give different results from computing it before transformation: cosine is invariant to a common rotation and uniform scaling, but not to general feature-wise rescaling or dimension reduction.
For a nonlinear coordinate map, transforming a velocity requires the map’s local derivative (Jacobian) at the cell, rather than simply treating a velocity as a difference between transformed points. If such a local transformation is unavailable or not justified, cosine comparisons in the nonlinear embedding may not represent the original expression-space velocity. The choice of representation is therefore part of the method, not a cosmetic plotting decision.
Worked Example: A Linear Rescaling Changes the Scores
Consider a hypothetical velocity \(v_i=(1,2)\) and two displacements \(d_{i1}=(1,0)\) and \(d_{i2}=(0,1)\). In the original coordinates, the cosines are \(1/\sqrt{5}\approx0.4472\) and \(2/\sqrt{5}\approx0.8944\). With \(\tau=0.2\), maximum-subtracted weights are
The normalized scores are approximately \(T_{i1}=0.0966\) and \(T_{i2}=0.9034\). The second displacement is more aligned in the original coordinates.
Now apply the same linear map \(A=\operatorname{diag}(2,1)\) to the velocity and displacements. They become \(Av_i=(2,2)\), \(Ad_{i1}=(2,0)\), and \(Ad_{i2}=(0,1)\). Both transformed cosines equal \(1/\sqrt{2}\approx0.7071\), so the two transition scores are \(0.5\) each. The transformation changed relative alignment because it rescaled one coordinate more than the other. This is why velocities and displacements must be compared in a declared, consistent space, and why coordinate scaling can affect the result.
Reading the Scores and Checking the Calculation
The scores \(T_{ij}\) are nonnegative and sum to one over \(j\in N(i)\), provided the neighbor set is nonempty and all included cosine values are defined. They express the relative allocation of a cell’s score across its candidate neighbors under the chosen cosine-and-temperature rule. They are not, without an additional probabilistic model and calibration, probabilities that the cell will physically transition to those neighbors. Nor do they measure how far a cell is expected to move: normalizing the vectors removes their lengths.
A useful diagnostic is to inspect the cosine values, not just the normalized scores. A high score can result because one neighbor is better aligned than the others even if all the cosine values are negative. In that case, the top neighbor is merely the least opposed candidate. Check whether candidate displacements and velocities use compatible normalization, whether the graph includes plausible local alternatives, and whether the score changes substantially under reasonable temperature choices. Also examine cells with zero or nearly zero velocity, very few neighbors, or tied cosine values. A zero velocity makes every cosine undefined; a nearly zero estimated velocity may have an unstable direction even when its cosine can be calculated.
When several neighbors have identical cosine values, they receive identical scores. With a very small temperature, tiny numerical differences can instead produce an almost one-neighbor allocation. Such concentration is not evidence by itself that the leading neighbor is a certain biological destination. It can reflect the temperature, measurement noise, or a small change in the estimated vector.
Worked Example: Strongly Aligned and Opposed Candidates
For a hypothetical cell, let \(v_i=(2,1)\) and let its three neighbor displacements be \(d_{i1}=(3,1)\), \(d_{i2}=(1,2)\), and \(d_{i3}=(-2,0)\). Assume the same coordinates are used for all vectors and set \(\tau=0.1\). The cosine values are
Using the unrounded cosine values and \(m_i=7/\sqrt{50}\), the stabilized weights are
The weight sum is approximately \(1.1496\), so the scores are \(T_{i1}\approx0.8698\), \(T_{i2}\approx0.1302\), and \(T_{i3}\approx5.70\times10^{-9}\). The third candidate is strongly opposed and receives essentially no weight at this temperature. The large contrast between the first two scores reflects both their cosine difference and the relatively small temperature.
Alternatives, Limitations, and Common Mistakes
A uniform allocation across graph neighbors ignores velocity direction and can be a useful baseline, but it does not use the estimated vector. A distance-based kernel ranks neighbors by proximity rather than directional alignment; it answers a different question. An unnormalized dot product \(v_i^\mathsf{T}d_{ij}\) uses both alignment and vector lengths, so long displacements or large velocity magnitudes can dominate. Cosine-based softmax instead emphasizes direction and yields normalized relative scores, but it discards magnitude and depends on the temperature.
The approach also inherits limitations of its inputs. A misspecified velocity, an unsuitable graph, inconsistent normalization, or a distorted low-dimensional representation can all produce misleading comparisons. The scores do not correct these problems, quantify uncertainty in the estimated velocity, or establish that observed neighbors are actual future states.
- Mistake: treating a large transition score as a calibrated chance of future transition. The normalization only makes scores sum to one across the selected neighbors under the specified rule. Without a calibrated transition model, interpret them as relative scores.
- Mistake: comparing a velocity in one representation with displacements in another. Cosines require compatible coordinates. Transform both consistently, or do not interpret the resulting alignment as a valid projection.
- Mistake: assuming the highest score means strong forward alignment. The highest-scoring neighbor may still have a negative cosine if all candidates are opposed. Inspect the raw cosines as well as their normalized scores.
- Mistake: interpreting the score as speed or distance traveled. Cosine normalization removes vector lengths. Use a separate, appropriate analysis if magnitude is the question.
Check Your Understanding
Try each problem, then compare your reasoning with the solutions below.
- If a cell has cosine similarities \(0.6\) and \(0.2\) to two neighbors, which receives the larger transition score for any \(\tau>0\)?
- Why does subtracting the maximum cosine before exponentiating leave the transition scores unchanged?
- What does a cosine of \(-0.4\) say about a neighbor displacement relative to the velocity?
- Why can a feature-wise rescaling change cosine-based transition scores?
- What should be done if a cell’s velocity vector is exactly zero?
Solutions. (1) The neighbor with cosine \(0.6\) has the larger score because the exponential is increasing and both scores share the same positive denominator. (2) Subtracting the same maximum from every cosine multiplies every exponential by the same positive factor, which cancels between numerator and denominator. (3) The displacement points partly opposite the velocity; the negative cosine does not by itself say whether it is the least opposed candidate. (4) Feature-wise rescaling changes vector angles in general, and cosine depends on those angles. (5) Its direction and therefore its cosine similarities are undefined; do not assign direction-based scores without an explicitly defined alternative.