from typing import Optional, Tuple import torch from torch import Tensor class…
- User
from typing import Optional, Tuple
import torch from torch import Tensor
class DenseMinCutPooling(torch.nn.Module): r"""The MinCut pooling operator from the "Spectral Clustering in Graph Neural Networks for Graph Pooling" https://arxiv.org/abs/1907.00481_ paper.
.. math:: \mathbf{X}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot \mathbf{X}
code\mathbf{A}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot \mathbf{A} \cdot \mathrm{softmax}(\mathbf{S})based on dense learned assignments :math:
\mathbf{S} \in \mathbb{R}^{B \times N \times C}. Returns the pooled node feature matrix, the coarsened and symmetrically normalized adjacency matrix and two auxiliary objectives: (1) The MinCut loss.. math:: \mathcal{L}_c = - \frac{\mathrm{Tr}(\mathbf{S}^{\top} \mathbf{A} \mathbf{S})} {\mathrm{Tr}(\mathbf{S}^{\top} \mathbf{D} \mathbf{S})}
where :math:
\mathbf{D}is the degree matrix, and (2) the orthogonality loss.. math:: \mathcal{L}_o = {\left| \frac{\mathbf{S}^{\top} \mathbf{S}} {{|\mathbf{S}^{\top} \mathbf{S}|}_F} -\frac{\mathbf{I}_C}{\sqrt{C}} \right|}_F.
Args: in_channels (int): Size of each input sample. out_channels (int): Number of output clusters. temp (float, optional): Temperature parameter for softmax function. (default: :obj:
1.0) mlp_hidden_channels (int, optional): Number of hidden channels in the MLP. If not specified, a linear layer is used. (default: :obj:None) """ def init(self, in_channels: int, out_channels: int, temp: float = 1.0, mlp_hidden_channels: int = 32): super().init()codeself.in_channels = in_channels self.out_channels = out_channels self.temp = temp self.lin = torch.nn.Sequential( torch.nn.Linear(in_channels, mlp_hidden_channels), torch.nn.ReLU(), torch.nn.Linear(mlp_hidden_channels, out_channels) )def forward( self, x: Tensor, edge_index: Tensor, mask: Optional[Tensor] = None, ) -> Tuple[Tensor, Tensor, Tensor, Tensor]: r""" Args: x (torch.Tensor): Node feature tensor :math:
\mathbf{X} \in \mathbb{R}^{B \times N \times F}, with batch-size :math:B, (maximum) number of nodes :math:Nfor each graph, and feature dimension :math:F. edge_index (torch.Tensor): Edge index tensor :math:. mask (torch.Tensor, optional): Mask matrix :math: indicating the valid nodes for each graph. (default: :obj:) - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.