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 and return a graph 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. |
required |
edge_weight
|
torch.Tensor | None
|
The edge weights corresponding to the edge index. |
None
|
Returns:
Type | Description |
---|---|
pathpyG.core.graph.Graph
|
A graph object containing the aggregated edge index, the node sequences, the edge weights and the inverse index. |
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_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
|
The number of nodes in the graph. |
required |
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
|
The number of nodes in the graph. |
required |
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. |