Beispiel #1
0
    from_timestamp = timestamp(edge_list[start])
    to_timestamp = timestamp(edge_list[end])
    g = subgraph_by_timestamp(
        mg,
        from_timestamp,
        to_timestamp,
    )
    average_degree = 2 * g.number_of_edges() / g.number_of_nodes()
    embedding = model.deepwalk(g)
    t0 = time.time()
    comm_list = model.ddcrp(g, embedding, ddcrp_scale=scale, receptive_hop=hop)
    ddcrp_time = time.time() - t0
    comm_list = comm_list[ddcrp_cutoff:]
    init_comm, mapping = model.mcla(comm_list, comm)
    predicted_cluster_size = len(init_comm)
    new_comm = model.kmeans(embedding, init_comm)

    def response(new_comm: List[Set[int]]) -> Any:
        out = []
        for i, c in enumerate(mapping):
            if len(c) == 0:
                new = new_comm[i]
                out.append({
                    "type": "new",
                    "join": list(new),
                })
            elif len(c) == 1:
                old = comm[i]
                new = new_comm[i]
                out.append({
                    "type": "old",
        embedding = Model(seed, g.number_of_nodes(),
                          dim).deepwalk(g, deepwalk_epochs)
        for scale in range(1000, 30000, 1000):
            t0 = time.time()
            comm_list = Model(seed, g.number_of_nodes(),
                              dim).ddcrp(g,
                                         embedding,
                                         ddcrp_scale=scale,
                                         ddcrp_iterations=ddcrp_iterations)
            ddcrp_time = time.time() - t0
            comm_list = comm_list[ddcrp_cutoff:]
            comm, _ = Model.mcla(comm_list)
            predicted_cluster_size = len(comm)
            modularity = nx.algorithms.community.quality.modularity(g, comm)
            performance = nx.algorithms.community.quality.performance(g, comm)
            improved_comm = Model.kmeans(embedding, comm)
            improved_modularity = nx.algorithms.community.quality.modularity(
                g, improved_comm)
            improved_performance = nx.algorithms.community.quality.performance(
                g, improved_comm)
            naive_comm = Model.kmeans(embedding, len(comm))
            naive_modularity = nx.algorithms.community.quality.modularity(
                g, naive_comm)
            naive_performance = nx.algorithms.community.quality.performance(
                g, naive_comm)
            write_line(graph_size, average_degree, cluster_size,
                       max_modularity, max_performance, scale,
                       predicted_cluster_size, modularity, performance,
                       improved_modularity, improved_performance,
                       naive_modularity, naive_performance, ddcrp_time)