deepmind-research icon indicating copy to clipboard operation
deepmind-research copied to clipboard

[learning_to_simulate] Exclude kinematic particles from evaluation MSE metrics

Open victrvondoom opened this issue 2 weeks ago • 0 comments

Bug description

The learning_to_simulate training and evaluation pipeline appears to handle kinematic particles inconsistently when calculating evaluation metrics.

In get_one_step_estimator_fn(), kinematic particles are explicitly excluded from the training loss through non_kinematic_mask:

non_kinematic_mask = tf.logical_not(
    get_kinematic_mask(features['particle_type'])
)

loss = (pred_acceleration - target_acceleration) ** 2
loss = tf.where(non_kinematic_mask, loss, tf.zeros_like(loss))
loss = tf.reduce_sum(loss) / tf.reduce_sum(num_non_kinematic)

However, the evaluation metrics are calculated without applying this mask:

eval_metrics_ops = {
    'loss_mse': tf.metrics.mean_squared_error(
        pred_acceleration, target_acceleration),
    'one_step_position_mse': tf.metrics.mean_squared_error(
        predicted_next_position, target_next_position)
}

This means evaluation includes predictions for kinematic particles even though these particles are excluded from the training objective.

There is a related inconsistency in rollout evaluation.

In rollout(), predicted positions for kinematic particles are replaced with their ground-truth positions:

kinematic_mask = get_kinematic_mask(features['particle_type'])
next_position_ground_truth = ground_truth_positions[:, step]

next_position = tf.where(
    kinematic_mask,
    next_position_ground_truth,
    next_position
)

The resulting rollout predictions are subsequently passed to tf.metrics.mean_squared_error() without excluding kinematic particles.

Consequently, kinematic particles contribute zero prediction error by construction during rollout evaluation, potentially making the reported rollout error artificially low.

Why this is a problem

The evaluation metrics should consistently measure the particles whose dynamics are actually being learned.

The current behavior creates two problems:

  1. One-step evaluation can include errors from kinematic particles that are excluded from training.
  2. Rollout evaluation includes kinematic particles whose predictions have already been replaced by ground truth.

As a result, evaluation scores can be misleading and may vary with the proportion of kinematic particles in a trajectory, even when the model's performance on simulated particles remains unchanged.

Steps to reproduce

  1. Load a dataset containing both normal and kinematic particles.
  2. Run one-step evaluation using get_one_step_estimator_fn().
  3. Observe that the training loss masks out kinematic particles, but loss_mse and one_step_position_mse do not.
  4. Run rollout evaluation.
  5. Observe that kinematic predictions are replaced with ground-truth positions before rollout_error_mse is calculated.
  6. Compare the reported metrics with an evaluation that excludes kinematic particles.

A useful synthetic test would contain one normal particle and one kinematic particle. Changing only the kinematic particle's model prediction should not change the evaluation score if the intended evaluation objective is to measure learned particle dynamics.

Expected behavior

Evaluation metrics should consistently exclude kinematic particles, following the same masking principle used in the training loss.

The correction should cover:

  • loss_mse
  • one_step_position_mse
  • rollout_error_mse

The implementation should also preserve correct metric aggregation across batches and evaluation steps, including distributed evaluation where applicable.

Suggested tests

  • Verify that kinematic particles do not contribute to one-step evaluation metrics.
  • Verify that kinematic particles do not contribute to rollout evaluation metrics.
  • Confirm that changing kinematic particle predictions does not change the reported metrics.
  • Confirm that metrics remain correct with different proportions of normal and kinematic particles.
  • Ensure existing evaluation behavior remains unchanged for datasets without kinematic particles.

Expected outcome

Training, one-step evaluation and rollout evaluation should use a consistent definition of the particles whose dynamics are being evaluated.

This would prevent ground-truth-overridden particles from artificially influencing reported model performance.

victrvondoom avatar Nov 15 '26 18:11 victrvondoom