Edge Feature
gtrick.dgl.CommonNeighbors(adj, edge_attr=None, batch_size=64)
¶
Compute the common neighbors of two nodes in a graph.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
SparseTensor
|
Adjacency matrix. |
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.dgl.ResourceAllocation(adj, 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 |
---|---|---|---|
adj |
SparseTensor
|
Adjacency matrix. |
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.dgl.AdamicAdar(adj, 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 |
---|---|---|---|
adj |
SparseTensor
|
Adjacency matrix. |
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.dgl.AnchorDistance(g, num_samples, k, ka, max_spd=5)
¶
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 |
---|---|---|---|
g |
dgl.DGLGraph
|
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
|
__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. |