NodeFlow – Graph sampled from a large graph

class dgl.NodeFlow(parent, nfobj)[source]

The NodeFlow class stores the sampling results of Neighbor sampling and Layer-wise sampling.

These sampling algorithms generate graphs with multiple layers. The edges connect the nodes between two layers while there don’t exist edges between the nodes in the same layer.

We store multiple layers of the sampling results in a single graph. We store extra information, such as the node and edge mapping from the NodeFlow graph to the parent graph.

DO NOT create NodeFlow object directly. Use sampling method to generate NodeFlow instead.

Parameters:
  • parent (DGLGraph) – The parent graph.
  • nfobj (NodeFlowObject) – The nodeflow object

Querying graph structure

NodeFlow.num_layers Get the number of layers.
NodeFlow.num_blocks Get the number of blocks.
NodeFlow.layer_size(layer_id) Return the number of nodes in a specified layer.
NodeFlow.block_size(block_id) Return the number of edges in a specified block.
NodeFlow.layer_in_degree(layer_id) Return the in-degree of the nodes in the specified layer.
NodeFlow.layer_out_degree(layer_id) Return the out-degree of the nodes in the specified layer.
NodeFlow.layer_nid(layer_id) Get the node Ids in the specified layer.
NodeFlow.layer_parent_nid(layer_id) Get the node Ids of the parent graph in the specified layer
NodeFlow.block_eid(block_id) Get the edge Ids in the specified block.
NodeFlow.block_parent_eid(block_id) Get the edge Ids of the parent graph in the specified block.
NodeFlow.block_edges(block_id[, remap_local]) Return the edges in a block.

Converting to other format

NodeFlow.block_adjacency_matrix(block_id, ctx) Return the adjacency matrix representation for a specific block in a NodeFlow.
NodeFlow.block_incidence_matrix(block_id, …) Return the incidence matrix representation of the block.

Using Node/edge features

NodeFlow.layers Return a LayerView of this NodeFlow.
NodeFlow.blocks Return a BlockView of this NodeFlow.
NodeFlow.set_n_initializer(initializer[, …]) Set the initializer for empty node features.
NodeFlow.set_e_initializer(initializer[, …]) Set the initializer for empty edge features.
NodeFlow.node_attr_schemes(layer_id) Return the node feature schemes.
NodeFlow.edge_attr_schemes(block_id) Return the edge feature schemes.

Mapping between NodeFlow and parent graph

NodeFlow.map_to_parent_nid(nid) This maps the child node Ids to the parent Ids.
NodeFlow.map_to_parent_eid(eid) This maps the child edge Ids to the parent Ids.
NodeFlow.map_from_parent_nid(layer_id, …) Map parent node Ids to NodeFlow node Ids in a certain layer.

Synchronize features between NodeFlow and parent graph

NodeFlow.copy_from_parent([…]) Copy node/edge features from the parent graph.
NodeFlow.copy_to_parent([node_embed_names, …]) Copy node/edge embeddings to the parent graph.

Computing with NodeFlow

NodeFlow.register_message_func(func[, block_id]) Register global message function for a block.
NodeFlow.register_reduce_func(func[, block_id]) Register global message reduce function for a block.
NodeFlow.register_apply_node_func(func[, …]) Register global node apply function for a block.
NodeFlow.register_apply_edge_func(func[, …]) Register global edge apply function for a block.
NodeFlow.apply_layer(layer_id[, func, v, …]) Apply node update function on the node embeddings in the specified layer.
NodeFlow.apply_block(block_id[, func, …]) Apply edge update function on the edge embeddings in the specified layer.
NodeFlow.block_compute(block_id[, …]) Perform the computation on the specified block.
NodeFlow.prop_flow([message_funcs, …]) Perform the computation on flows.