Beispiel #1
0
def test_dirac_aids_norm(coord1, coord2, e_cost, expected):
    node0 = Node(0, LabelNodeAIDS(*coord1))
    node1 = Node(1, LabelNodeAIDS(*coord2))

    edit_cost = EditCostAIDS(*e_cost)
    result = edit_cost.cost_substitute_node(node0, node1)

    assert result == expected
    assert edit_cost.cost_insert_node(node0) == e_cost[0]
    assert edit_cost.cost_delete_node(node1) == e_cost[1]
Beispiel #2
0
def test_1_node_same(ged):
    gr_src = Graph('gr1', 'gr1.gxl', 1)
    gr_trgt = Graph('gr2', 'gr2.gxl', 1)

    gr_src.add_node(Node(0, LabelNodeAIDS('C', 1, 1, 2., 2.)))

    gr_trgt.add_node(Node(0, LabelNodeAIDS('C', 1, 1, 2., 2.)))

    dist = ged.compute_edit_distance(gr_src, gr_trgt)

    expected_dist = 0.
    assert dist == expected_dist
Beispiel #3
0
def test_1_node(ged):
    gr_src = Graph('gr1', 'gr1.gxl', 1)
    gr_trgt = Graph('gr2', 'gr2.gxl', 1)

    gr_src.add_node(Node(0, LabelNodeAIDS('C', 1, 1, 2., 2.)))

    gr_trgt.add_node(Node(0, LabelNodeAIDS('O', 1, 1, 2., 2.)))

    dist = ged.compute_edit_distance(gr_src, gr_trgt)

    expected_dist = 2.2
    print(dist)
    print(ged.C.base)
    print(ged.C_star.base)
    print(ged.phi.base)
    assert dist == expected_dist
Beispiel #4
0
def test_2_node(ged):
    gr_src = Graph('gr1', 'gr1.gxl', 2)
    gr_trgt = Graph('gr2', 'gr2.gxl', 2)

    gr_src.add_node(Node(0, LabelNodeAIDS('C', 1, 1, 2., 2.)))
    gr_src.add_node(Node(1, LabelNodeAIDS('O', 1, 1, 2., 2.)))

    gr_trgt.add_node(Node(0, LabelNodeAIDS('C', 1, 1, 2., 2.)))
    gr_trgt.add_node(Node(1, LabelNodeAIDS('C', 1, 1, 2., 2.)))

    dist = ged.compute_edit_distance(gr_src, gr_trgt)

    np_C = np.asarray(ged.C)
    expected_C = np.array([[0., 0, 1.1, np.inf], [2.2, 2.2, np.inf, 1.1],
                           [1.1, np.inf, 0., 0.], [np.inf, 1.1, 0., 0.]])
    assert np.array_equal(np_C, expected_C)

    expected_dist = 2.2
    assert dist == expected_dist
Beispiel #5
0
def test_3_nodes_1_node(ged):
    gr_src = Graph('gr1', 'gr1.gxl', 3)
    gr_trgt = Graph('gr2', 'gr2.gxl', 1)

    gr_src.add_node(Node(0, LabelNodeAIDS('O', 1, 1, 2., 2.)))
    gr_src.add_node(Node(1, LabelNodeAIDS('C', 1, 1, 2., 2.)))
    gr_src.add_node(Node(2, LabelNodeAIDS('O', 1, 1, 2., 2.)))

    gr_src.add_edge(Edge(0, 1, LabelEdge(0)))
    gr_src.add_edge(Edge(1, 2, LabelEdge(0)))

    gr_trgt.add_node(Node(0, LabelNodeAIDS('H', 1, 1, 2., 2.)))

    dist = ged.compute_edit_distance(gr_src, gr_trgt)

    print(ged.C.base)
    print(ged.C_star.base)

    expected_dist = 4.6
    assert round(dist, 2) == expected_dist
Beispiel #6
0
def test_with_deleted_node(ged):
    gr_src = Graph('gr1', 'gr1.gxl', 3)
    gr_trgt = Graph('gr2', 'gr2.gxl', 3)

    gr_src = Graph('gr1', 'gr1.gxl', 5)
    gr_src.add_node(Node(0, LabelNodeAIDS('O', 1, 1, 2., 2.)))
    gr_src.add_node(Node(1, LabelNodeAIDS('C', 1, 1, 2., 2.)))
    gr_src.add_node(Node(2, LabelNodeAIDS('O', 1, 1, 2., 2.)))
    # print(gr_src)
    gr_src.add_node(Node(3, LabelNodeAIDS('Cl', 1, 1, 2., 2.)))
    gr_src.add_node(Node(4, LabelNodeAIDS('N', 1, 1, 2.4, 2.)))

    gr_src.add_edge(Edge(0, 3, LabelEdge(0)))
    gr_src.add_edge(Edge(1, 3, LabelEdge(0)))

    gr_src.add_edge(Edge(4, 2, LabelEdge(0)))
    gr_src.add_edge(Edge(3, 4, LabelEdge(0)))

    gr_src.remove_node_by_idx(4)
    gr_src.remove_node_by_idx(3)
    print(gr_src)

    gr_trgt.add_node(Node(0, LabelNodeAIDS('H', 1, 1, 2., 2.)))
    gr_trgt.add_node(Node(1, LabelNodeAIDS('Ca', 1, 1, 2., 2.)))
    gr_trgt.add_node(Node(2, LabelNodeAIDS('C', 1, 1, 2., 2.)))

    gr_trgt.add_edge(Edge(0, 1, LabelEdge(0)))
    gr_trgt.add_edge(Edge(1, 2, LabelEdge(0)))
    gr_trgt.add_edge(Edge(2, 0, LabelEdge(0)))

    dist = ged.compute_edit_distance(gr_src, gr_trgt)

    print(ged.C.base)
    print(ged.C_star.base)

    expected_dist = 4.7
    print(dist)
    assert round(dist, 2) == expected_dist
Beispiel #7
0
def test_label_AIDS():
    expected = ('C', 0, 1, 6., 5.)
    label = LabelNodeAIDS(*expected)

    assert label.get_attributes() == expected