linear_model.ZINB_grad.train_ZINB
- linear_model.ZINB_grad.train_ZINB(x, optimizer, model, epochs=150, val=False)[source]
Trains a ZINB-Grad model.
- The function will train a ZINB-Grad model using an optimizer for a number of epochs,
and it will return both losses and negative log-likelihood, which were obtained during the training procedure.
Parameters
- xtorch.Tensor
It is the data for training, a Tensor of shape (n_samples, n_features).
- optimizer: An object of torch.optim.Optimizer
For more details, please refer to Pytorch documentation.
- model: An object of the ZINB_Grad class
Please refer to the example.
- epochsint (optional, default=150)
Number of iteration for training.
- valbool (optional, default=False)
Whether it is validation or training process.
Returns
- losseslist
A list consisting of the loss of each epoch.
- neg_log_likslist
A list consisting of the negative Log-likelihood of each epoch.
Examples
>>> import ZINB_grad >>> import data_prep >>> import torch >>> from torch.utils.data import DataLoader >>> cortex = data_prep.CORTEX() >>> y, labels = next(iter(DataLoader(cortex, batch_size= cortex.n_cells, shuffle=True))) >>> model = ZINB_grad.ZINB_WaVE(Y = y, K = 10, device =device) >>> optimizer = torch.optim.Adam(model.parameters(), lr = 0.08) >>> losses, neg_log_liks = ZINB_grad.train_ZINB(y, optimizer, model, epochs = 300)