dgl.rand_bipartite
- dgl.rand_bipartite(utype, etype, vtype, num_src_nodes, num_dst_nodes, num_edges, idtype=torch.int64, device=device(type='cpu'))[source]
生成一个随机的单向二分图并返回。
It uniformly chooses
num_edges
from all possible node pairs and form a graph. The random choice is without replacement, which means there will be no multi-edge in the resulting graph.To control the randomness, set the random seed via
dgl.seed()
.- Parameters:
utype (str, optional) – The name of the source node type.
etype (str, optional) – The name of the edge type.
vtype (str, optional) – The name of the destination node type.
num_src_nodes (int) – 源节点的数量。
num_dst_nodes (int) – 目标节点的数量。
num_edges (int) – The number of edges
idtype (int32, int64, optional) – The data type for storing the structure-related graph information such as node and edge IDs. It should be a framework-specific data type object (e.g., torch.int32). By default, DGL uses int64.
device (Device context, optional) – The device of the resulting graph. It should be a framework-specific device object (e.g., torch.device). By default, DGL stores the graph on CPU.
- Returns:
生成的随机二分图。
- Return type:
另请参阅
示例
>>> import dgl >>> dgl.rand_bipartite('user', 'buys', 'game', 50, 100, 10) Graph(num_nodes={'game': 100, 'user': 50}, num_edges={('user', 'buys', 'game'): 10}, metagraph=[('user', 'game', 'buys')])