python类clustering()的实例源码

net_distribution.py 文件源码 项目:tweetopo 作者: zthxxx 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)
net_distribution.py 文件源码 项目:tweetopo 作者: zthxxx 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_clusterings(self):
        clusterings = nx.clustering(self.G)
        max_clustering = max(clusterings.values())
        return clusterings, max_clustering
compute_topological_features.py 文件源码 项目:tweegraph 作者: PGryllos 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
connections_simulation.py 文件源码 项目:gossip-python 作者: thomai 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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))
nxgraph.py 文件源码 项目:anomalous-vertices-detection 作者: Kagandi 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def get_clustering_coefficient(self, node):
        """
        Parameters
        ----------
        node:

        Returns
        -------
        NxGraph: Graph object

        Examples
        --------
        >>>
        """
        return nx.clustering(self._graph, node, weight=self._weight_field)


问题


面经


文章

微信
公众号

扫码关注公众号