cfpq_data.graphs.utils.edges_statistics#

Returns statistics of graph edges.

Functions

get_labels_frequency(graph)

Returns a dictionary with the number of edge labels used in the graph.

get_sorted_labels(graph, *[, reverse])

Returns a list of edge labels sorted by the number of uses in the graph.

get_labels_frequency(graph: MultiDiGraph) DefaultDict[Any, int][source]#

Returns a dictionary with the number of edge labels used in the graph.

Parameters:

graph (MultiDiGraph) -- Given graph.

Examples

>>> from cfpq_data import *
>>> g = labeled_two_cycles_graph(1, 1, labels=("a", "b"))
>>> list(g.edges(data=True))
[(1, 0, {'label': 'a'}), (0, 1, {'label': 'a'}), (0, 2, {'label': 'b'}), (2, 0, {'label': 'b'})]
>>> labels_frequency = get_labels_frequency(g)
>>> labels_frequency
defaultdict(<class 'int'>, {'a': 2, 'b': 2})
Returns:

labels_frequency -- Dictionary with edge labels usage frequency.

Return type:

DefaultDict[Any, int]

get_sorted_labels(graph: MultiDiGraph, *, reverse: bool = False) List[Any][source]#

Returns a list of edge labels sorted by the number of uses in the graph. The labels with equal number of uses are sorted lexicographically.

Parameters:
  • graph (MultiDiGraph) -- Given graph.

  • reverse (bool) -- If set to True, then the labels are sorted in reverse (ascending) order.

Examples

>>> from cfpq_data import *
>>> g = labeled_two_cycles_graph(42, 29)
>>> sorted_labels = get_sorted_labels(g)
>>> sorted_labels
['a', 'b']
Returns:

labels -- Sorted list of graph edge labels.

Return type:

List[Any]