networks.compare.py

class apparent.networks.compare.NetworkComparator(networks)

A class to compare networks using curvature-based metrics and Scott package.

This class provides functionality to compute pairwise distances between networks using various curvature measures. It leverages the Scott package for robust network comparison through topological data analysis.

Parameters:

networks (list) – A list of NetworkX graphs to compare.

networks

A list of NetworkX graphs to compare.

Type:

list

Examples

>>> import networkx as nx
>>> from apparent.networks import NetworkComparator
>>>
>>> # Create sample networks
>>> G1 = nx.karate_club_graph()
>>> G2 = nx.erdos_renyi_graph(34, 0.1)
>>> networks = [G1, G2]
>>>
>>> # Compare networks
>>> comparator = NetworkComparator(networks)
>>> distances = comparator.compare(measure="forman_curvature")
>>> print(f"Distance matrix shape: {distances.shape}")
__init__(networks)

Initialize the NetworkComparator instance.

Parameters:

networks (list) – List of NetworkX graphs to compare. Each graph should be a valid NetworkX graph object.

Examples

>>> G1 = nx.karate_club_graph()
>>> G2 = nx.erdos_renyi_graph(34, 0.1)
>>> comparator = NetworkComparator([G1, G2])
compare(measure='forman_curvature', metric='landscape', weight=None, alpha=0.0, prob_fn=None, **kwargs) ndarray

Compare networks using Scott’s Comparator and return a pairwise distance matrix.

This method computes pairwise distances between all networks using the specified curvature measure and comparison metric. The computation is performed for all unique pairs of networks, creating a symmetric distance matrix.

Parameters:
  • measure (str, optional) – The curvature measure to use for comparison. Default is “forman_curvature”. Available measures depend on the Scott package implementation.

  • metric (str, optional) – The comparison metric to use for computing distances between curvature distributions. Default is “landscape”.

  • weight (str or None, optional) – The edge attribute to use as weight when computing curvatures. If None, edges are treated as unweighted. Default is None.

  • alpha (float, optional) – The alpha parameter for the Comparator, used in certain curvature measures. Default is 0.0.

  • prob_fn (callable or None, optional) – A probability function for the Comparator. If None, uses default probability function from Scott package. Default is None.

  • **kwargs (dict, optional) – Additional keyword arguments passed to the Scott Comparator.

Returns:

D – A symmetric pairwise distance matrix of shape (n_networks, n_networks). D[i, j] represents the distance between networks i and j.

Return type:

np.ndarray

Raises:

ValueError – If no networks are provided for comparison.

Examples

>>> G1 = nx.karate_club_graph()
>>> G2 = nx.erdos_renyi_graph(34, 0.1)
>>> comparator = NetworkComparator([G1, G2])
>>> distances = comparator.compare(measure="forman_curvature", metric="landscape")
>>> print(f"Distance between networks: {distances[0, 1]}")