graph_tool.stats.distance_histogram#
- graph_tool.stats.distance_histogram(g, weight=None, bins=[0, 1], samples=None, float_count=True)[source]#
Return the shortest-distance histogram for each vertex pair in the graph.
- Parameters:
- g
Graph Graph to be used.
- weight
EdgePropertyMap(optional, default: None) Edge weights.
- binslist of bins (optional, default: [0, 1])
List of bins to be used for the histogram. The values given represent the edges of the bins (i.e. lower and upper bounds). If the list contains two values, this will be used to automatically create an appropriate bin range, with a constant width given by the second value, and starting from the first value.
- samplesint (optional, default: None)
If supplied, the distances will be randomly sampled from a number of source vertices given by this parameter. If samples is None (default), all pairs are used.
- float_countbool (optional, default: True)
If True, the counts in each histogram bin will be returned as floats. If False, they will be returned as integers.
- g
- Returns:
- counts
numpy.ndarray The bin counts.
- bins
numpy.ndarray The bin edges.
- counts
See also
vertex_histVertex histograms.
edge_histEdge histograms.
vertex_averageAverage of vertex degree, properties.
distance_histogramShortest-distance histogram.
Notes
The algorithm runs in \(O(V^2)\) time, or \(O(V^2\log V)\) if weight is not None. If samples is supplied, the complexities are \(O(\text{samples}\times V)\) and \(O(\text{samples}\times V\log V)\), respectively.
If enabled during compilation, this algorithm runs in parallel.
Examples
>>> g = gt.random_graph(100, lambda: (3, 3)) >>> hist = gt.distance_histogram(g) >>> print(hist) [array([ 0., 300., 866., 2189., 3825., 2525., 195.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)] >>> hist = gt.distance_histogram(g, samples=10) >>> print(hist) [array([ 0., 30., 87., 221., 400., 236., 16.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]