GNN Models
- class fedgraph.gnn_models.AggreGCN(nfeat: int, nhid: int, nclass: int, dropout: float, NumLayers: int)[source]
This class is an Aggregated GCN model with different methods of aggregation on the input features for the graph nodes on the first layer with a linear layer and the rest of the layers with GCNConv layers.
- Parameters:
- forward(aggregated_feature: Tensor, adj_t: Tensor) Tensor [source]
Represents the forward pass computation of a GCN with different methods of aggregation on the input features for the graph nodes on the first layer with a linear layer and the rest of the layers with GCNConv layers.
- Parameters:
x (torch.Tensor) – Input feature tensor for the graph nodes aggregated by the aggregation method.
adj_t (torch.Tensor) – Adjacency matrix of the graph.
- Returns:
(tensor) – The log softmax of the output of the last layer.
- Return type:
torch.Tensor
- class fedgraph.gnn_models.AggreGCN_Arxiv(nfeat: int, nhid: int, nclass: int, dropout: float, NumLayers: int)[source]
This class is an Aggregated GCN model with different methods of aggregation on the input features for the graph nodes on the first layer with a linear layer and the rest of the layers with GCNConv layers.
- Parameters:
- forward(aggregated_feature: Tensor, adj_t: Tensor) Tensor [source]
Represents the forward pass computation of a GCN with different methods of aggregation on the input features for the graph nodes on the first layer with a linear layer and the rest of the layers with GCNConv layers.
- Parameters:
x (torch.Tensor) – Input feature tensor for the graph nodes aggregated by the aggregation method.
adj_t (torch.Tensor) – Adjacency matrix of the graph.
- Returns:
(tensor) – The log softmax of the output of the last layer.
- Return type:
torch.Tensor
- class fedgraph.gnn_models.GCN(nfeat: int, nhid: int, nclass: int, dropout: float, NumLayers: int)[source]
A Graph Convolutional Network model implementation which creates a GCN with specified numbers of features, hidden layers, and output classes.
- Parameters:
- class fedgraph.gnn_models.GCN_arxiv(nfeat: int, nhid: int, nclass: int, dropout: float, NumLayers: int)[source]
A variant of the GCN model tailored for the arXiv dataset.
- Parameters:
- class fedgraph.gnn_models.GCN_products(nfeat: int, nhid: int, nclass: int, dropout: float, NumLayers: int)[source]
A specialized GCN model implementation designed for product graphs.
- Parameters:
- forward(x: Tensor, adj_t: Tensor) Tensor [source]
This function represents the forward pass computation of a GCN with products as input features for the graph nodes on the first layer and the rest of the layers with GCNConv layers.
- xtorch.Tensor
Input feature tensor for the graph nodes.
- adj_ttorch.Tensor
Adjacency matrix of the graph.
- Returns:
(tensor)
- Return type:
torch.Tensor
- class fedgraph.gnn_models.GIN(nhid: int, nlayer: int, nfeat: int | None = None, nclass: int | None = None, dropout: float | None = None)[source]
A Graph Isomorphism Network (GIN) model implementation which creates a GIN with specified numbers of features, hidden units, classes, layers, and dropout. The GIN model is a variant of the Graph Convolutional Network (GCN) model.
- Parameters:
- pre
The pre-neural network layer.
- Type:
torch.nn.Sequential
- graph_convs
The list of graph convolutional layers.
- Type:
torch.nn.ModuleList
- nn1
The first neural network layer.
- Type:
torch.nn.Sequential
- nnk
The k-th neural network layer.
- Type:
torch.nn.Sequential
- post
The post-neural network layer.
- Type:
torch.nn.Sequential
Note
This base model applies for both the server and the trainer. When the model is used as a server, only nhid, and nlayer should be passed as arguments. When the model is used as a trainer, nfeat, nclass, and dropout should also be passed as arguments.
- forward(data: Data) Tensor [source]
Forward pass of the GIN model, which takes in the input graph data and returns the model’s prediction.
- Parameters:
data (torch_geometric.data.Data) – The input graph data.
- Returns:
The prediction of the model.
- Return type:
torch.Tensor
- class fedgraph.gnn_models.GNN_LP(user_nums: int, item_nums: int, data_meta_data: tuple, hidden_channels: int)[source]
A Graph Nerual Network (GNN) model implementation used for link prediction tasks, which creates a GNN with specified numbers of user and item nodes, hidden channels, and data metadata.
- Parameters:
- user_emb
The user embedding layer.
- Type:
torch.nn.Embedding
- item_emb
The item embedding layer.
- Type:
torch.nn.Embedding
- forward(data: HeteroData) Tensor [source]
Represents the forward pass computation that is used in the training stage.
- Parameters:
data (HeteroData) – The input graph data.
- Returns:
(tensor) – The prediction output of the model.
- Return type:
torch.Tensor
- pred(train_data: HeteroData, test_data: HeteroData) Tensor [source]
Represents the prediction computation that is used in the test stage.
- Parameters:
train_data (HeteroData) – The training graph data.
test_data (HeteroData) – The testing graph data.
- Returns:
(tensor) – The prediction output of the model.
- Return type:
torch.Tensor
- class fedgraph.gnn_models.GNN_base(hidden_channels: int)[source]
A base Graph Neural Network model implementation which creates a GNN with two convolutional layers.
- Parameters:
hidden_channels (int) – The number of hidden features in each layer of the GNN model.
- conv1
The first convolutional layer.
- conv2
The second convolutional layer.
- class fedgraph.gnn_models.SAGE_products(nfeat: int, nhid: int, nclass: int, dropout: float, NumLayers: int)[source]
A Graph SAGE model designed specifically for handling product graphs as another variant of GCN.
- Parameters: