GOOD.networks.models.MixupGCNs
GCN implementation of the Mixup algorithm from “Mixup for Node and Graph Classification” paper
Classes
|
The graph convolutional operator from the "Mixup for Node and Graph Classification" paper and "Semi-supervised Classification with Graph Convolutional Networks" paper |
|
Mixup-GCN feature extractor using the |
|
The Graph Neural Network modified from the "Mixup for Node and Graph Classification" paper and "Semi-supervised Classification with Graph Convolutional Networks" paper. |
- class GOOD.networks.models.MixupGCNs.MixUpGCNConv(in_channels: int, out_channels: int, improved: bool = False, cached: bool = False, add_self_loops: bool = True, normalize: bool = True, bias: bool = True, **kwargs)[source]
Bases:
MessagePassingThe graph convolutional operator from the “Mixup for Node and Graph Classification” paper and “Semi-supervised Classification with Graph Convolutional Networks” paper
\[\mathbf{X}^{\prime} = \mathbf{\hat{D}}^{-1/2} \mathbf{\hat{A}} \mathbf{\hat{D}}^{-1/2} \mathbf{X} \mathbf{\Theta},\]where \(\mathbf{\hat{A}} = \mathbf{A} + \mathbf{I}\) denotes the adjacency matrix with inserted self-loops and \(\hat{D}_{ii} = \sum_{j=0} \hat{A}_{ij}\) its diagonal degree matrix. The adjacency matrix can include other values than
1representing edge weights via the optionaledge_weighttensor.Its node-wise formulation is given by:
\[\mathbf{x}^{\prime}_i = \mathbf{\Theta}^{\top} \sum_{j \in \mathcal{N}(v) \cup \{ i \}} \frac{e_{j,i}}{\sqrt{\hat{d}_j \hat{d}_i}} \mathbf{x}_j\]with \(\hat{d}_i = 1 + \sum_{j \in \mathcal{N}(i)} e_{j,i}\), where \(e_{j,i}\) denotes the edge weight from source node
jto target nodei(default:1.0)- Parameters
in_channels (int) – Size of each input sample, or
-1to derive the size from the first input(s) to the forward method.out_channels (int) – Size of each output sample.
improved (bool, optional) – If set to
True, the layer computes \(\mathbf{\hat{A}}\) as \(\mathbf{A} + 2\mathbf{I}\). (default:False)cached (bool, optional) – If set to
True, the layer will cache the computation of \(\mathbf{\hat{D}}^{-1/2} \mathbf{\hat{A}} \mathbf{\hat{D}}^{-1/2}\) on first execution, and will use the cached version for further executions. This parameter should only be set toTruein transductive learning scenarios. (default:False)add_self_loops (bool, optional) – If set to
False, will not add self-loops to the input graph. (default:True)normalize (bool, optional) – Whether to add self-loops and compute symmetric normalization coefficients on the fly. (default:
True)bias (bool, optional) – If set to
False, the layer will not learn an additive bias. (default:True)**kwargs (optional) – Additional arguments of
torch_geometric.nn.conv.MessagePassing.
- Shapes:
input: node features \((|\mathcal{V}|, F_{in})\), edge indices \((2, |\mathcal{E}|)\), edge weights \((|\mathcal{E}|)\) (optional)
output: node features \((|\mathcal{V}|, F_{out})\)
- message(x_j: Tensor, edge_weight: Optional[Tensor]) Tensor[source]
Constructs messages from node \(j\) to node \(i\) in analogy to \(\phi_{\mathbf{\Theta}}\) for each edge in
edge_index. This function can take any argument as input which was initially passed topropagate(). Furthermore, tensors passed topropagate()can be mapped to the respective nodes \(i\) and \(j\) by appending_ior_jto the variable name, .e.g.x_iandx_j.
- message_and_aggregate(adj_t: SparseTensor, x: Tensor) Tensor[source]
Fuses computations of
message()andaggregate()into a single function. If applicable, this saves both time and memory since messages do not explicitly need to be materialized. This function will only gets called in case it is implemented and propagation takes place based on atorch_sparse.SparseTensor.
- class GOOD.networks.models.MixupGCNs.MixupGCNFeatExtractor(config: Union[CommonArgs, Munch])[source]
Bases:
BasicEncoder,GNNBasicMixup-GCN feature extractor using the
MixUpGCNConvoperator.- Parameters
config (Union[CommonArgs, Munch]) – munchified dictionary of args (
config.model.dim_hidden,config.model.model_layer,config.dataset.dim_node)
- forward(*args, **kwargs)[source]
The Mixup-GCN model implementation.
- Parameters
*args (list) – argument list for the use of arguments_read. Refer to
arguments_read**kwargs (dict) –
dictionary of OOD args (
kwargs.ood_algorithm) (2) key word arguments for the use of arguments_read. Refer toarguments_read
- Returns (Tensor):
node feature representations
- class GOOD.networks.models.MixupGCNs.Mixup_GCN(config: Union[CommonArgs, Munch])[source]
Bases:
GNNBasicThe Graph Neural Network modified from the “Mixup for Node and Graph Classification” paper and “Semi-supervised Classification with Graph Convolutional Networks” paper.
- Parameters
config (Union[CommonArgs, Munch]) – munchified dictionary of args (
config.model.dim_hidden,config.model.model_layer,config.dataset.dim_node,config.dataset.num_classes)
- forward(*args, **kwargs) Tensor[source]
The Mixup-GCN model implementation.
- Parameters
*args (list) – argument list for the use of arguments_read. Refer to
arguments_read**kwargs (dict) – key word arguments for the use of arguments_read. Refer to
arguments_read
- Returns (Tensor):
label predictions