Source code for hypergraphx.communities.hyperlink_comm.hyperlink_communities

import logging
import networkx as nx
import numpy as np
import scipy.spatial.distance as ssd
from scipy.cluster.hierarchy import fcluster, linkage

from hypergraphx import Hypergraph
from hypergraphx.measures.edge_similarity import jaccard_distance as jaccard
from hypergraphx.readwrite.io_pickle import load_pickle, save_pickle






def _cut_dendrogram(dendrogram, cut_height):
    cut = fcluster(dendrogram, t=cut_height, criterion="distance")
    return cut


def _edge_label2node_labels(h, labels):
    nodes = {}
    for i in range(len(labels)):
        label_arco = labels[i]
        for nodo in h[i]:
            if nodo not in nodes:
                nodes[nodo] = []
                nodes[nodo].append(label_arco)
            else:
                nodes[nodo].append(label_arco)
    return nodes






[docs] def overlapping_communities( H: Hypergraph, dendrogram: np.ndarray, cut_height: float ) -> dict: """ Returns the overlapping communities in the dendrogram at the given cut height Parameters ---------- H : Hypergraph The hypergraph of interest dendrogram : np.ndarray The dendrogram of the given hypergraph cut_height The cut height Returns ------- dict The overlapping communities """ cut = _cut_dendrogram(dendrogram, cut_height) h = H.get_edges() labels = _edge_label2node_labels(h, cut) return labels