Zog.HealthMetrics (Zog v0.4.0)
View SourceNative graph health metrics backed by Zog (Zig) via Zigler.
This module computes structural distance metrics derived from all-pairs shortest paths: eccentricity, diameter, radius, and average path length.
Distances are weighted and computed using Dijkstra's algorithm from every node. Weights are expected to be non-negative.
Summary
Functions
Computes all health metrics at once.
Returns the average path length over all ordered pairs of distinct reachable nodes.
Returns the diameter of the graph (longest shortest path).
Returns a map from node label to eccentricity.
Returns the radius of the graph (minimum eccentricity).
Functions
@spec analyze(Zog.SoA.t()) :: %{ eccentricity: %{required(Zog.SoA.label()) => float()}, diameter: float(), radius: float(), average_path_length: float() }
Computes all health metrics at once.
Returns a map with:
:eccentricity— a map from node label to its eccentricity (the maximum distance to any other reachable node).:diameter— the largest eccentricity in the graph.:radius— the smallest eccentricity in the graph.:average_path_length— the average shortest-path distance over all ordered pairs of distinct reachable nodes.
Examples
iex> builder = Zog.directed()
...> |> Zog.add_edge(:a, :b, 1.0)
...> |> Zog.add_edge(:b, :c, 1.0)
iex> Zog.HealthMetrics.analyze(builder)
%{
eccentricity: %{a: 2.0, b: 1.0, c: 0.0},
diameter: 2.0,
radius: 0.0,
average_path_length: 1.3333333333333333
}
Returns the average path length over all ordered pairs of distinct reachable nodes.
Returns the diameter of the graph (longest shortest path).
@spec eccentricity(Zog.SoA.t()) :: %{required(Zog.SoA.label()) => float()}
Returns a map from node label to eccentricity.
Returns the radius of the graph (minimum eccentricity).