Zog.HealthMetrics (Zog v0.4.0)

View Source

Native 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

analyze(builder)

@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
}

average_path_length(builder)

@spec average_path_length(Zog.SoA.t()) :: float()

Returns the average path length over all ordered pairs of distinct reachable nodes.

diameter(builder)

@spec diameter(Zog.SoA.t()) :: float()

Returns the diameter of the graph (longest shortest path).

eccentricity(builder)

@spec eccentricity(Zog.SoA.t()) :: %{required(Zog.SoA.label()) => float()}

Returns a map from node label to eccentricity.

nif_health_metrics(arg1, arg2, arg3, arg4)

@spec nif_health_metrics(
  0..18_446_744_073_709_551_615,
  [0..4_294_967_295] | <<_::_*32>>,
  [0..4_294_967_295] | <<_::_*32>>,
  [float()] | <<_::_*64>>
) :: term()

radius(builder)

@spec radius(Zog.SoA.t()) :: float()

Returns the radius of the graph (minimum eccentricity).