Graph algorithms¶
Search, connected components and communities on a graph store (Graphs) or a skeleton store (Skeletons). Each function reads all of the level’s edges into memory. On a skeleton store, the edges are the parent links.
Function |
What it does |
Returns |
|---|---|---|
|
Hop count from |
|
|
Dijkstra; A* when |
|
|
Component label per vertex, edges undirected. |
|
|
Coreness: the largest k for which the vertex is in a subgraph where every vertex has at least k neighbours. |
|
|
Communities by synchronous label propagation. Labels can oscillate; check |
|
|
Communities that maximise modularity. Here |
|
Vertices are numbered in store order (chunk by chunk), not in the input file’s
order. Row i of read_graph(store)["positions"] is vertex i. Labels are
numbered in order of each group’s lowest vertex. If the store has no edge
attribute named by weight, every edge weighs 1.
The example store holds two 6-vertex cliques joined by one edge, and a separate
3-vertex path. Each edge has a length attribute.
from zarr_vectors.types.graphs import read_graph
from zarr_vectors_tools.algorithms import compute_connected_components, shortest_path
positions = read_graph("net.zv")["positions"] # row i = vertex i
shortest_path("net.zv", 0, 14, weight="length")
# {'path': [0, 5, 6, 14], 'cost': 95.0, 'visited': 12}
compute_connected_components("net.zv")["labels"]
# [0 0 0 0 0 0 0 0 0 0 1 1 1 0 0]
For your own algorithms, build_adjacency(level_group, *, weight_attr=None) in
zarr_vectors_tools.algorithms.graph_search returns each vertex’s neighbours,
paired with their edge weights, and the vertex count. Get level_group from
zarr_vectors.building.get_resolution_level(open_store(path), 0). For per-neuron measures
such as cable length, see skeleton metrics.