class GCN(n_nodes=1000, ns=1, input_size=None, gcn_layers=2, gcn_units=1024,
gcn_output_size=256, embedding_size=128, predictor_units=64,
dropout=.01, lr=1e-3, epochs=3, early_stop=None, cuda=False)
This class implements the GCN (Graph Convolutional Network) model with the specified hyperparameters.
-
n_nodes : int, optional (default=1000)
Number of nodes in the graph.
-
ns : int, optional (default=1)
Neighborhood size for self-supervised learning.
-
input_size : int or None, optional (default=None)
Input size for the model. If None, it is automatically determined.
-
gcn_layers : int, optional (default=2)
Number of GCN layers in the model.
-
gcn_units : int, optional (default=1024)
Number of units in each GCN layer.
-
gcn_output_size : int, optional (default=256)
Output size of the final GCN layer.
-
embedding_size : int, optional (default=128)
Size of the node embeddings.
-
predictor_units : int, optional (default=64)
Number of units in the predictor layer.
-
dropout : float, optional (default=0.01)
Dropout probability for regularization.
-
lr : float, optional (default=1e-3)
Learning rate for model training.
-
epochs : int, optional (default=3)
Number of training epochs.
-
early_stop : int or None, optional (default=None)
Number of epochs with no improvement to trigger early stopping. If None, early stopping is not used.
-
cuda : bool, optional (default=False)
Whether to use CUDA for GPU acceleration.
_train_single_step_edges(training_batch, negative_pairs)
This method trains the model for a single step using edge-level training data. It computes predictions, retrieves self-supervised true labels, computes the loss, and backpropagates to update the model's parameters. It also computes the 'local' accuracy based on the predictions.
-
training_batch : tuple
A tuple containing training data, features, and positive pairs.
-
negative_pairs : torch.Tensor
Tensor containing negative pairs for training.
-
train_loss : torch.Tensor
The computed training loss for the current step.
-
accuracy : float
The computed 'local' accuracy for the current step.
get_embeddings(X, features=None)
This method computes embeddings for the input data using the model. It also allows for the specification of a feature matrix. If no feature matrix is provided, an identity matrix is used as features. The resulting embeddings are converted to a NumPy array for convenience.
-
X : torch.Tensor
Input data for which embeddings are to be obtained.
-
features : torch.Tensor or None, optional (default=None)
Feature matrix. If None, an identity matrix is used as features.
-
embeddings : numpy.ndarray
Embeddings obtained for the input data.
fit(X, features=None, save=False, dir_name=None, pbar=None, day=None)
This method trains the model for self-supervised learning using the provided adjacency matrix. It iterates through epochs and predicts future connections in the graph. If 'save' is True, it saves the trained model and results in the specified directory. 'pbar' is used to track training progress, and 'day' is used to indicate the current day in the training process.
-
X : torch.Tensor
The sparse adjacency matrix used for training.
-
features : torch.Tensor or None, optional (default=None)
Feature matrix. If None, an identity matrix is used as features.
-
save : bool, optional (default=False)
Whether to save the trained model and results.
-
dir_name : str or None, optional (default=None)
Directory name for saving the model and results.
-
pbar : tqdm.tqdm or None, optional (default=None)
Progress bar for tracking training progress.
-
day : int or None, optional (default=None)
The current day in the training process.
class GCN_GRU(n_nodes=1000, history=10, ns=1, input_size=None, gcn_layers=2,
gcn_units=1024, gcn_output_size=512, embedding_size=128,
predictor_units=64, dropout=.01, lr=1e-3, early_stop=None,
best_train_acc=False, cuda=False)
This class implements the GCN-GRU model with the specified hyperparameters. It sets up the model, optimizer, and manages CUDA if available and specified.
-
n_nodes : int, optional (default=1000)
Number of nodes in the graph.
-
history : int, optional (default=10)
Number of days to use as history.
-
ns : int, optional (default=1)
Neighborhood size for self-supervised learning.
-
input_size : int or None, optional (default=None)
Input size for the model. If None, it is automatically determined.
-
gcn_layers : int, optional (default=2)
Number of GCN layers in the model.
-
gcn_units : int, optional (default=1024)
Number of units in each GCN layer.
-
gcn_output_size : int, optional (default=256)
Output size of the final GCN layer.
-
embedding_size : int, optional (default=128)
Size of the node embeddings.
-
predictor_units : int, optional (default=64)
Number of units in the predictor layer.
-
dropout : float, optional (default=0.01)
Dropout probability for regularization.
-
lr : float, optional (default=1e-3)
Learning rate for model training.
-
early_stop : int or None, optional (default=None)
Number of epochs with no improvement to trigger early stopping. If None, early stopping is not used.
-
best_train_acc : bool, optional (default=False)
Whether to use the best training accuracy model for testing.
-
cuda : bool, optional (default=False)
Whether to use CUDA for GPU acceleration.
_train_single_step_edges(training_batch, negative_pairs)
This method trains the model for a single step using edge-level training data. It computes predictions, retrieves self-supervised true labels, computes the loss, and backpropagates to update the model's parameters. It also computes the 'local' accuracy based on the predictions.
-
training_batch : tuple
A tuple containing training data, features, and positive pairs.
-
negative_pairs : torch.Tensor
Tensor containing negative pairs for training.
-
train_loss : torch.Tensor
The computed training loss for the current step.
-
accuracy : float
The computed 'local' accuracy for the current step.
get_embeddings(X, features=None)
This method computes embeddings for the input data using the model. It also allows for the specification of a feature matrix. If no feature matrix is provided, an identity matrix is used as features. The resulting embeddings are converted to a NumPy array for convenience.
-
X : torch.Tensor
Input data for which embeddings are to be obtained.
-
features : torch.Tensor or None, optional (default=None)
Feature matrix. If None, an identity matrix is used as features.
-
embeddings : numpy.ndarray
Embeddings obtained for the input data.
fit(X, epochs, features=None, save=False, dir_name=None)
This method fits the GCN-GRU model to the input data using a specified number of training epochs. It iterates through epochs, training on historical data, and updating the model. If 'save' is True, it saves the trained model and training history in the specified directory.
-
X : list of torch.Tensor
List of sparse adjacency matrices representing historical data.
-
epochs : int
Number of training epochs.
-
features : list of torch.Tensor or None, optional (default=None)
List of feature matrices corresponding to historical data. If None, identity matrices are used as features.
-
save : bool, optional (default=False)
Whether to save the trained model and training history.
-
dir_name : str or None, optional (default=None)
Directory name for saving the model and training history.
class IncrementalGcnGru(n_nodes=1000, history=10, ns=1, input_size=None,
gcn_layers=2, gcn_units=1024, gcn_output_size=512,
embedding_size=128, predictor_units=64, dropout=.01, lr=1e-3,
epochs=3, cuda=False)
This class implements the Incremental GCN-GRU model with the specified hyperparameters. It sets up the model, optimizer, and manages CUDA if available and specified.
-
n_nodes : int, optional (default=1000)
Number of nodes in the graph.
-
history : int, optional (default=10)
Number of days to use as history.
-
ns : int, optional (default=1)
Neighborhood size for self-supervised learning.
-
input_size : int or None, optional (default=None)
Input size for the model. If None, it is automatically determined.
-
gcn_layers : int, optional (default=2)
Number of GCN layers in the model.
-
gcn_units : int, optional (default=1024)
Number of units in each GCN layer.
-
gcn_output_size : int, optional (default=256)
Output size of the final GCN layer.
-
embedding_size : int, optional (default=128)
Size of the node embeddings.
-
predictor_units : int, optional (default=64)
Number of units in the predictor layer.
-
dropout : float, optional (default=0.01)
Dropout probability for regularization.
-
lr : float, optional (default=1e-3)
Learning rate for model training.
-
epochs : int, optional (default=3)
Number of training epochs.
-
cuda : bool, optional (default=False)
Whether to use CUDA for GPU acceleration.
_train_single_step_edges(training_batch, negative_pairs)
This method trains the model for a single step using edge-level training data. It computes predictions, retrieves self-supervised true labels, computes the loss, and backpropagates to update the model's parameters. It also computes the 'local' accuracy based on the predictions.
-
training_batch : tuple
A tuple containing training data, features, and positive pairs.
-
negative_pairs : torch.Tensor
Tensor containing negative pairs for training.
-
train_loss : torch.Tensor
The computed training loss for the current step.
-
accuracy : float
The computed 'local' accuracy for the current step.
get_embeddings(X, features=None)
This method computes embeddings for the input data using the model. It also allows for the specification of a feature matrix. If no feature matrix is provided, an identity matrix is used as features. The resulting embeddings are converted to a NumPy array for convenience.
-
X : torch.Tensor
Input data for which embeddings are to be obtained.
-
features : torch.Tensor or None, optional (default=None)
Feature matrix. If None, an identity matrix is used as features.
-
embeddings : numpy.ndarray
Embeddings obtained for the input data.
fit(X, features=None, save=False, dir_name=None, pbar=None, day=None)
This method trains the Incremental GCN-GRU model on the provided data for a specified
number of epochs. It iteratively looks back "history" days and predicts the next day's
graph structure. It updates the model's parameters using the _train_single_step_edges
method.
-
X : list of torch.Tensor
List of sparse adjacency matrices for each day.
-
features : list of torch.Tensor or None, optional (default=None)
List of feature matrices for each day. If None, identity matrices are used.
-
save : bool, optional (default=False)
Whether to save the trained model.
-
dir_name : str or None, optional (default=None)
The directory where the trained model should be saved.
-
pbar : tqdm.tqdm or None, optional (default=None)
A tqdm progress bar to track training progress. If None, no progress bar is used.
-
day : int or None, optional (default=None)
The current day being trained. Used for progress bar description.