def partition(self, force=False): ''' Calculate the best nodal partition of G using the louvain algorithm as implemented in :func:`community.best_partition`. If desired, the node-wise partition can be accessed and manipulated by the nodal attribute "module" and the module-wise partition as ``G.graph["partition"]`` Parameters ---------- force : bool pass True to recalculate when a partition exists Returns ------- (dict, dict) Two dictionaries represent the resulting nodal partition of G. The first maps nodes to modules and the second maps modules to nodes. See Also -------- :func:`BrainNetwork.calc_nodal_partition` ''' if 'partition' not in self.graph: nodal_partition, module_partition = calc_nodal_partition(self) nx.set_node_attributes(self, nodal_partition, name='module') self.graph['partition'] = module_partition return nx.get_node_attributes(self, name='module'), self.graph['partition']
def setUpClass(self): self.karate = nx.karate_club_graph() self.totalpart = {x: [x] for x in list(self.karate.nodes)} self.triviallpart = {0: [x for x in list(self.karate.nodes)]} self.nonpart = {0: [0]} n, m = gm.calc_nodal_partition(self.karate) self.bestpart_n = n self.bestpart_m = m self.nonbinary = nx.karate_club_graph() nx.set_edge_attributes(self.nonbinary, '0.5', name='weight')
def throw_out_nonbinary_graph(self): with self.assertRaises(Exception): gm.calc_nodal_partition(self.nonbinary)