Example #1
0
def test_sign_cora():
    args = get_default_args()
    args.task = "node_classification"
    args.model = "sign"
    args.dataset = "cora"
    args.lr = 0.00005
    args.hidden_size = 2048
    args.num_layers = 3
    args.num_propagations = 3
    args.dropout = 0.3
    args.directed = False
    args.dropedge_rate = 0.2
    args.asymm_norm = False
    args.set_diag = False
    args.remove_diag = False
    task = build_task(args)
    ret = task.train()
    assert 0 < ret["Acc"] < 1
Example #2
0
    def objective(self, trials):
        fixed_params = self.func_fixed()
        params = self.func_search(trials)
        params.update(fixed_params)
        args = self.build_args(params)
        model = build_model(args)
        task = build_task(args, model=model, dataset=self.dataset)

        result = task.train()

        for item in list(result.keys()):
            if "Val" in item:
                result = {item: result[item]}
                break

        assert type(result) == dict
        result = list(result.values())
        return 1.0 - sum(result) / len(result)
def test_grace():
    args = get_unsupervised_nn_args()
    args.model = "grace"
    args.num_layers = 2
    args.max_epoch = 2
    args.drop_feature_rates = [0.1, 0.2]
    args.drop_edge_rates = [0.2, 0.3]
    args.activation = "relu"
    args.proj_hidden_size = 32
    args.tau = 0.5
    args.dataset = "cora"
    args, dataset = build_nn_dataset(args)

    for bs in [-1, 512]:
        args.batch_size = bs
        task = build_task(args)
        ret = task.train()
        assert ret["Acc"] > 0
Example #4
0
def test_pairnorm_cora_deepgat():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "pairnorm"
    args.pn_model = "DeepGAT"
    args.nlayer = 10
    args.missing_rate = 100
    args.norm_mode = "PN-SI"
    args.residual = 0
    args.hidden_layers = 64
    args.nhead = 2
    args.dropout = 0.6
    args.norm_scale = 1.0
    args.no_fea_norm = "store_false"
    task = build_task(args)
    ret = task.train()
    assert 0 <= ret["Acc"] <= 1
Example #5
0
def test_hin2vec_dblp():
    args = get_default_args()
    args.task = 'multiplex_node_classification'
    args.dataset = 'gtn-dblp'
    args.model = 'hin2vec'
    dataset = build_dataset(args)
    args.walk_length = 5
    args.walk_num = 1
    args.negative = 3
    args.batch_size = 1000
    args.hop = 2
    args.epoches = 1
    args.lr = 0.025
    args.cpu = True
    model = build_model(args)
    task = build_task(args)
    ret = task.train()
    assert ret['f1'] > 0
Example #6
0
def test_gatne_amazon():
    args = get_default_args()
    args.task = "multiplex_link_prediction"
    args.dataset = "amazon"
    args.model = "gatne"
    args.walk_length = 5
    args.walk_num = 1
    args.window_size = 3
    args.worker = 5
    args.schema = None
    args.epoch = 1
    args.batch_size = 128
    args.edge_dim = 5
    args.att_dim = 5
    args.negative_samples = 5
    args.neighbor_samples = 5
    task = build_task(args)
    ret = task.train()
    assert ret["ROC_AUC"] >= 0 and ret["ROC_AUC"] <= 1
Example #7
0
def test_sdne_ppi():
    args = get_default_args()
    args.task = 'link_prediction'
    args.dataset = 'ppi'
    args.model = 'sdne'
    dataset = build_dataset(args)
    args.hidden_size1 = 100
    args.hidden_size2 = 16
    args.droput = 0.2
    args.alpha = 0.01
    args.beta = 5
    args.nu1 = 1e-4
    args.nu2 = 1e-3
    args.max_epoch = 1
    args.lr = 0.001
    model = build_model(args)
    task = build_task(args)
    ret = task.train()
    assert ret['ROC_AUC'] >= 0 and ret['ROC_AUC'] <= 1
def test_graph_mix():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "gcnmix"
    dataset = build_dataset(args)
    args.num_features = dataset.num_features
    args.num_classes = dataset.num_classes
    args.rampup_starts = 1
    args.rampup_ends = 100
    args.mixup_consistency = 5.0
    args.ema_decay = 0.999
    args.alpha = 1.0
    args.temperature = 1.0
    args.k = 10
    model = build_model(args)
    task = build_task(args)
    ret = task.train()
    assert ret["Acc"] >= 0 and ret["Acc"] <= 1
Example #9
0
def test_sdne_ppi():
    args = get_default_args()
    args.task = 'unsupervised_node_classification'
    args.dataset = 'ppi'
    args.model = 'sdne'
    dataset = build_dataset(args)
    args.hidden_size1 = 100
    args.hidden_size2 = 16
    args.droput = 0.2
    args.alpha = 0.01
    args.beta = 5
    args.nu1 = 1e-4
    args.nu2 = 1e-3
    args.max_epoch = 1
    args.lr = 0.001
    model = build_model(args)
    task = build_task(args)
    ret = task.train()
    assert ret['Micro-F1 0.9'] > 0
