# Path: skmultilearn/cluster/base.py
# class LabelGraphClustererBase(object):
#     """An abstract base class for Label Graph clustering
# 
#     Inherit it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#     """
# 
#     def __init__(self, graph_builder):
#         """
# 
#         Attributes
#         ----------
#         graph_builder : a  GraphBuilderBase derivative class
#             a graph building class for the clusterer
#         """
#         super(LabelGraphClustererBase, self).__init__()
#         self.graph_builder = graph_builder
# 
#     def fit_predict(self, X, y):
#         """ Abstract method for clustering label space
# 
#         Implement it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#         Raises
#         ------
#         NotImplementedError
#             this is an abstract method
#         """
#         raise NotImplementedError("LabelGraphClustererBase::fit_predict()")
# 
# Path: skmultilearn/cluster/helpers.py
# def _membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of int
#         community membership i.e. vertex/label `i` is in community `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_id in enumerate(membership_vector):
#         list_of_members[community_id].append(vertex_id)
#     return list_of_members


import community
import networkx as nx
import numpy as np
from networkx.algorithms.community import asyn_lpa_communities
from .base import LabelGraphClustererBase
from .helpers import _membership_to_list_of_communities
        ----------
        X : None
            currently unused, left for scikit compatibility
        y : scipy.sparse
            label space of shape :code:`(n_samples, n_labels)`

        Returns
        -------
        arrray of arrays of label indexes (numpy.ndarray)
            label space division, each sublist represents labels that are in that community
        """
        edge_map = self.graph_builder.transform(y)

        if self.graph_builder.is_weighted:
            self.weights_ = dict(weight=list(edge_map.values()))
        else:
            self.weights_ = dict(weight=None)

        self.graph_ = nx.Graph()
        for n in range(y.shape[1]):
            self.graph_.add_node(n)

        for e, w in edge_map.items():
            self.graph_.add_edge(e[0], e[1], weight=w)

        if self.method == 'louvain':
            partition_dict = community.best_partition(self.graph_)
            memberships = [partition_dict[i] for i in range(y.shape[1])]

            return np.array(

# Path: skmultilearn/cluster/base.py
# class LabelGraphClustererBase(object):
#     """An abstract base class for Label Graph clustering
# 
#     Inherit it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#     """
# 
#     def __init__(self, graph_builder):
#         """
# 
#         Attributes
#         ----------
#         graph_builder : a  GraphBuilderBase derivative class
#             a graph building class for the clusterer
#         """
#         super(LabelGraphClustererBase, self).__init__()
#         self.graph_builder = graph_builder
# 
#     def fit_predict(self, X, y):
#         """ Abstract method for clustering label space
# 
#         Implement it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#         Raises
#         ------
#         NotImplementedError
#             this is an abstract method
#         """
#         raise NotImplementedError("LabelGraphClustererBase::fit_predict()")
# 
# Path: skmultilearn/cluster/helpers.py
# def _membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of int
#         community membership i.e. vertex/label `i` is in community `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_id in enumerate(membership_vector):
#         list_of_members[community_id].append(vertex_id)
#     return list_of_members


# Path: skmultilearn/cluster/networkx.py
import community
import networkx as nx
import numpy as np
from networkx.algorithms.community import asyn_lpa_communities
from .base import LabelGraphClustererBase
from .helpers import _membership_to_list_of_communities

        ----------
        X : None
            currently unused, left for scikit compatibility
        y : scipy.sparse
            label space of shape :code:`(n_samples, n_labels)`

        Returns
        -------
        arrray of arrays of label indexes (numpy.ndarray)
            label space division, each sublist represents labels that are in that community
        """
        edge_map = self.graph_builder.transform(y)

        if self.graph_builder.is_weighted:
            self.weights_ = dict(weight=list(edge_map.values()))
        else:
            self.weights_ = dict(weight=None)

        self.graph_ = nx.Graph()
        for n in range(y.shape[1]):
            self.graph_.add_node(n)

        for e, w in edge_map.items():
            self.graph_.add_edge(e[0], e[1], weight=w)

        if self.method == 'louvain':
            partition_dict = community.best_partition(self.graph_)
            memberships = [partition_dict[i] for i in range(y.shape[1])]

            return np.array(

                _membership_to_list_of_communities(