GOOD.networks.models.GCNs

The Graph Neural Network from the “Semi-supervised Classification with Graph Convolutional Networks” paper.

Classes

GCN(config)

The Graph Neural Network from the "Semi-supervised Classification with Graph Convolutional Networks" paper.

GCNConv(*args, **kwargs)

The graph convolutional operator from the `"Semi-supervised

GCNEncoder(config)

The GCN encoder using the GCNConv operator for message passing.

GCNFeatExtractor(config)

GCN feature extractor using the GCNEncoder .

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

Bases: GNNBasic

The Graph Neural Network from the “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 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

class GOOD.networks.models.GCNs.GCNConv(*args, **kwargs)[source]

Bases: GCNConv

The graph convolutional operator from the `”Semi-supervised

Classification with Graph Convolutional Networks” <https://arxiv.org/abs/1609.02907>`_ paper

Parameters
  • *args (list) – argument list for the use of arguments_read.

  • **kwargs (dict) – Additional key word arguments for the use of arguments_read.

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})\)

forward(x: Tensor, edge_index: Union[Tensor, SparseTensor], edge_weight: Optional[Tensor] = None) Tensor[source]

The GCN graph convolutional operator.

Parameters
  • x (Tensor) – node features

  • edge_index (Tensor) – edge indices

  • edge_weight (Tensor) – edge weights

Returns (Tensor):

node feature representations

propagate(edge_index: Union[Tensor, SparseTensor], size: Optional[Tuple[int, int]] = None, **kwargs)[source]

The initial call to start propagating messages.

Parameters
  • edge_index (Tensor or SparseTensor) – A torch.LongTensor or a torch_sparse.SparseTensor that defines the underlying graph connectivity/message passing flow. edge_index holds the indices of a general (sparse) assignment matrix of shape [N, M]. If edge_index is of type torch.LongTensor, its shape must be defined as [2, num_messages], where messages from nodes in edge_index[0] are sent to nodes in edge_index[1] (in case flow="source_to_target"). If edge_index is of type torch_sparse.SparseTensor, its sparse indices (row, col) should relate to row = edge_index[1] and col = edge_index[0]. The major difference between both formats is that we need to input the transposed sparse adjacency matrix into propagate().

  • size (tuple, optional) – The size (N, M) of the assignment matrix in case edge_index is a LongTensor. If set to None, the size will be automatically inferred and assumed to be quadratic. This argument is ignored in case edge_index is a torch_sparse.SparseTensor. (default: None)

  • **kwargs – Any additional data which is needed to construct and aggregate messages, and to update node embeddings.

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

Bases: BasicEncoder

The GCN encoder using the GCNConv operator for message passing.

Parameters

config (Union[CommonArgs, Munch]) – munchified dictionary of args (config.model.dim_hidden, config.model.model_layer, config.dataset.dim_node)

forward(x, edge_index, edge_weight, batch)[source]

The GCN encoder.

Parameters
  • x (Tensor) – node features

  • edge_index (Tensor) – edge indices

  • edge_weight (Tensor) – edge weights

  • batch (Tensor) – batch indicator

Returns (Tensor):

node feature representations

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

Bases: GNNBasic

GCN feature extractor using the GCNEncoder .

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]

GCN feature extractor using the GCNEncoder .

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

node feature representations