MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / v2e_aggregation_of_group

Method v2e_aggregation_of_group

easygraph/classes/hypergraph.py:1348–1415  ·  view source on GitHub ↗

r"""Message aggregation step of ``vertices to hyperedges`` in specified hyperedge group. Args: ``group_name`` (``str``): The specified hyperedge group. ``X`` (``torch.Tensor``): Vertex feature matrix. Size :math:`(|\mathcal{V}|, C)`. ``aggr`` (``str``): T

(
        self,
        group_name: str,
        X: torch.Tensor,
        aggr: str = "mean",
        v2e_weight: Optional[torch.Tensor] = None,
        drop_rate: float = 0.0,
    )

Source from the content-addressed store, hash-verified

1346 return X
1347
1348 def v2e_aggregation_of_group(
1349 self,
1350 group_name: str,
1351 X: torch.Tensor,
1352 aggr: str = "mean",
1353 v2e_weight: Optional[torch.Tensor] = None,
1354 drop_rate: float = 0.0,
1355 ):
1356 r"""Message aggregation step of ``vertices to hyperedges`` in specified hyperedge group.
1357
1358 Args:
1359 ``group_name`` (``str``): The specified hyperedge group.
1360 ``X`` (``torch.Tensor``): Vertex feature matrix. Size :math:`(|\mathcal{V}|, C)`.
1361 ``aggr`` (``str``): The aggregation method. Can be ``'mean'``, ``'sum'`` and ``'softmax_then_sum'``.
1362 ``v2e_weight`` (``torch.Tensor``, optional): The weight vector attached to connections (vertices point to hyepredges). If not specified, the function will use the weights specified in hypergraph construction. Defaults to ``None``.
1363 ``drop_rate`` (``float``): Dropout rate. Randomly dropout the connections in incidence matrix with probability ``drop_rate``. Default: ``0.0``.
1364 """
1365 assert (
1366 group_name in self.group_names
1367 ), f"The specified {group_name} is not in existing hyperedge groups."
1368 assert aggr in ["mean", "sum", "softmax_then_sum"]
1369 if self.device != X.device:
1370 self.to(X.device)
1371 if v2e_weight is None:
1372 if drop_rate > 0.0:
1373 P = sparse_dropout(self.H_T_of_group(group_name), drop_rate)
1374 else:
1375 P = self.H_T_of_group(group_name)
1376 if aggr == "mean":
1377 X = torch.sparse.mm(P, X)
1378 X = torch.sparse.mm(self.D_e_neg_1_of_group(group_name), X)
1379 elif aggr == "sum":
1380 X = torch.sparse.mm(P, X)
1381 elif aggr == "softmax_then_sum":
1382 P = torch.sparse.softmax(P, dim=1)
1383 X = torch.sparse.mm(P, X)
1384 else:
1385 raise ValueError(f"Unknown aggregation method {aggr}.")
1386 else:
1387 # init message path
1388 assert (
1389 v2e_weight.shape[0] == self.v2e_weight_of_group(group_name).shape[0]
1390 ), (
1391 "The size of v2e_weight must be equal to the size of"
1392 f" self.v2e_weight_of_group('{group_name}')."
1393 )
1394 P = torch.sparse_coo_tensor(
1395 self.H_T_of_group(group_name)._indices(),
1396 v2e_weight,
1397 self.H_T_of_group(group_name).shape,
1398 device=self.device,
1399 )
1400 if drop_rate > 0.0:
1401 P = sparse_dropout(P, drop_rate)
1402 # message passing
1403 if aggr == "mean":
1404 X = torch.sparse.mm(P, X)
1405 D_e_neg_1 = torch.sparse.sum(P, dim=1).to_dense().view(-1, 1)

Callers 1

v2e_of_groupMethod · 0.95

Calls 5

toMethod · 0.95
H_T_of_groupMethod · 0.95
D_e_neg_1_of_groupMethod · 0.95
v2e_weight_of_groupMethod · 0.95
sparse_dropoutFunction · 0.90

Tested by

no test coverage detected