How to use leidenalg - 10 common examples

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 test_merge_nodes(self):
    G = ig.Graph.Full(100);
    partition = leidenalg.CPMVertexPartition(G, resolution_parameter=0.5);
    self.optimiser.merge_nodes(partition, consider_comms=leidenalg.ALL_NEIGH_COMMS);
    self.assertListEqual(
        partition.sizes(), [100],
        msg="CPMVertexPartition(resolution_parameter=0.5) of complete graph after merge nodes incorrect.");
    self.assertEqual(
        partition.total_weight_in_all_comms(),
        G.ecount(),
        msg="total_weight_in_all_comms not equal to ecount of graph.");
github vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
def test_Bipartite(self):
    graph = bipartite_graph
    partition, partition_0, partition_1 = \
        leidenalg.CPMVertexPartition.Bipartite(graph, resolution_parameter_01=0.2)
    self.optimiser.optimise_partition_multiplex([partition, partition_0, partition_1],
                                     layer_weights=[1, -1, -1])
    self.assertEqual(len(partition), 1)
github vtraag / leidenalg / tests / test_Optimiser.py View on Github external
def test_optimiser(self):
    G = reduce(ig.Graph.disjoint_union, (ig.Graph.Tree(10, 3, mode=ig.TREE_UNDIRECTED) for i in range(10)));
    partition = leidenalg.CPMVertexPartition(G, resolution_parameter=0);
    self.optimiser.consider_comms=leidenalg.ALL_NEIGH_COMMS;
    self.optimiser.optimise_partition(partition);
    self.assertListEqual(
        partition.sizes(), 10*[10],
        msg="After optimising partition failed to find different components with CPMVertexPartition(resolution_parameter=0)");
github vtraag / leidenalg / tests / test_Optimiser.py View on Github external
def test_diff_move_node_optimality(self):
    G = ig.Graph.Erdos_Renyi(100, p=5./100, directed=False, loops=False);
    partition = leidenalg.CPMVertexPartition(G, resolution_parameter=0.1);
    while 0 < self.optimiser.move_nodes(partition, consider_comms=leidenalg.ALL_NEIGH_COMMS):
      pass;
    for v in G.vs:
      neigh_comms = set(partition.membership[u.index] for u in v.neighbors());
      for c in neigh_comms:
        self.assertLessEqual(
          partition.diff_move(v.index, c), 1e-10, # Allow for a small difference up to rounding error.
          msg="Was able to move a node to a better community, violating node optimality.");
github vtraag / leidenalg / tests / test_Optimiser.py View on Github external
def test_neg_weight_bipartite(self):
    G = ig.Graph.Full_Bipartite(50, 50);
    G.es['weight'] = -0.1;
    partition = leidenalg.CPMVertexPartition(G, resolution_parameter=-0.1, weights='weight');
    self.optimiser.consider_comms=leidenalg.ALL_COMMS;
    self.optimiser.optimise_partition(partition);
    self.assertListEqual(
        partition.sizes(), 2*[50],
        msg="After optimising partition failed to find bipartite structure with CPMVertexPartition(resolution_parameter=-0.1)");
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 vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
def setUp(self):
    super(ModularityVertexPartitionTest, self).setUp();
    self.partition_type = leidenalg.ModularityVertexPartition;
github vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
def setUp(self):
    super(RBConfigurationVertexPartitionTest, self).setUp();
    self.partition_type = leidenalg.RBConfigurationVertexPartition;
github vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
def setUp(self):
    super(RBERVertexPartitionTest, self).setUp();
    self.partition_type = leidenalg.RBERVertexPartition;