distance_histogram

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:
gGraph

Graph to be used.

weightEdgePropertyMap (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.

Returns:
countsnumpy.ndarray

The bin counts.

binsnumpy.ndarray

The bin edges.

See also

vertex_hist

Vertex histograms.

edge_hist

Edge histograms.

vertex_average

Average of vertex degree, properties.

distance_histogram

Shortest-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.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

Examples

>>> g = gt.random_graph(100, lambda: (3, 3))
>>> hist = gt.distance_histogram(g)
>>> print(hist)
[array([   0.,  300.,  862., 2205., 3787., 2532.,  214.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([  0.,  30.,  87., 224., 377., 253.,  19.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]