Training MOGDx
- train.AUROC(logits, targets, meta)[source]
Calculates the Area Under the Receiver Operating Characteristic curve (AUROC).
- Parameters:
logits (torch.Tensor) – The predicted outcomes from the model.
targets (torch.Tensor) – The true outcomes.
meta (pd.Series) – Metadata associated with the outcomes.
- Returns:
Contains the matplotlib figure object, and the transformed prediction scores.
- Return type:
tuple
- train.confusion_matrix(logits, targets, display_labels)[source]
Generates a confusion matrix plot from the predicted and true labels.
- Parameters:
logits (torch.Tensor) – Logits output from the model.
targets (torch.Tensor) – True labels for the data.
display_labels (list) – List of labels to display on the matrix axes.
- Returns:
Seaborn axis grid containing the confusion matrix plot.
- Return type:
seaborn.axisgrid
- train.evaluate(model, graph, dataloader)[source]
Evaluates the model performance on a validation set.
- Parameters:
model (torch.nn.Module) – Model to evaluate.
graph (dgl.DGLGraph) – Graph from which data is to be loaded.
dataloader (torch.utils.data.DataLoader) – DataLoader the supplies the evaluation data.
- Returns:
A tuple containing the loss, accuracy, F1 score, precision, recall, logits and labels.
- Return type:
tuple
- train.layerwise_infer(device, graph, nid, model, batch_size)[source]
Perform inference in a layer-wise manner for subgraph provided.
- Parameters:
device (str) – The device on which the inference will be computed (e.g., ‘cuda’ or ‘cpu’).
graph (dgl.DGLGraph) – The graph containing the nodes.
nid (list or tensor) – Node IDs for which inference is to be performed.
model (nn.Module) – The trained model.
batch_size (int) – The size of batches to process the graph.
- Returns:
Accuracy of prediction after inference.
- Return type:
float
- train.train(g, train_index, device, model, labels, epochs, lr, patience, pretrain=False, pnet=False, batch_size=1024)[source]
Trains a model on the given graph data using specified parameters.
- Parameters:
g (dgl.DGLGraph) – The graph containing feature and label data.
train_index (list) – Indices used for training the model.
device (str) – Device type to use (‘cuda’ or ‘cpu’).
model (torch.nn.Module) – Model to be trained.
labels (torch.Tensor) – Labels for the training data.
epochs (int) – Number of epochs to train the model.
lr (float) – Learning rate for the optimizer.
patience (int) – Patience for early stopping criterion.
pretrain (bool) – Whether to preprocess data before training.
pnet (bool) – Indicates the use of a Pathway Network model for data preprocessing.
- Returns:
Either a graph or a matplotlib figure depending on the ‘pretrain’ parameter.
- train.tsne_embedding_plot(emb, meta)[source]
Generates a 2D t-SNE plot of embeddings colored by metadata labels.
- Parameters:
emb (np.array) – High-dimensional embeddings to be reduced.
meta (pd.Series) – Metadata series containing labels to color the embeddings.
- Returns:
Displays a t-SNE plot of embeddings.
- Return type:
None