Edge Feature
gtrick.pyg.CommonNeighbors(edge_index, edge_attr=None, batch_size=64)
¶
Bases: object
Compute the common neighbors of two nodes in a graph.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_index |
torch.LongTensor
|
Graph connectivity. |
required |
edge_attr |
torch.Tensor
|
Edge feature. |
None
|
batch_size |
int
|
The batch size to compute common neighbors. |
64
|
__call__(edges)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges |
torch.Tensor
|
The edges with the shape (num_edges, 2). |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
The calculated common neighbors feature. |
gtrick.pyg.ResourceAllocation(edge_index, edge_attr=None, batch_size=64)
¶
Bases: object
Compute the resource allocation of two nodes in a graph.
Resource allocation of \(u\) and \(v\) is defined as
where \(\Gamma(u)\) denotes the set of neighbors of \(u\).
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_index |
torch.LongTensor
|
Graph connectivity. |
required |
edge_attr |
torch.Tensor
|
Edge feature. |
None
|
batch_size |
int
|
The batch size to compute common neighbors. |
64
|
__call__(edges)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges |
torch.Tensor
|
The edges with the shape (num_edges, 2). |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
The calculated resource allocation feature. |
gtrick.pyg.AdamicAdar(edge_index, edge_attr=None, batch_size=64)
¶
Bases: object
Computes the adamic adar of two nodes in a graph.
Adamic-Adar index of \(u\) and \(v\) is defined as
where \(\Gamma(u)\) denotes the set of neighbors of \(u\). This index leads to zero-division for nodes only connected via self-loops. It is intended to be used when no self-loops are present.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_index |
torch.LongTensor
|
Graph connectivity. |
required |
edge_attr |
torch.Tensor
|
Edge feature. |
None
|
batch_size |
int
|
The batch size to compute common neighbors. |
64
|
__call__(edges=None)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges |
torch.Tensor
|
The edges with the shape (num_edges, 2). |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
The calculated adamic adar feature. |
gtrick.pyg.AnchorDistance(data, num_samples, k, ka, max_spd=5, to_undirected=True)
¶
Bases: object
Computes the anchor distance of two nodes in a graph.
The anchor distance randomly selects \(k_a\) nodes from \(V\) to be anchor nodes and then calculates the shortest path starting from these anchor nodes to any other nodes. After that, the distance between \(u\) and \(v\) can be estimated by:
To reduce the randomness, it uses \(k\) anchor sets to generate multiple distance features.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
torch_geometric.data.Data
|
Graph data. |
required |
num_samples |
int
|
The number of times to sample anchor sets. |
required |
k |
int
|
The size of sampled anchor sets. |
required |
ka |
int
|
The number of anchor nodes. |
required |
max_spd |
int
|
The max shortest distance. |
5
|
to_undirected |
bool
|
Converts the graph to an undirected graph. |
True
|
__call__(edges)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges |
torch.Tensor
|
The edges with the shape (num_edges, 2). |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
The calculated anchor distance feature. |