"docs/source/vscode:/vscode.git/clone" did not exist on "ec64581c962783bd0bbe953f5786d31709c5e401"
node2vec_impl.h 1.62 KB
Newer Older
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*!
 *  Copyright (c) 2021 by Contributors
 * \file graph/sampling/node2vec_impl.h
 * \brief DGL sampler - templated implementation definition of node2vec random
 * walks
 */

#ifndef DGL_GRAPH_SAMPLING_RANDOMWALKS_NODE2VEC_IMPL_H_
#define DGL_GRAPH_SAMPLING_RANDOMWALKS_NODE2VEC_IMPL_H_

#include <dgl/array.h>
#include <dgl/base_heterograph.h>

#include <functional>
#include <utility>
#include <vector>
#include <tuple>

namespace dgl {

using namespace dgl::runtime;
using namespace dgl::aten;

namespace sampling {

namespace impl {

/*!
 * \brief Node2vec random walk.
 * \param hg The heterograph.
 * \param seeds A 1D array of seed nodes, with the type the source type of the
 * first edge type in the metapath.
 * \param p Float, indicating likelihood of immediately revisiting a node in the walk.
 * \param q Float, control parameter to interpolate between breadth-first strategy and
 *        depth-first strategy.
 * \param walk_length Int, length of walk.
 * \param prob A vector of 1D float arrays, indicating the transition
 *        probability of each edge by edge type.  An empty float array assumes uniform
 *        transition.
 * \return A 2D array of shape (len(seeds), len(walk_length) + 1)
 *         with node IDs.  The paths that terminated early are padded with -1.
 */
43
template <DGLDeviceType XPU, typename IdxType>
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
44
45
46
47
48
49
50
51
52
53
54
55
std::pair<IdArray, IdArray> Node2vec(
    const HeteroGraphPtr hg, const IdArray seeds, const double p,
    const double q, const int64_t walk_length,
    const FloatArray &prob);

};  // namespace impl

};  // namespace sampling

};  // namespace dgl

#endif  // DGL_GRAPH_SAMPLING_RANDOMWALKS_NODE2VEC_IMPL_H_