コード例 #1
0
    args.lr = eval(args.lr)

    args.path = './data/' + args.dataset + '/'
    args.user_dataset = args.path + 'userRating'
    args.group_dataset = args.path + 'groupRating'
    args.user_in_group_path = "./data/" + args.dataset + "/groupMember.txt"

    print('args', args)
    # initial helper
    helper = Helper()

    # get the dict of users in group
    g_m_d = helper.gen_group_member_dict(args.user_in_group_path)

    # initial dataSet class
    dataset = GDataset(args.user_dataset, args.group_dataset,
                       args.num_negatives, g_m_d)

    # get group number
    num_group = max(g_m_d.keys()) + 1
    num_users, num_items = dataset.num_users, dataset.num_items
    # print('num_users',num_users)
    # build AGREE model
    agree = AGREE(num_users, num_items, num_group, args.embedding_size, g_m_d,
                  args.drop_ratio).to(device)
    # config information
    print("AGREE at embedding size %d, run Iteration:%d" %
          (args.embedding_size, args.epoch))
    history = []
    tops = [5, 10, 15, 20]
    for epoch in range(args.epoch):
        # training
コード例 #2
0
    hr, ndcg = np.array(hits).mean(), np.array(ndcgs).mean()
    return hr, ndcg


if __name__ == '__main__':
    # initial parameter class
    config = Config()

    # initial helper
    helper = Helper()

    # get the dict of users in group
    g_m_d = helper.gen_group_member_dict(config.user_in_group_path)

    # initial dataSet class
    dataset = GDataset(config.user_dataset, config.group_dataset,
                       config.num_negatives)

    # get group number~
    num_group = len(g_m_d)
    num_users, num_items = dataset.num_users, dataset.num_items

    # build AGREE model
    agree = AGREE(num_users, num_items, num_group, config.embedding_size,
                  g_m_d, config.drop_ratio)

    # config information
    print("AGREE at embedding size %d, run Iteration:%d, NDCG and HR at %d" %
          (config.embedding_size, config.epoch, config.topK))
    # train the model
    for epoch in range(config.epoch):
        agree.train()
コード例 #3
0
ファイル: main.py プロジェクト: MinkOrange/MGGCF
    model.eval()
    (hits, ndcgs) = helper.evaluate_model(model, testRatings, testNegatives, K, type_m)
    hr, ndcg = np.array(hits).mean(), np.array(ndcgs).mean()
    return hr, ndcg


if __name__ == '__main__':
    # initial parameter class
    config = Config()

    # initial helper
    helper = Helper()


    # initial dataSet class
    dataset = GDataset(config.user_dataset, config.group_dataset,config.num_negatives)

    # get group number
    num_users, num_items, num_groups = dataset.num_users, dataset.num_items, dataset.num_groups

    # build NCF model
    ncf = NCF(num_users, num_items, num_groups, config.factor_num, config.num_layers , config.drop_ratio)

    # config information
    print("NCF at embedding size %d, run Iteration:%d, NDCG and HR at %d" %(config.factor_num, config.epoch, config.topK))
    # train the model
    for epoch in range(config.epoch):
        ncf.train()
        # 开始训练时间
        t1 = time()
        training(ncf, dataset.get_user_dataloader(config.batch_size), epoch, config, 'user')