예제 #1
0
def cugraph_call(cu_M, max_iter, pos_list, outbound_attraction_distribution,
                 lin_log_mode, prevent_overlapping, edge_weight_influence,
                 jitter_tolerance, barnes_hut_theta, barnes_hut_optimize,
                 scaling_ratio, strong_gravity_mode, gravity):

    G = cugraph.Graph()
    G.from_cudf_edgelist(cu_M,
                         source='0',
                         destination='1',
                         edge_attr='2',
                         renumber=False)

    # cugraph Force Atlas 2 Call
    t1 = time.time()
    pos = cugraph.force_atlas2(
        G,
        max_iter=max_iter,
        pos_list=pos_list,
        outbound_attraction_distribution=outbound_attraction_distribution,
        lin_log_mode=lin_log_mode,
        prevent_overlapping=prevent_overlapping,
        edge_weight_influence=edge_weight_influence,
        jitter_tolerance=jitter_tolerance,
        barnes_hut_optimize=barnes_hut_optimize,
        barnes_hut_theta=barnes_hut_theta,
        scaling_ratio=scaling_ratio,
        strong_gravity_mode=strong_gravity_mode,
        gravity=gravity)
    t2 = time.time() - t1
    print('Cugraph Time : ' + str(t2))
    return pos
예제 #2
0
def test_force_atlas2_multi_column_pos_list(graph_file, score, max_iter,
                                            barnes_hut_optimize):
    cu_M = utils.read_csv_file(graph_file)
    test_callback = TestCallback()
    pos = cugraph_call(cu_M,
                       max_iter=max_iter,
                       pos_list=None,
                       outbound_attraction_distribution=True,
                       lin_log_mode=False,
                       prevent_overlapping=False,
                       edge_weight_influence=1.0,
                       jitter_tolerance=1.0,
                       barnes_hut_optimize=False,
                       barnes_hut_theta=0.5,
                       scaling_ratio=2.0,
                       strong_gravity_mode=False,
                       gravity=1.0,
                       callback=test_callback)

    cu_M.rename(columns={'0': 'src_0', '1': 'dst_0'}, inplace=True)
    cu_M['src_1'] = cu_M['src_0'] + 1000
    cu_M['dst_1'] = cu_M['dst_0'] + 1000

    G = cugraph.Graph()
    G.from_cudf_edgelist(
        cu_M, source=["src_0", "src_1"],
        destination=["dst_0", "dst_1"],
        edge_attr="2"
    )

    pos_list = cudf.DataFrame()
    pos_list['vertex_0'] = pos['vertex']
    pos_list['vertex_1'] = pos_list['vertex_0'] + 1000
    pos_list['x'] = pos['x']
    pos_list['y'] = pos['y']

    cu_pos = cugraph.force_atlas2(
               G,
               max_iter=max_iter,
               pos_list=pos_list,
               outbound_attraction_distribution=True,
               lin_log_mode=False,
               prevent_overlapping=False,
               edge_weight_influence=1.0,
               jitter_tolerance=1.0,
               barnes_hut_optimize=False,
               barnes_hut_theta=0.5,
               scaling_ratio=2.0,
               strong_gravity_mode=False,
               gravity=1.0,
               callback=test_callback)

    cu_pos = cu_pos.sort_values('0_vertex')
    matrix_file = graph_file.with_suffix(".mtx")
    M = scipy.io.mmread(matrix_file)
    M = M.todense()
    cu_trust = trustworthiness(M, cu_pos[["x", "y"]].to_pandas())
    print(cu_trust, score)
    assert cu_trust > score
예제 #3
0
async def main(zmq_ctx):

    def map_positions(pos):
        return cudf.DataFrame(pos, columns=["x", "y"]).astype("float32")

    callback = GraphZmqCallback(
        zmq_ctx=zmq_ctx,
        map_positions=map_positions,
        nodes=nodes[["id", "color", "size"]],
        edges=edges[["edge", "bundle", "color"]],
        edge_col_names=["edge", "color", "bundle"],
        node_col_names=["id", "color", "size", "x", "y"],
    )
    cugraph.force_atlas2(
        graph,
        max_iter=500,
        callback=callback,
    )
    callback.update(msg=b"close")
    callback.close()