tf_geometric¶
Graph (Data Structure for a Single Graph)¶

class
tf_geometric.
Graph
(x, edge_index, y=None, edge_weight=None)¶ 
__init__
(x, edge_index, y=None, edge_weight=None)¶  Parameters
x – Tensor/NDArray, shape: [num_nodes, num_features], node features
edge_index – Tensor/NDArray, shape: [2, num_edges], edge information. Each column of edge_index (u, v) represents an directed edge from u to v. Note that it does not cover the edge from v to u. You should provide (v, u) to cover it. This is not convenient for users. Thus, we allow users to provide edge_index in undirected form and convert it later. That is, we can only provide (u, v) and convert it to (u, v) and (v, u) with convert_edge_to_directed method.
y – Tensor/NDArray/None, any shape, graph label. If you want to use this object to construct a BatchGraph object, y cannot be a scalar Tensor.
edge_weight – Tensor/NDArray/None, shape: [num_edges]

convert_data_to_tensor
(inplace=False)¶ Convert all graph data into Tensors. All corresponding properties will be replaces by their Tensor versions.
 Returns
The Graph object itself.

convert_edge_to_directed
(merge_mode='sum')¶ Each column of edge_index (u, v) represents an directed edge from u to v. Note that it does not cover the edge from v to u. You should provide (v, u) to cover it. This is not convenient for users. Thus, we allow users to provide edge_index in undirected form and convert it later. That is, we can only provide (u, v) and convert it to (u, v) and (v, u) with convert_edge_to_directed method.
Deprecated since version 0.0.84: Use
to_directed(inplace=True)
instead. Returns

property
num_edges
¶ Number of edges
 Returns
Number of edges

property
num_features
¶ Number of node features
 Returns
Number of node features

property
num_nodes
¶ Number of nodes
 Returns
Number of nodes

sample_new_graph_by_node_index
(sampled_node_index)¶  Parameters
sampled_node_index – Tensor/NDArray, shape: [num_sampled_nodes]
 Returns
A new cloned graph where nodes that are not in sampled_node_index are removed, as well as the associated information, such as edges.

tensor_spec_edge_weight
= TensorSpec(shape=(None,), dtype=tf.float32, name=None)¶ A Graph object wrappers all the data of a graph, including node features, edge info (index and weight) and graph label

to_directed
(merge_mode='sum', inplace=False)¶ Each column of edge_index (u, v) represents an directed edge from u to v. Note that it does not cover the edge from v to u. You should provide (v, u) to cover it. This is not convenient for users. Thus, we allow users to provide edge_index in undirected form and convert it later. That is, we can simply provide (u, v) and convert it to (u, v) and (v, u) with convert_edge_to_directed method.
 Returns
If inplace is False, return a new graph with directed edges. Else, return the current graph with directed edges.

BatchGraph (Data Structure for a Batch of Graphs)¶

class
tf_geometric.
BatchGraph
(x, edge_index, node_graph_index, edge_graph_index, y=None, edge_weight=None, graphs=None)¶ Batch graph wrap a batch of graphs into a single graph, where each nodes has an unique index and a graph index. The node_graph_index is the index of the corresponding graph for each node in the batch. The edge_graph_index is the index of the corresponding edge for each node in the batch.

__init__
(x, edge_index, node_graph_index, edge_graph_index, y=None, edge_weight=None, graphs=None)¶  Parameters
x – Tensor/NDArray, shape: [num_nodes, num_features], node features
edge_index – Tensor/NDArray, shape: [2, num_edges], edge information. Each column of edge_index (u, v) represents an directed edge from u to v. Note that it does not cover the edge from v to u. You should provide (v, u) to cover it.
node_graph_index – Tensor/NDArray, shape: [num_nodes], graph index for each node
edge_graph_index – Tensor/NDArray/None, shape: [num_edges], graph index for each edge
y – Tensor/NDArray/None, any shape, graph label. If you want to use this object to construct a BatchGraph object, y cannot be a scalar Tensor.
edge_weight – Tensor/NDArray/None, shape: [num_edges]
graphs – list[Graph], original graphs

convert_data_to_tensor
(inplace=False)¶ Convert all graph data into Tensors. All corresponding properties will be replaces by their Tensor versions.
 Returns
The Graph object itself.

convert_edge_to_directed
(merge_mode='sum')¶ Each column of edge_index (u, v) represents an directed edge from u to v. Note that it does not cover the edge from v to u. You should provide (v, u) to cover it. This is not convenient for users. Thus, we allow users to provide edge_index in undirected form and convert it later. That is, we can only provide (u, v) and convert it to (u, v) and (v, u) with convert_edge_to_directed method.
Deprecated since version 0.0.84: Use
to_directed(inplace=True)
instead. Returns

to_directed
(merge_mode='sum', inplace=False)¶ Each column of edge_index (u, v) represents an directed edge from u to v. Note that it does not cover the edge from v to u. You should provide (v, u) to cover it. This is not convenient for users. Thus, we allow users to provide edge_index in undirected form and convert it later. That is, we can simply provide (u, v) and convert it to (u, v) and (v, u) with convert_edge_to_directed method.
 Returns
If inplace is False, return a new graph with directed edges. Else, return the current graph with directed edges.
