Stores how (hyper-)edges connect tuples of nodes from incident node sets.
tfgnn.HyperAdjacency(
data: Data, spec: 'GraphPieceSpecBase'
)
The incident node sets in the hyper-adjacency are referenced by a unique
integer identifier called the node set tag. (For a non-hyper graph, it is
conventional to use the integers tfgnn.SOURCE
and tfgnn.TARGET
.) This
allows the hyper-adjacency to connect nodes from the same or different node
sets. Each hyper-edge connects a fixed number of nodes, one node from each
incident node set. The adjacency information is stored as a mapping from the
node set tags to integer tensors containing indices of nodes in corresponding
node sets. Those tensors are indexed by edges. All index tensors have the same
type spec and shape of [*graph_shape, num_edges]
, where num_edges
is the
number of edges in the edge set (could be potentially ragged). The index
tensors are of tf.Tensor
type if num_edges
is not None
or
graph_shape.rank = 0
and of tf.RaggedTensor
type otherwise.
The HyperAdjacency is a composite tensor.
data
|
Nest of Field or subclasses of GraphPieceBase. |
spec
|
A subclass of GraphPieceSpecBase with a _data_spec that matches
data .
|
@classmethod
from_indices( indices: Indices, *_, validate: Optional[bool] = None ) -> 'HyperAdjacency'
Constructs a new instance from the indices
tensors.
# Single graph (rank is 0). Connects pairs of nodes (a[0], b[2]),
# (a[1], b[1]), (a[2], b[0]) from node sets a and b.
tfgnn.HyperAdjacency.from_indices({
tfgnn.SOURCE: ('a', [0, 1, 2]),
tfgnn.TARGET: ('b', [2, 1, 0])
})
# Single hypergraph (rank is 0). Connects triplets of nodes
# (a[0], b[2], c[1]), (a[1], b[1], c[0]) from the node sets a, b and c.
tfgnn.HyperAdjacency.from_indices({
0: ('a', [0, 1]),
1: ('b', [2, 1]),
2: ('c', [1, 0]),
})
# Batch of two graphs (rank is 1). Connects pairs of nodes in
# graph 0: (a[0], b[2]), (a[1], b[1]); graph 1: (a[2], b[0]).
tfgnn.HyperAdjacency.from_indices({
tfgnn.SOURCE: ('a', tf.ragged.constant([[0, 1], [2]])),
tfgnn.TARGET: ('b', tf.ragged.constant([[2, 1], [0]])),
})
Args | |
---|---|
indices
|
A mapping from node tags to 2-tuples of node set name and node
index tensor. The index tensors must have the same type spec and shape
of [*graph_shape, num_edges] , where num_edges is the number of edges
in each graph (could be ragged). The index tensors are of tf.Tensor
type if num_edges is not None or graph_shape.rank = 0 and of
tf.RaggedTensor type otherwise.
|
validate
|
If True , checks that node indices have the same type spec.
|
Returns | |
---|---|
A HyperAdjacency tensor with its shape and indices_dtype being
inferred from the passed indices values.
|
get_indices_dict() -> Dict[IncidentNodeTag, Tuple[NodeSetName, Field]]
Returns copy of indices as a dictionary.
node_set_name(
node_set_tag: IncidentNodeTag
) -> NodeSetName
Returns a node set name for the given node set tag.
set_shape(
new_shape: ShapeLike
) -> 'GraphPieceBase'
Deprecated. Use with_shape()
.
with_indices_dtype(
dtype: tf.dtypes.DType
) -> 'GraphPieceBase'
Returns a copy of this piece with the given indices dtype.
with_row_splits_dtype(
dtype: tf.dtypes.DType
) -> 'GraphPieceBase'
Returns a copy of this piece with the given row splits dtype.
with_shape(
new_shape: ShapeLike
) -> 'GraphPieceBase'
Enforce the common prefix shape on all the contained features.
__getitem__(
node_set_tag: IncidentNodeTag
) -> tfgnn.Field
Returns an index tensor for the given node set tag.