kg_topology_toolbox.utils.composition_count

kg_topology_toolbox.utils.composition_count(df, chunk_size, workers, directed=True)[source]

A helper function to compute the composition count of a graph.

Parameters:
  • df (DataFrame) – A graph represented as a pd.DataFrame. Must contain the columns h and t. No self-loops should be present in the graph.

  • chunk_size (int) – Size of chunks of columns of the adjacency matrix to be processed together.

  • workers (int) – Number of workers processing chunks concurrently

  • directed (bool) – Boolean flag. If false, bidirectional edges are considered for triangles by adding the adjacency matrix and its transposed. Default: True.

Return type:

DataFrame

Returns:

The results dataframe. Contains the following columns: - h (int): Index of the head entity. - t (int): Index of the tail entity. - n_triangles (int): Number of compositions for the (h, t) edge.