Beispiel #1
0
def get_context_pairs(graphs, num_time_steps):
    """ Load/generate context pairs for each snapshot through random walk sampling."""
    load_path = "data/{}/train_pairs_n2v_{}.pkl".format(FLAGS.dataset, str(num_time_steps - 2))
    try:
        context_pairs_train = dill.load(open(load_path, 'rb'))
        print("Loaded context pairs from pkl file directly")
    except (IOError, EOFError):
        print("Computing training pairs ...")
        context_pairs_train = []
        for i in range(0, num_time_steps):
            context_pairs_train.append(run_random_walks_n2v(graphs[i], graphs[i].nodes()))
        dill.dump(context_pairs_train, open(load_path, 'wb'))
        print ("Saved pairs")

    return context_pairs_train
Beispiel #2
0
def get_context_pairs(graphs, num_time_steps):
    """ Load/generate context pairs for each snapshot through random walk sampling."""
    load_path = "data/{}/train_pairs_n2v_{}.pkl".format(
        FLAGS.dataset, str(num_time_steps - 2))
    try:
        #        dill 可以用于保存对象等大多数Python的数据格式
        context_pairs_train = dill.load(open(load_path, 'rb'))
        print("Loaded context pairs from pkl file directly")
    except (IOError, EOFError):
        print("Computing training pairs ...")
        context_pairs_train = []
        #num_time_steps表示训练的静态快照图,
        #所以这里的context_pairs_train列表包含num_time_steps个数的字典。
        for i in range(0, num_time_steps):
            #run_random_walks_n2v()返回的是一个字典。
            context_pairs_train.append(
                run_random_walks_n2v(graphs[i], graphs[i].nodes()))
        #保存不同时刻图的随机游走的固定窗口的节点对。
        dill.dump(context_pairs_train, open(load_path, 'wb'))
        print("Saved pairs")

    return context_pairs_train
Beispiel #3
0
def get_context_pairs_incremental(graph):
    return run_random_walks_n2v(graph, graph.nodes())