How to use the leidenalg.Optimiser function in leidenalg

To help you get started, we’ve selected a few leidenalg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vtraag / leidenalg / tests / test_Optimiser.py View on Github external
def setUp(self):
    self.optimiser = leidenalg.Optimiser();
github vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
def setUp(self):
      self.optimiser = leidenalg.Optimiser();
github iosonofabio / northstar / northstar / cluster_with_annotations.py View on Github external
def fit(self):
        '''Compute communities from a matrix with fixed nodes

        Returns:
            None, but the membership attribute is set as an array of int with
            size N - n_fixed with the community/cluster membership of all
            columns except the first n fixed ones.
        '''
        self._parse_graph()

        aa = self.annotations
        n_fixed = len(aa)
        g = self.graph
        N = g.vcount()

        opt = leidenalg.Optimiser()
        fixed_nodes = [int(i < n_fixed) for i in range(N)]

        # NOTE: initial membership is singletons except for atlas nodes, which
        # get the membership they have.
        aau = list(np.unique(aa))
        aaun = len(aau)
        initial_membership = []
        for j in range(N):
            if j < n_fixed:
                mb = aau.index(aa[j])
            else:
                mb = aaun + (j - n_fixed)
            initial_membership.append(mb)

        if self.metric == 'cpm':
            partition = leidenalg.CPMVertexPartition(
github iosonofabio / northstar / semiannotate / semiannotate.py View on Github external
_self_loops=True,
        _node_sizes=True,
        ):
        '''Compute communities from a matrix with fixed nodes

        Returns:
            None, but SemiAnnotate.membership is set as an array of int with
            size N - n_fixed with the community/cluster membership of all
            columns except the first n_fixed ones.
        '''
        import inspect
        import igraph as ig
        import leidenalg

        # Check whether this version of Leiden has fixed nodes support
        opt = leidenalg.Optimiser()
        sig = inspect.getfullargspec(opt.optimise_partition)
        if 'fixed_nodes' not in sig.args:
            raise ImportError('This version of the leidenalg module does not support fixed nodes. Please update to a later (development) version')

        matrix = self.matrix
        sizes = self.sizes
        n_fixed = self.n_fixed
        clustering_metric = self.clustering_metric
        resolution_parameter = self.resolution_parameter
        neighbors = self.neighbors

        L, N = matrix.shape
        n_fixede = np.sum(sizes[:n_fixed])
        Ne = np.sum(sizes)

        # Construct graph from the lists of neighbors
github iosonofabio / northstar / semiannotate / semiannotate.py View on Github external
def compute_communities(self):
        '''Compute communities from a matrix with fixed nodes

        Returns:
            None, but SemiAnnotate.membership is set as an array of int with
            size N - n_fixed with the community/cluster membership of all
            columns except the first n_fixed ones.
        '''
        import inspect
        import igraph as ig
        import leidenalg

        # Check whether this version of Leiden has fixed nodes support
        opt = leidenalg.Optimiser()
        sig = inspect.getfullargspec(opt.optimise_partition)
        if 'fixed_nodes' not in sig.args:
            raise ImportError('This version of the leidenalg module does not support fixed nodes. Please update to a later (development) version')

        matrix = self.matrix_expanded
        aa = self.atlas_annotations
        aau = self.atlas_annotations_unique
        n_fixed = len(aa)
        clustering_metric = self.clustering_metric
        resolution_parameter = self.resolution_parameter
        neighbors = self.neighbors

        L, N = matrix.shape

        # Construct graph from the lists of neighbors
        edges_d = set()