kg_topology_toolbox.utils.composition_count

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

Compute 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

  • metapaths (bool) – If True, the number of compositions is computed separately for each unique metapath.

  • directed (bool) – 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 any edge between (h, t).