ash_model.measures.hyperedge_profile_purity

ash_model.measures.hyperedge_profile_purity(h, hyperedge_id, tid)[source]

Computes the purity of the hyperedge profile, i.e., the relative frequency of the most common attribute value for each attribute in the hyperedge nodes’ profiles.

Parameters:
  • h (ASH) – The ASH object

  • hyperedge_id (str) – The hyperedge id

  • tid (int) – The temporal id

Returns:

A dictionary with attribute names as keys and their purity as values

Return type:

dict

Examples

Build a small temporal ASH from 10 Barabási–Albert graphs, annotate nodes with a categorical color, then compute the purity on one hyperedge at tid=0.

>>> import numpy as np, networkx as nx
>>> from ash_model.utils.networkx import from_networkx_maximal_cliques_list
>>> Gs = [nx.barabasi_albert_graph(100, 3, seed=i) for i in range(10)]
>>> rng = np.random.default_rng(42)
>>> for G in Gs:
...     for n in G.nodes():
...         G.nodes[n]['color'] = 'red' if rng.integers(0, 2) == 0 else 'blue'
>>> h = from_networkx_maximal_cliques_list(Gs)
>>> tid = 0
>>> he0 = next(iter(h.hyperedges(start=tid, end=tid)))
>>> hyperedge_profile_purity(h, he0, tid)
{'color': {'blue': 1.0}}