PerSourceUniform
- class dgl.dataloading.negative_sampler.PerSourceUniform(k)[source]
Bases:
_BaseNegativeSampler负采样器,根据均匀分布为每个源节点随机选择负目标节点。
对于每种类型的边
(u, v),类型为(srctype, etype, dsttype),DGL 会生成k对负边(u, v'),其中v'是从所有类型为dsttype的节点中均匀选择的。生成的边也将具有类型(srctype, etype, dsttype)。- Parameters:
k (int) – 每条边的负样本数量。
示例
>>> g = dgl.graph(([0, 1, 2], [1, 2, 3])) >>> neg_sampler = dgl.dataloading.negative_sampler.PerSourceUniform(2) >>> neg_sampler(g, torch.tensor([0, 1])) (tensor([0, 0, 1, 1]), tensor([1, 0, 2, 3]))