mindspore_gl.sampling

Sampling APIs for graph data.

mindspore_gl.sampling.k_hop_subgraph(node_idx, num_hops, adj_coo, node_count, relabel_nodes=False, flow='source_to_target')[source]

K-hop sampling on MindHomoGraph

Parameters
  • node_idx (int, list, tuple or numpy.ndarray) – sampling subgraph around ‘node_idx’.

  • num_hops (int) – sampling ‘num_hops’ hop subgraph.

  • adj_coo (numpy.ndarray) – input adj of graph.

  • node_count (int) – the number of nodes.

  • relabel_nodes (bool) – node indexes need relabel or not.

  • flow – the visit direction.

Returns

res(dict), has 4 keys ‘subset’, ‘adj_coo’, ‘inv’, ‘edge_mask’, where,

  • subset (numpy.ndarray) - nodes’ idx of sampled K-hop subgraph.

  • adj_coo (numpy.ndarray) - adj of sampled K-hop subgraph.

  • inv (list) - the mapping from node indices in node_idx to their new location.

  • edge_mask (numpy.ndarray) - the edge mask indicating which edges were preserved.