GOOD.networks.models.MixupGCNs

GCN implementation of the Mixup algorithm from “Mixup for Node and Graph Classification” paper

Classes

MixUpGCNConv(in_channels, out_channels[, ...])

The graph convolutional operator from the "Mixup for Node and Graph Classification" paper and "Semi-supervised Classification with Graph Convolutional Networks" paper

MixupGCNFeatExtractor(config)

Mixup-GCN feature extractor using the MixUpGCNConv operator.

Mixup_GCN(config)

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: MessagePassing

The 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 1 representing edge weights via the optional edge_weight tensor.

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 j to target node i (default: 1.0)

Parameters
  • in_channels (int) – Size of each input sample, or -1 to 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 to True in 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 to propagate(). Furthermore, tensors passed to propagate() can be mapped to the respective nodes \(i\) and \(j\) by appending _i or _j to the variable name, .e.g. x_i and x_j.

message_and_aggregate(adj_t: SparseTensor, x: Tensor) Tensor[source]

Fuses computations of message() and aggregate() 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 a torch_sparse.SparseTensor.

class GOOD.networks.models.MixupGCNs.MixupGCNFeatExtractor(config: Union[CommonArgs, Munch])[source]

Bases: BasicEncoder, GNNBasic

Mixup-GCN feature extractor using the MixUpGCNConv operator.

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) –

    1. dictionary of OOD args (kwargs.ood_algorithm) (2) key word arguments for the use of arguments_read. Refer to arguments_read

Returns (Tensor):

node feature representations

class GOOD.networks.models.MixupGCNs.Mixup_GCN(config: Union[CommonArgs, Munch])[source]

Bases: GNNBasic

The 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