MCPcopy
hub / github.com/dmlc/dgl / __call__

Method __call__

python/dgl/sampling/pinsage.py:119–163  ·  view source on GitHub ↗

Parameters ---------- seed_nodes : Tensor A tensor of given node IDs of node type ``ntype`` to generate neighbors from. The node type ``ntype`` is the beginning and ending node type of the given metapath. It must be on the same device as

(self, seed_nodes)

Source from the content-addressed store, hash-verified

117
118 # pylint: disable=no-member
119 def __call__(self, seed_nodes):
120 """
121 Parameters
122 ----------
123 seed_nodes : Tensor
124 A tensor of given node IDs of node type ``ntype`` to generate neighbors from. The
125 node type ``ntype`` is the beginning and ending node type of the given metapath.
126
127 It must be on the same device as the graph and have the same dtype
128 as the ID type of the graph.
129
130 Returns
131 -------
132 g : DGLGraph
133 A homogeneous graph constructed by selecting neighbors for each given node according
134 to the algorithm above.
135 """
136 seed_nodes = utils.prepare_tensor(self.G, seed_nodes, "seed_nodes")
137 self.restart_prob = F.copy_to(self.restart_prob, F.context(seed_nodes))
138
139 seed_nodes = F.repeat(seed_nodes, self.num_random_walks, 0)
140 paths, _ = random_walk(
141 self.G,
142 seed_nodes,
143 metapath=self.full_metapath,
144 restart_prob=self.restart_prob,
145 )
146 src = F.reshape(
147 paths[:, self.metapath_hops :: self.metapath_hops], (-1,)
148 )
149 dst = F.repeat(paths[:, 0], self.num_traversals, 0)
150
151 src, dst, counts = _select_pinsage_neighbors(
152 src,
153 dst,
154 (self.num_random_walks * self.num_traversals),
155 self.num_neighbors,
156 )
157 neighbor_graph = convert.heterograph(
158 {(self.ntype, "_E", self.ntype): (src, dst)},
159 {self.ntype: self.G.num_nodes(self.ntype)},
160 )
161 neighbor_graph.edata[self.weight_column] = counts
162
163 return neighbor_graph
164
165
166class PinSAGESampler(RandomWalkNeighborSampler):

Callers

nothing calls this directly

Calls 5

random_walkFunction · 0.85
contextMethod · 0.80
copy_toMethod · 0.45
num_nodesMethod · 0.45

Tested by

no test coverage detected