Exemplo n.º 1
0
Arquivo: prone++.py Projeto: zrt/cogdl
    def prop(self, params):
        prop_types = [
            key for key, value in params.items()
            if value == 1 and key in self.prop_types
        ]
        if not prop_types:
            print(" -- dropped -- ")
            return None, None

        prop_result_list = []
        for selected_prop in prop_types:
            prop_result = propagate(self.adj, self.emb, selected_prop, params)
            prop_result_list.append(prop_result)

        if self.loss_type == "infomax":
            neg_prop_result = []
            pmt = self.permutation
            for s_prop in prop_types:
                neg_prop = propagate(self.adj, self.emb[pmt], s_prop, params)
                neg_prop[pmt] = neg_prop
                neg_prop_result.append(neg_prop)
            return np.array(prop_result_list), np.array(neg_prop_result)
        elif self.loss_type == "infonce":
            return np.array(prop_result_list), None
        elif self.loss_type == "sparse":
            return np.array(prop_result_list), None
        else:
            raise ValueError(
                "use 'infonce', 'infomax' or 'sparse' loss, currently using {}"
                .format(self.loss_type))
Exemplo n.º 2
0
Arquivo: prone++.py Projeto: zrt/cogdl
    def __call__(self, emb, adj):
        if len(self.filter_types) == 1 and self.filter_types[0] == "identity":
            return emb

        dim = emb.shape[1]
        prop_result = []
        for tp in self.filter_types:
            prop_result.append(propagate(adj, emb, tp))
        prop_result_emb = np.concatenate(prop_result, axis=1)
        if self.svd:
            prop_result_emb = get_embedding_dense(prop_result_emb, dim)
        return prop_result_emb
def test_prone_module():
    from cogdl.layers.prone_module import propagate
    import scipy.sparse as sp

    data = np.ones(400)
    edge_index = np.random.randint(0, 100, (2, 200))
    row = np.concatenate((edge_index[0], edge_index[1]))
    col = np.concatenate((edge_index[1], edge_index[0]))

    print(row.shape, col.shape)
    matrix = sp.csr_matrix((data, (row, col)), shape=(100, 100))
    emb = np.random.randn(100, 20)
    for module in ["heat", "ppr", "gaussian", "prone", "sc"]:
        res = propagate(matrix, emb, module)
        assert res.shape == emb.shape