-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhyperedge_aggregator.py
More file actions
25 lines (22 loc) · 911 Bytes
/
hyperedge_aggregator.py
File metadata and controls
25 lines (22 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import torch
from torch_geometric.utils import scatter
def compute_mean(x, edge_index):
row, col = edge_index
mean_features = scatter(x[row], col, dim=0, reduce='mean')
return mean_features
def compute_var(x, edge_index):
row, col = edge_index
mean_features = scatter(x[row], col, dim=0, reduce='mean')
mean_sq = scatter((x*x)[row], col, dim=0, reduce='mean')
var_features = mean_sq - mean_features * mean_features
return var_features
def compute_cov(x, edge_index):
row, col = edge_index
mean_features = scatter(x[row], col, dim=0, reduce='mean')
xxT = torch.einsum('bi,bj->bij', x, x)
xxT = xxT[row,...]
shapes = xxT.size()
xxT = xxT.reshape(-1, x.size(1) * x.size(1))
mean_xxT = scatter(xxT, col, dim=0, reduce='mean').reshape(-1, x.size(1), x.size(1))
cov = mean_xxT - torch.einsum('bi,bj->bij', mean_features, mean_features)
return cov