dgl.sampling

dgl.sampling 包包含用于通过随机游走、邻居采样等方式从图进行采样的算子和工具。它们通常与 dgl.dataloading 包中的 DataLoader 一起使用。用户指南 第 6 章:大型图上的随机训练 对不同组件如何协同工作进行了全面的解释。

随机游走

random_walk(g, nodes, *[, metapath, length, ...])

根据给定的元路径,从起始节点数组生成随机游走轨迹。

node2vec_random_walk(g, nodes, p, q, walk_length)

根据 node2vec 模型,从起始节点数组生成随机游走轨迹。

pack_traces(traces, types)

random_walk() 返回的填充轨迹打包成一个连接数组。

邻居采样

sample_neighbors(g, nodes, fanout[, ...])

对给定节点的邻边进行采样并返回诱导子图。

sample_labors(g, nodes, fanout[, edge_dir, ...])

一种采样器,通过劳动采样为多层 GNN 构建节点表示的计算依赖,该采样器来自 NeurIPS 2023 的论文 Layer-Neighbor Sampling -- Defusing Neighborhood Explosion in GNNs

sample_neighbors_biased(g, nodes, fanout, bias)

对给定节点的邻边进行采样并返回诱导子图,其中每个邻居被选中的概率由其标签决定。

select_topk(g, k, weight[, nodes, edge_dir, ...])

选择给定节点的 k-大(或 k-小)权重的邻边并返回诱导子图。

PinSAGESampler(G, ntype, other_type, ...[, ...])

PinSAGE 式邻居采样器。

负采样

global_uniform_negative_sampling(g, num_samples)

执行负采样,生成源-目标对,使给定类型的边不存在。