lift_order
Utility functions for lifting the order of a graph (line-graph transformation).
aggregate_edge_index
¶
Aggregate the possibly duplicated edges in the (higher-order) edge index.
Aggregate the possibly duplicated edges in the (higher-order) edge index and return a Data object
containing the (higher-order) edge index without duplicates and the node sequences.
This method can be seen as a higher-order generalization of the torch_geometric.utils.coalesce method.
It is used for example to generate the DeBruijn graph of a given order from the corresponding line graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
torch.Tensor
|
The edge index of a (higher-order) graph where each source and destination node corresponds to a node which is an edge in the (k-1)-th order graph. |
required |
node_sequence
|
torch.Tensor
|
The node sequences of first order nodes that each node in the edge index corresponds to,
of shape |
required |
edge_weight
|
torch.Tensor | None
|
The edge weights corresponding to the edge index. |
None
|
aggr
|
str
|
The aggregation method to use for the edge weights. One of "sum", "mean", "min", "max". |
'sum'
|
Returns:
| Type | Description |
|---|---|
torch_geometric.data.Data
|
A |
torch_geometric.data.Data
|
inverse index. For order 1, node indices are first-order node indices, so the result has one node per |
torch_geometric.data.Data
|
first-order node up to the largest one that occurs, including those not traversed by any edge. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pathpyG/algorithms/lift_order.py
aggregate_node_attributes
¶
Aggregate the node attributes of each pair of nodes in the edge index.
This method aggregates the node attributes of each pair of nodes in the edge index using the aggregation method specified. The method returns an attribute for each edge. The aggregation methods are:
- "src": Use the attribute of the source node for each edge.
- "dst": Use the attribute of the destination node for each edge.
- "max": Use the maximum of the attributes of the source and destination nodes for each edge.
- "mul": Use the product of the attributes of the source and destination nodes for each edge.
- "add": Use the sum of the attributes of the source and destination nodes for each edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
torch.Tensor
|
The edge index of the graph. |
required |
node_attribute
|
torch.Tensor
|
The node attribute tensor. |
required |
aggr
|
str
|
The aggregation method to use. One of "src", "dst", "max", "mul" or "add". |
'src'
|
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
The aggregated node attributes for each edge. |
Source code in src/pathpyG/algorithms/lift_order.py
lift_node_sequence
¶
Extend node sequences by one order along an edge index.
Each edge (u, v) of the (k-1)-th order graph becomes a node of the k-th order graph,
representing the path of u followed by the last first-order node of v.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
torch.Tensor
|
A sorted edge index tensor of shape (2, num_edges). |
required |
node_sequence
|
torch.Tensor
|
The node sequences of the (k-1)-th order graph, of shape (num_nodes, k-1). |
required |
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
The node sequences of the k-th order graph, of shape (num_edges, k). |
Source code in src/pathpyG/algorithms/lift_order.py
lift_order_edge_index
¶
Line graph transformation.
Do a line graph transformation on the edge index to lift the order of the graph by one. Assumes that the edge index is sorted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
torch.Tensor
|
A sorted edge index tensor of shape (2, num_edges). |
required |
num_nodes
|
int | None
|
The number of nodes in the graph. If not given, it will be inferred from the edge index (maximum node index + 1). |
None
|
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
The edge index of the lifted (line) graph. |
Source code in src/pathpyG/algorithms/lift_order.py
lift_order_edge_index_weighted
¶
Weighted line graph transformation.
Do a line graph transformation on the edge index to lift the order of the graph by one. Additionally, aggregate the edge weights of the (k-1)-th order graph to the (k)-th order graph. Assumes that the edge index is sorted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
torch.Tensor
|
A sorted edge index tensor of shape (2, num_edges). |
required |
edge_weight
|
torch.Tensor
|
The edge weights of the (k-1)th order graph. |
required |
num_nodes
|
int | None
|
The number of nodes in the graph. |
None
|
aggr
|
str
|
The aggregation method to use. One of "src", "dst", "max", "mul" or "add". |
'src'
|
Returns:
| Type | Description |
|---|---|
tuple[torch.Tensor, torch.Tensor]
|
A tuple containing the edge index of the lifted (line) graph and the aggregated edge weights. |
Source code in src/pathpyG/algorithms/lift_order.py
lift_order_step
¶
Lift an edge index together with its node sequences by one order.
Combines the line-graph transformation of the edge index with the corresponding
extension of the node sequences, so that the result again describes a graph whose
nodes are paths of first-order nodes. The result is not aggregated: duplicate
node sequences are left for aggregate_edge_index
(or [HigherOrderGraph.aggregate][pathpyG.HigherOrderGraph.aggregate]) to merge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
torch.Tensor
|
A sorted edge index tensor of shape (2, num_edges). |
required |
node_sequence
|
torch.Tensor
|
The node sequences of the (k-1)-th order graph. |
required |
edge_weight
|
torch.Tensor | None
|
The edge weights of the (k-1)-th order graph. If None, the lifted graph is returned without weights. |
None
|
aggr
|
str
|
The aggregation method for the edge weights. One of "src", "dst", "max",
"mul" or "add". Ignored if |
'src'
|
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
A tuple of the lifted edge index, the lifted node sequences and the aggregated |
torch.Tensor
|
edge weights (None if |