liveBook · Manning

Objective function

As explained in Graph Neural Networks in Action

A loss function is a function that quantifies the discrepancy between a model's output and the desired target.

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

How Graph Neural Networks in Action covers it

How deep it goes
Explains computation inside training loops and composite objectives, without deriving individual loss formulas.
Examples
Uses masked node classification and molecular graph reconstruction with predicted adjacency, features, and QED properties.
What it assumes
Assumes familiarity with model predictions, labels, graph data, and optimizers while reviewing the training-loop mechanics.
What you can do after
Apply it via a GNN training loop that computes loss, propagates gradients, and updates model parameters.
How it connects
Connects loss functions with training loops, training masks, backpropagation, optimizers, graph autoencoders, and semi-supervised learning.

Also explained in

Compare how 30 books explain objective function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.