예제 #1
0
 def get_pre_recall():
     while len(self._G1.edges()) != 0:
         edge = max(nx.edge_betweenness(self._G1).items(), key=lambda item: item[1])[0]
         self._G1.remove_edge(edge[0], edge[1])
         components = [list(c) for c in list(nx.connected_components(self._G1))]
         if len(components) != len(self._partition):
             cur_Q = cal_Q(components, self._G1)
             if cur_Q > self._max_Q:
                 self._max_Q = cur_Q
                 self._partition = components
예제 #2
0
 def execute(self):
     while len(self._G.edges()) != 0:
         edge = max(nx.edge_betweenness(self._G).items(),key=lambda item:item[1])[0]
         self._G.remove_edge(edge[0], edge[1])
         components = list(nx.connected_components(self._G))
         if len(components) != len(self._partition):
             cur_Q = cal_Q(components, self._G_cloned)
             if cur_Q > self._max_Q:
                 self._max_Q = cur_Q
                 self._partition = components
     print self._max_Q
     print self._partition
     return self._partition
예제 #3
0
 def execute(self):
     while len(self._G.edges()) != 0:
         edge = max(nx.edge_betweenness(self._G).items(),
                    key=lambda item: item[1])[0]
         self._G.remove_edge(edge[0], edge[1])
         components = list(nx.connected_components(self._G))
         if len(components) != len(self._partition):
             cur_Q = cal_Q(components, self._G_cloned)
             if cur_Q > self._max_Q:
                 self._max_Q = cur_Q
                 self._partition = components
     print self._max_Q
     print self._partition
     return self._partition
예제 #4
0
        iter_time = 1
        while True:
            iter_time += 1
            mod_inc = self.first_stage()
            if mod_inc:
                self.second_stage()
            else:
                break
        return self.get_communities()


if __name__ == '__main__':
    path_list = ['../network/club.txt', '../data/facebook_combined.txt']
    graph_path = path_list[1]
    G = load_graph(graph_path)

    start_time = time.time()

    algorithm = Louvain(G)
    communities = algorithm.execute()

    execution_time = (time.time() - start_time)
    time_length = '{0:.2f}'.format(execution_time)
    print(time_length)

    print(len(communities))
    print(cal_Q(communities, G))

    for c in communities:
        print(c)