Ejemplo n.º 1
0
def exec_struc2vec(args):
    '''
	Pipeline for representational learning for all nodes in a graph.
	'''
    if (args.OPT3):
        until_layer = args.until_layer
    else:
        until_layer = None

    G = read_graph()
    G = struc2vec.Graph(G, args.directed, args.workers, untilLayer=until_layer)

    if (args.OPT1):
        G.preprocess_neighbors_with_bfs_compact()
    else:
        G.preprocess_neighbors_with_bfs()

    if (args.OPT2):
        G.create_vectors()
        G.calc_distances(compactDegree=args.OPT1)
    else:
        G.calc_distances_all_vertices(compactDegree=args.OPT1)

    G.create_distances_network()
    G.preprocess_parameters_random_walk()

    G.simulate_walks(args.num_walks, args.walk_length)

    return G
Ejemplo n.º 2
0
    def struc2vec(self):
        if self.nodeGraph == '':
            return
        beginTime = time.time()
        print('1: struc2vec Begin')
        strucGraph = graph.from_networkx(self.nodeGraph)
        strucGraph = struc2vec.Graph(strucGraph,
                                     'undirected',
                                     4,
                                     untilLayer=None)
        if True:
            strucGraph.preprocess_neighbors_with_bfs_compact()
        else:
            strucGraph.preprocess_neighbors_with_bfs()
        if True:
            strucGraph.create_vectors()
            strucGraph.calc_distances(compactDegree=True)
        else:
            strucGraph.calc_distances_all_vertices(compactDegree=True)
        strucGraph.create_distances_network()
        strucGraph.preprocess_parameters_random_walk()
        strucGraph.simulate_walks(10, 80)

        walks = LineSentence('random_walks.txt')
        self.model = Word2Vec(walks,
                              size=self.D,
                              window=10,
                              min_count=0,
                              hs=1,
                              sg=1,
                              workers=4,
                              iter=5)
        print('Time of Struc2Vec', time.time() - beginTime)
Ejemplo n.º 3
0
def exec_struc2vec(input_file):
    '''
	Pipeline for representational learning for all nodes in a graph.
	'''

    until_layer = 6

    G = read_graph(input_file)
    G = struc2vec.Graph(G, 'undirected', workers=4, untilLayer=until_layer)

    G.preprocess_neighbors_with_bfs_compact()

    G.create_vectors()
    G.calc_distances(compactDegree=True)

    G.create_distances_network()
    G.preprocess_parameters_random_walk()

    G.simulate_walks(10, 80)

    return G
Ejemplo n.º 4
0
def exec_struc2vec(args):
    '''
	Pipeline for representational learning for all nodes in a graph.
	'''

    #K = args.num_walks
    #S = args.walk_length

    K = 10
    S = 5

    G = read_graph()
    G = struc2vec.Graph(G, args.directed, args.workers, K, S)

    G.preprocess_neighbors_with_rw()

    G.create_vectors()
    G.calc_distances()

    G.create_distances_network()

    walks = G.simulate_walks(args.num_walks, args.walk_length)

    return walks