Sample neighboring edges of the given nodes and return the induced subgraph. For each node, a number of inbound (or outbound when ``edge_dir == 'out'``) edges will be randomly chosen. The graph returned will then contain all the nodes in the original graph, but only the sampled edges.
(
g,
nodes,
fanout,
edge_dir="in",
prob=None,
replace=False,
copy_ndata=True,
copy_edata=True,
_dist_training=False,
exclude_edges=None,
output_device=None,
)
| 220 | |
| 221 | |
| 222 | def sample_neighbors( |
| 223 | g, |
| 224 | nodes, |
| 225 | fanout, |
| 226 | edge_dir="in", |
| 227 | prob=None, |
| 228 | replace=False, |
| 229 | copy_ndata=True, |
| 230 | copy_edata=True, |
| 231 | _dist_training=False, |
| 232 | exclude_edges=None, |
| 233 | output_device=None, |
| 234 | ): |
| 235 | """Sample neighboring edges of the given nodes and return the induced subgraph. |
| 236 | |
| 237 | For each node, a number of inbound (or outbound when ``edge_dir == 'out'``) edges |
| 238 | will be randomly chosen. The graph returned will then contain all the nodes in the |
| 239 | original graph, but only the sampled edges. |
| 240 | |
| 241 | Node/edge features are not preserved. The original IDs of |
| 242 | the sampled edges are stored as the `dgl.EID` feature in the returned graph. |
| 243 | |
| 244 | GPU sampling is supported for this function. Refer to :ref:`guide-minibatch-gpu-sampling` |
| 245 | for more details. |
| 246 | |
| 247 | Parameters |
| 248 | ---------- |
| 249 | g : DGLGraph |
| 250 | The graph. Can be either on CPU or GPU. |
| 251 | nodes : tensor or dict |
| 252 | Node IDs to sample neighbors from. |
| 253 | |
| 254 | This argument can take a single ID tensor or a dictionary of node types and ID tensors. |
| 255 | If a single tensor is given, the graph must only have one type of nodes. |
| 256 | fanout : int or dict[etype, int] |
| 257 | The number of edges to be sampled for each node on each edge type. |
| 258 | |
| 259 | This argument can take a single int or a dictionary of edge types and ints. |
| 260 | If a single int is given, DGL will sample this number of edges for each node for |
| 261 | every edge type. |
| 262 | |
| 263 | If -1 is given for a single edge type, all the neighboring edges with that edge |
| 264 | type and non-zero probability will be selected. |
| 265 | edge_dir : str, optional |
| 266 | Determines whether to sample inbound or outbound edges. |
| 267 | |
| 268 | Can take either ``in`` for inbound edges or ``out`` for outbound edges. |
| 269 | prob : str, optional |
| 270 | Feature name used as the (unnormalized) probabilities associated with each |
| 271 | neighboring edge of a node. The feature must have only one element for each |
| 272 | edge. |
| 273 | |
| 274 | The features must be non-negative floats or boolean. Otherwise, the result |
| 275 | will be undefined. |
| 276 | exclude_edges: tensor or dict |
| 277 | Edge IDs to exclude during sampling neighbors for the seed nodes. |
| 278 | |
| 279 | This argument can take a single ID tensor or a dictionary of edge types and ID tensors. |
no test coverage detected