An objective function quantifies the discrepancy between predictions and desired targets, giving training a value to minimize. In graph neural networks, it compares predicted outputs with labels or reconstructed graph data. section 2.3.3 section 5.4.4
A graph-model training step uses the objective function as a short pipeline:
- Run a forward pass to produce predictions, such as node outputs, adjacency matrices, feature matrices, or molecular properties. section 2.3.3 section 5.4.4
- Select the relevant predictions, such as labeled nodes selected through a training mask. section 2.3.3
- Compare predictions with targets, then backpropagate the resulting value and update the optimizer. section 2.3.3
- Combine several terms when the task requires multiple goals, including reconstruction loss, KL divergence loss, property prediction loss, and gradient penalties. section 5.4.4
Molecule generation
A variational graph autoencoder predicts an adjacency matrix, node-feature matrix, and QED property. Its objective combines reconstruction, KL divergence, property prediction, and gradient-penalty terms; decreasing loss indicates improved reproduction of molecules. section 5.4.4
Listing 5.23 Training function for molecule graph generation
def train(model, optimizer, data, test=False):
model.train()
optimizer.zero_grad()
pred_adj, pred_feat, pred_qed, mu, logvar, _ = model(data)
real_adj = create_adjacency_matrix\
(data.edge_index, data.edge_attr, \
num_nodes=NUM_ATOMS)
real_x = data.x
real_qed = data.qed
loss = calculate_loss\
(pred_adj[0], real_adj, pred_qed, \
real_qed, mu, logvar) #1
total_loss = loss
if not test:
total_loss.backward()
optimizer.step()
return total_loss.item()
Inspect the training function showing prediction, target construction, composite loss calculation, conditional backpropagation, and optimizer stepping. section 5.4.4





