Example #10
0
def test_lightgcn_ali():
    args = get_default_args()
    args.dataset = "ali"
    args.model = "lightgcn"
    args.Ks = [1]
    args.dim = 8
    args.l2 = 1e-4
    args.mess_dropout = False
    args.mess_dropout_rate = 0.0
    args.edge_dropout = False
    args.edge_dropout_rate = 0.0
    args.ns = "rns"
    args.K = 1
    args.n_negs = 1
    args.pool = "mean"
    args.context_hops = 1
    task = build_task(args)
    ret = task.train(unittest=True)
    assert ret["Recall"] >= 0
Example #11
0
def test_jknet_jknet_cora():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "jknet"
    args.lr = 0.005
    args.layer_aggregation = "maxpool"
    args.node_aggregation = "sum"
    args.n_layers = 3
    args.n_units = 16
    args.in_features = 1433
    args.out_features = 7
    args.max_epoch = 2

    for aggr in ["maxpool", "concat"]:
        args.layer_aggregation = aggr
        task = build_task(args)
        ret = task.train()
        assert 0 <= ret["Acc"] <= 1
Example #12
0
def test_pyg_gcn_cora_sampler():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "pyg_gcn"
    args.cpu = True
    args.num_layers = 2
    args.sample_coverage = 20
    args.size_subgraph = 200
    args.num_walks = 20
    args.walk_length = 10
    args.size_frontier = 20
    sampler_list = ["node", "edge", "rw", "mrw"]

    for sampler in sampler_list:
        args.sampler = sampler
        task = build_task(args)
        ret = task.train()
        assert 0 <= ret["Acc"] <= 1
Example #13
0
def test_gdc_gcn_cora():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "gdc_gcn"
    dataset = build_dataset(args)
    args.num_features = dataset.num_features
    args.num_classes = dataset.num_classes
    args.num_layers = 1
    args.alpha = 0.05  # ppr filter param
    args.t = 5.0  # heat filter param
    args.k = 128  # top k entries to be retained
    args.eps = 0.01  # change depending on gdc_type
    args.dataset = dataset
    args.gdc_type = "ppr"  # ppr, heat, none

    model = build_model(args)
    task = build_task(args, dataset=dataset, model=model)
    ret = task.train()
    assert 0 <= ret["Acc"] <= 1
def test_pprgo_cora():
    args = get_default_args()
    args.cpu = True
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "pprgo"
    args.k = 32
    args.alpha = 0.5
    args.eval_step = 1
    args.batch_size = 32
    args.test_batch_size = 128
    args.activation = "relu"
    args.num_layers = 2
    args.nprop_inference = 2
    args.eps = 0.001
    for norm in ["sym", "row"]:
        args.norm = norm
        task = build_task(args)
        ret = task.train()
        assert 0 <= ret["Acc"] <= 1
Example #15
0
def test_dropedge_inceptiongcn_cora():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.model = "dropedge_gcn"
    args.baseblock = "inceptiongcn"
    args.inputlayer = "gcn"
    args.outputlayer = "gcn"
    args.hidden_size = 64
    args.dropout = 0.5
    args.withbn = False
    args.withloop = False
    args.nhiddenlayer = 1
    args.nbaseblocklayer = 1
    args.aggrmethod = "add"
    args.activation = F.relu
    args.task_type = "full"

    task = build_task(args)
    ret = task.train()
    assert 0 <= ret["Acc"] <= 1
Example #16
0
def test_gatne_amazon():
    args = get_default_args()
    args.task = 'multiplex_link_prediction'
    args.dataset = 'amazon'
    args.model = 'gatne'
    dataset = build_dataset(args)
    args.walk_length = 5
    args.walk_num = 1
    args.window_size = 3
    args.worker = 5
    args.iteration = 1
    args.epoch = 1
    args.batch_size = 128
    args.edge_dim = 5
    args.att_dim = 5
    args.negative_samples = 5
    args.neighbor_samples = 5
    model = build_model(args)
    task = build_task(args)
    ret = task.train()
    assert ret['ROC_AUC'] >= 0 and ret['ROC_AUC'] <= 1
Example #17
0
def test_graphsaint_cora():
    args = get_default_args()
    args.task = "node_classification"
    args.dataset = "cora"
    args.trainer = "graphsaint"
    args.model = "graphsaint"
    args.valid_cpu = True
    args.cpu = True
    args.architecture = "1-1-0"
    args.aggr = "concat"
    args.act = "relu"
    args.bias = "norm"
    args.sample_coverage = 10
    args.size_subgraph = 200
    args.num_walks = 20
    args.walk_length = 10
    args.size_frontier = 20
    args.sampler = "node"
    task = build_task(args)
    ret = task.train()
    assert 0 <= ret["Acc"] <= 1
