我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用networkx.clustering()。
def __init__(self, edges, measure='pagerank'): ''' Class for analysis graph :param edges: weighted_edges The edges must be given as 3-tuples like (u,v,weight) :param measure: what measure for analysis to filter, must be one of 'degree' or 'pagerank' or 'clustering' ''' self.measures = ['degree', 'pagerank', 'clustering'] self.measure = measure self.ranks = {} self.G = nx.Graph() self.import_data(edges)
def get_clusterings(self): clusterings = nx.clustering(self.G) max_clustering = max(clusterings.values()) return clusterings, max_clustering
def get_clustering_index(pair_id): global graph id_1 = int(pair_id.split('_')[0]) id_2 = int(pair_id.split('_')[1]) return nx.clustering(graph, id_1) + nx.clustering(graph, id_2)
def run(self): ip_addresses = ['192.168.1.%s' % x for x in range(1, self._number_clients)] ports = [x for x in range(1, 2)] clients = [] progress = 0 for ip_addr in ip_addresses: print_progress(progress, self._number_clients, suffix="Running simulation") for port in ports: progress += 1 client = Client(ip_addr, port, clients[0] if len(clients) > 0 else None, max_chache_size=self._number_connections_per_client) clients.append(client) connection = Connection(client, clients[0]) connection.initiate() bootstrapper_connections = clients[0].get_connections() for conn in bootstrapper_connections: connection = Connection(client, conn.second_client) connection.initiate() graph = networkx.nx.Graph() for client in clients: logging.error(client.get_ident()) logging.error(client.get_connection_idents()) for node in client.get_connections(): graph.add_edge(node.first_client.get_ident(), node.second_client.get_ident()) networkx.draw(graph, with_labels=False) plt.savefig("path_graph.pdf") print("Network is connected: %s" % networkx.is_connected(graph)) print("Average shortest path length: %s" % networkx.average_shortest_path_length(graph)) print("Average bipartite clustering coefficent %s" % networkx.average_clustering(graph)) print("Bipartite clustering coefficent %s" % networkx.clustering(graph)) print("degree_assortativity_coefficient %s" % networkx.degree_assortativity_coefficient(graph))
def get_clustering_coefficient(self, node): """ Parameters ---------- node: Returns ------- NxGraph: Graph object Examples -------- >>> """ return nx.clustering(self._graph, node, weight=self._weight_field)