def reichardt_bornholdt(network, t_step=0.9, **kwargs): """ Produce a clustering of the network represented by the adjacency matrix `adjacency`. Parameters ---------- network: clustering.Network A Network object representing an adjacency matrix Returns ------- A Series representing the community membership """ clustering_c.set_globals(network, g=25) communities = clustering_c.cluster(network, **kwargs) communities = pd.DataFrame(np.array(communities), columns=['community']) communities['node'] = network.adjacency.index return communities
for x in binary] objective = pd.Series( {str(c.values):hessian(adjacency, c.values) for c in community_lists}) return objective.order(ascending=False) if __name__ == "__main__": # A network with two very obvious communities: # A, B, C, D and E, F, G, H. A single connection # from E to D joins the two communities rows = [[0,1,1,0,0,0,0,0], [1,0,1,1,0,0,0,0], [0,1,0,0,0,0,0,0], [1,1,0,0,0,0,0,0], [0,0,0,1,0,1,1,0], [0,0,0,0,1,0,0,1], [0,0,0,0,0,0,0,1], [0,0,0,0,1,1,0,0], ] names = ["A", "B", "C", "D", "E", "F", "G", "H"] adj = pd.DataFrame(rows).astype(float) adj.index = names adj.columns = names a = clustering_c.Network(adj) test_communities = pd.Series([0,0,0,0,0,0,0,0], index=names) modularity = _brute_force(a, clustering_c.modularity) potts = _brute_force(a, clustering_c.reichardt_bornholdt) clustering_c.test() clustering_c.cluster(a)