Example #18
0
def train():
    args = build_default_args()
    dataset, args = get_dataset(args)

    combinations = get_parameters()
    best_parameters = None
    best_result = None
    best_val_acc = 0

    print(f"===== Start At: {get_time()} ===========")
    start = time.time()

    random_seeds = list(range(5))
    for item in combinations:
        for key, val in item.items():
            setattr(args, key, val)

        print(f"### -- Parameters: {args.__dict__}")
        result_list = []
        for seed in random_seeds:
            set_random_seed(seed)

            task = build_task(args, dataset=dataset)
            res = task.train()
            result_list.append(res)

        val_acc = [x["ValAcc"] for x in result_list]
        test_acc = [x["Acc"] for x in result_list]
        val_acc = sum(val_acc) / len(val_acc)
        print(f"###    Result: {val_acc}")
        if val_acc > best_val_acc:
            best_parameters = copy.deepcopy(args)
            best_result = dict(Acc=sum(test_acc) / len(test_acc),
                               ValAcc=val_acc)
    print(f"Best Parameters: {best_parameters}")
    print(f"Best result: {best_result}")

    end = time.time()
    print(f"===== End At: {get_time()} ===========")
    print("Time cost:", end - start)
Example #19
0
def test_supergat():
    args = get_default_args()
    args.model = "supergat"
    args.trainer = None
    args.heads = 8
    args.attention_type = "mask_only"
    args.neg_sample_ratio = 0.5
    args.edge_sampling_ratio = 0.8
    args.val_interval = 1
    args.att_lambda = 10
    args.pretraining_noise_ratio = 0
    args.to_undirected_at_neg = False
    args.to_undirected = False
    args.out_heads = None
    args.total_pretraining_epoch = 0
    args.super_gat_criterion = None
    args.scaling_factor = None
    dataset = build_dataset(args)
    model = build_model(args)
    task = build_task(args, dataset=dataset, model=model)
    ret = task.train()
    assert 0 <= ret["Acc"] <= 1
Example #20
0
def test_deepergcn_cora():
    args = get_default_args()
    args.dataset = "cora"
    args.task = "node_classification"
    args.model = "deepergcn"
    args.num_layers = 2
    args.connection = "res+"
    args.cluster_number = 3
    args.learn_beta = True
    args.learn_msg_scale = True
    args.aggr = "softmax_sg"
    args.batch_size = 1
    args.activation = "relu"
    args.beta = 1.0
    args.p = 1.0
    args.use_msg_norm = True
    args.learn_p = True
    args.learn_beta = True
    args.learn_msg_scale = True
    task = build_task(args)
    ret = task.train()
    assert 0 < ret["Acc"] < 1
Example #21
0
    def __init__(self, app: str, model: str, **kwargs):
        super(RecommendationPipepline, self).__init__(app,
                                                      model=model,
                                                      **kwargs)

        if "data" in kwargs:
            data = kwargs["data"]
            val_data = test_data = data[-100:, :]
            data = build_recommendation_data("custom", data, val_data,
                                             test_data)
            self.data_path = kwargs.get("data_path", "tmp_data.pt")
            self.batch_size = kwargs.get("batch_size", 128)
            torch.save(data, self.data_path)
            self.dataset = NodeDataset(path=self.data_path, scale_feat=False)
        elif "dataset" in kwargs:
            dataset = kwargs.pop("dataset")
            self.dataset = build_dataset_from_name(dataset)
        else:
            print("Please provide recommendation data!")
            exit(0)

        self.batch_size = kwargs.get("batch_size", 2048)
        self.n_items = self.dataset[0].n_params["n_items"]

        args = get_default_args(task="recommendation",
                                dataset="ali",
                                model=model,
                                **kwargs)
        args.model = args.model[0]

        task = build_task(args, dataset=self.dataset)
        task.train()

        self.model = task.model
        self.model.eval()

        self.user_emb, self.item_emb = self.model.generate()
Example #22
0
def test_stpgnn_infomax():
    args = get_strategies_for_pretrain_args()
    args.pretrain_task = "infomax"
    task = build_task(args)
    ret = task.train()
    assert 0 < ret["Acc"] <= 1
Example #23
0
def test_gcn_cora():
    args = get_gnn_link_prediction_args()
    print(args.evaluate_interval)
    task = build_task(args)
    ret = task.train()
    assert 0.5 <= ret["AUC"] <= 1.0
Example #24
0
from cogdl.utils import build_args_from_dict


def get_default_args():
    cuda_available = torch.cuda.is_available()
    default_dict = {
        'hidden_size': 16,
        'dropout': 0.5,
        'patience': 100,
        'max_epoch': 500,
        'cpu': not cuda_available,
        'lr': 0.01,
        'device_id': [0],
        'weight_decay': 5e-4
    }
    return build_args_from_dict(default_dict)


if __name__ == "__main__":
    args = get_default_args()
    args.task = 'node_classification'
    args.dataset = 'cora'
    args.model = 'gcn'
    dataset = build_dataset(args)
    args.num_features = dataset.num_features
    args.num_classes = dataset.num_classes
    args.num_layers = 2
    model = build_model(args)
    task = build_task(args, dataset=dataset, model=model)
    ret = task.train()
Example #25
0
from cogdl.tasks import build_task
from cogdl.options import get_default_args

args = get_default_args(task="node_classification",
                        dataset="cora",
                        model="gcn")
task = build_task(args)
ret = task.train()