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

Method e2v_aggregation_of_group

easygraph/classes/hypergraph.py:1569–1636  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

1567 return X
1568
1569 def e2v_aggregation_of_group(
1570 self,
1571 group_name: str,
1572 X: torch.Tensor,
1573 aggr: str = "mean",
1574 e2v_weight: Optional[torch.Tensor] = None,
1575 drop_rate: float = 0.0,
1576 ):
1577 r"""Message aggregation step of ``hyperedges to vertices`` in specified hyperedge group.
1578
1579 Args:
1580 ``group_name`` (``str``): The specified hyperedge group.
1581 ``X`` (``torch.Tensor``): Hyperedge feature matrix. Size :math:`(|\mathcal{E}|, C)`.
1582 ``aggr`` (``str``): The aggregation method. Can be ``'mean'``, ``'sum'`` and ``'softmax_then_sum'``.
1583 ``e2v_weight`` (``torch.Tensor``, optional): The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults to ``None``.
1584 ``drop_rate`` (``float``): Dropout rate. Randomly dropout the connections in incidence matrix with probability ``drop_rate``. Default: ``0.0``.
1585 """
1586 assert (
1587 group_name in self.group_names
1588 ), f"The specified {group_name} is not in existing hyperedge groups."
1589 assert aggr in ["mean", "sum", "softmax_then_sum"]
1590 if self.device != X.device:
1591 self.to(X.device)
1592 if e2v_weight is None:
1593 if drop_rate > 0.0:
1594 P = sparse_dropout(self.H_of_group(group_name), drop_rate)
1595 else:
1596 P = self.H_of_group(group_name)
1597 if aggr == "mean":
1598 X = torch.sparse.mm(P, X)
1599 X = torch.sparse.mm(self.D_v_neg_1_of_group[group_name], X)
1600 elif aggr == "sum":
1601 X = torch.sparse.mm(P, X)
1602 elif aggr == "softmax_then_sum":
1603 P = torch.sparse.softmax(P, dim=1)
1604 X = torch.sparse.mm(P, X)
1605 else:
1606 raise ValueError(f"Unknown aggregation method: {aggr}")
1607 else:
1608 # init message path
1609 assert (
1610 e2v_weight.shape[0] == self.e2v_weight_of_group[group_name].shape[0]
1611 ), (
1612 "The size of e2v_weight must be equal to the size of"
1613 f" self.e2v_weight_of_group('{group_name}')."
1614 )
1615 P = torch.sparse_coo_tensor(
1616 self.H_of_group[group_name]._indices(),
1617 e2v_weight,
1618 self.H_of_group[group_name].shape,
1619 device=self.device,
1620 )
1621 if drop_rate > 0.0:
1622 P = sparse_dropout(P, drop_rate)
1623 # message passing
1624 if aggr == "mean":
1625 X = torch.sparse.mm(P, X)
1626 D_v_neg_1 = torch.sparse.sum(P, dim=1).to_dense().view(-1, 1)

Callers 1

e2v_of_groupMethod · 0.95

Calls 3

toMethod · 0.95
H_of_groupMethod · 0.95
sparse_dropoutFunction · 0.90

Tested by

no test coverage detected