Edit on GitHub

starplast.benchmark

Building the same map twice, on the CPU and on the GPU, and showing what differs.

Two questions a switch labelled "GPU acceleration" raises and does not answer: how much faster, and is it the same map. The second matters more here. cuml's UMAP is not umap-learn -- different implementation, different random stream -- so turning the switch on does not speed a map up, it produces a different map of the same data. That is a fine thing to work with and a terrible thing to discover halfway through a comparison, so this runs both and puts them side by side.

The number that says how different: k-nearest-neighbour overlap. Two embeddings can look alike and place different genes together, and they can look unlike -- rotated, mirrored, differently scaled -- while preserving every neighbourhood. Coordinates cannot be compared directly; who is next to whom can, and that is what the map is read for.

def knn_overlap(A, B, k: int = 15) -> float:

Fraction of each point's k nearest neighbours shared between two embeddings.

1.0 is the same neighbourhoods throughout; 0.0 is no gene keeping a single neighbour. Rotation, reflection and scale do not touch it, which is what makes it the right comparison for two embeddings that were never going to have the same coordinates.

def compare( nodes, spec=None, sample: int = 2000, seed: int = 42, log=<built-in function print>) -> dict:

Build the same embedding both ways and report the times and the difference.

Bounded by sample because this is a demonstration, not a run: the point is to see the two maps beside each other and the two clocks beside each other, and waiting four minutes for the full proteome to answer "are these different" is not seeing it sooner.