This part asks you to do a mini-batch training of the model.
Set the parameter in the PDE alpha = 0.1. (This is not for learning. In PINN, we know the exact form of a PDE. We just need neural networks to help us solve it.)
Set the number of epochs as 1000.
Define
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
While iterating over epochs, use tqdm to track the progress:
for epoch in tqdm(range(num_epochs)):
In each epoch,
(1) Configure the model to the training mode.
(2) Iterate over all mini-batches of dataset_train_PDE.
(3) For each of the above mini-batch of the PDE dataset, while computing the total loss function, you also need to use all data in dataset_train_IC and dataset_train_BC.
(4) Do all these tasks on GPU.
In each epoch, after training over all mini-batches, if the epoch index is divisible by 100, do the following tasks:
(1) Configure the model to the evaluation mode.
(2) Compute the total loss over the entire three datasets: dataset_train_PDE, dataset_train_IC, dataset_train_BC.
(3) Print the epoch index, the residual loss from PDE, the IC loss, the BC loss, and the total loss.