Mean squared error (MSE) averages the squared differences between predicted and target values. It turns regression error into a scalar loss that can guide model training: larger mistakes receive disproportionately larger penalties. section 5.4.2 section 6.2.2
Use MSE as a training and evaluation component in a straightforward pipeline:
- Produce predictions from the model, such as molecular QED values or future sensor positions. section 5.4.2 section 6.2.2
- Compare predictions with the corresponding target values through the criterion function. section 5.4.2 section 6.2.2
- Backpropagate the loss during training, then calculate it on validation or test data without updating parameters. section 6.2.2
MSE inside a graph autoencoder loss
Molecular graph generation combines several objectives. Binary cross-entropy measures adjacency reconstruction, MSE measures QED prediction, and KL divergence regularizes the latent space; the three losses are summed for training. section 5.4.2
Listing 5.18 Loss for molecule graph generation
def calculate_loss(self, pred_adj, \
true_adj, qed_pred, qed_true, mu, logvar):
adj_loss = F.binary_cross_entropy\
(pred_adj, true_adj) #1
qed_loss = F.mse_loss\
(qed_pred.view(-1), qed_true.view(-1)) #2
kl_loss = -0.5 * torch.mean\
(torch.sum(1 + logvar - mu.pow(2)\ #3
- logvar.exp(), dim=1))
return adj_loss + qed_loss + kl_loss
Inspect the PyTorch implementation where qed_loss is computed with F.mse_loss after flattening predicted and true QED values. section 5.4.2
Listing 6.3 Testing loop
model.eval() #1
predictions = []
test_losses = []
seq_len = 40
with torch.no_grad():
for i, (inputs, targets) in enumerate(testloader):
inputs = inputs.to(device)
targets = targets.to(device)
preds = []
for _ in range(seq_len):
output = model(inputs)
preds.append(output)
inputs = torch.cat([inputs[:, 1:]\
, output.unsqueeze(1)], dim=1) \ #2
preds = torch.cat(preds, dim=1) #3
loss = criterion(preds, targets) #3
test_losses.append(loss.item()) #3
predictions.append(preds.detach().cpu().numpy())
predictions = np.concatenate(predictions, axis=0) #4
test_loss = np.mean(test_losses) #5
Trace how the same criterion evaluates multi-step predictions in a testing loop and contributes to the reported mean test loss. section 6.2.2












