Example #1
0
    def test_get_node_degree(self):
        data = Reader().read('./tests/graph_data.txt', sep=' ')
        gmd = GraphModality(data=data)

        global_iid_map = OrderedDict()
        for raw_iid, raw_jid, val in data:
            global_iid_map.setdefault(raw_iid, len(global_iid_map))

        gmd.build(id_map=global_iid_map)

        degree = gmd.get_node_degree()

        self.assertEqual(degree.get(0)[0], 4)
        self.assertEqual(degree.get(0)[1], 1)
        self.assertEqual(degree.get(1)[0], 2)
        self.assertEqual(degree.get(1)[1], 1)
        self.assertEqual(degree.get(5)[0], 0)
        self.assertEqual(degree.get(5)[1], 1)

        degree = gmd.get_node_degree([0, 1], [0, 1])

        self.assertEqual(degree.get(0)[0], 1)
        self.assertEqual(degree.get(0)[1], 0)
        self.assertEqual(degree.get(1)[0], 0)
        self.assertEqual(degree.get(1)[1], 1)
Example #2
0
    def test_get_train_triplet(self):
        data = Reader().read('./tests/graph_data.txt', sep=' ')
        gmd = GraphModality(data=data)

        global_iid_map = OrderedDict()
        for raw_iid, raw_jid, val in data:
            global_iid_map.setdefault(raw_iid, len(global_iid_map))

        gmd.build(id_map=global_iid_map)
        rid, cid, val = gmd.get_train_triplet([0, 1, 2], [0, 1, 2])
        self.assertEqual(len(rid), 3)
        self.assertEqual(len(cid), 3)
        self.assertEqual(len(val), 3)

        rid, cid, val = gmd.get_train_triplet([0, 2], [0, 1])
        self.assertEqual(len(rid), 1)
        self.assertEqual(len(cid), 1)
        self.assertEqual(len(val), 1)
Example #3
0
    def test_build(self):
        data = Reader().read('./tests/graph_data.txt', sep=' ')
        gmd = GraphModality(data=data)

        global_iid_map = OrderedDict()
        for raw_iid, raw_jid, val in data:
            global_iid_map.setdefault(raw_iid, len(global_iid_map))

        gmd.build(id_map=global_iid_map)

        self.assertEqual(len(gmd.map_rid), 7)
        self.assertEqual(len(gmd.map_cid), 7)
        self.assertEqual(len(gmd.val), 7)
        self.assertEqual(gmd.matrix.shape, (7, 7))

        try:
            GraphModality().build()
        except ValueError:
            assert True