Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Distributionally Robust Optimization

Distributionally robust optimization trains models for the worst plausible data distribution rather than the average one, via ambiguity sets or group DRO.

Distributionally robust optimization (DRO) is a training and decision-making approach that minimizes the expected loss under the worst distribution in a set of plausible data distributions, instead of under the training distribution alone. Standard training, known as empirical risk minimization (ERM), assumes future data will resemble the training data and minimizes the average loss. DRO assumes real data will differ in ways that can be bounded and optimizes for the hardest case inside that bound. The resulting models trade a little average accuracy for steadier performance when conditions shift, such as a camera that saw far more daytime than nighttime footage during training.

Ambiguity Sets#

The set of distributions that DRO guards against is called the ambiguity set, or uncertainty set, and its shape decides what kind of robustness the model gains:

  • Divergence balls: Contain every distribution within a fixed KL or chi-squared divergence of the training data. Optimizing against them upweights the training examples with the highest loss, so the model cannot ignore its hardest samples. A closely related objective, the conditional value at risk, averages only the worst fraction of per-example losses.
  • Wasserstein balls: Contain distributions reachable by moving probability mass a limited distance in input space. Because the distance measures how much mass moves and how far, these sets cover small perturbations of the inputs themselves.
  • Group mixtures: Contain any reweighting of known subpopulations, such as day and night images or scans from different hospitals. The worst case is then simply the worst group.

Wasserstein DRO is closely tied to adversarial training against adversarial attacks, which also optimizes for nearby worst-case inputs. The size of the set is DRO's central hyperparameter: a large set prepares the model for unrealistic data and lowers its typical accuracy, while a small one misses the shifts that matter in deployment.

Group DRO#

Group DRO, introduced by Shiori Sagawa, Pang Wei Koh, Tatsunori Hashimoto, and Percy Liang in work published in 2020, is the most widely used form in deep learning. It minimizes the loss of the worst-performing group instead of the average loss over all examples. In practice it keeps a weight for each group, carried from batch to batch, raises the weight of whichever groups currently have the highest loss, and backpropagates the group-weighted loss:

import torch

# Per-image losses from one training batch and the condition each image came from
losses = torch.tensor([0.20, 0.30, 0.25, 0.90, 1.10, 0.15])
groups = torch.tensor([0, 0, 0, 1, 1, 0])  # 0 = daytime, 1 = nighttime
group_losses = torch.stack([losses[groups == g].mean() for g in (0, 1)])

# Empirical risk minimization optimizes the average loss over all images
print(f"ERM loss: {losses.mean():.2f}, daytime loss: {group_losses[0]:.2f}, nighttime loss: {group_losses[1]:.2f}")

# Group DRO shifts its group weights toward high-loss groups with an exponentiated-gradient step
group_weights = torch.tensor([0.5, 0.5])  # carried over from earlier batches
group_weights = group_weights * torch.exp(1.0 * group_losses)  # step size 1.0
group_weights = group_weights / group_weights.sum()
dro_loss = (group_weights * group_losses).sum()  # the loss that is backpropagated
print(f"Group weights: day {group_weights[0]:.2f}, night {group_weights[1]:.2f}, group DRO loss: {dro_loss:.2f}")

The average loss of 0.48 looks healthy, but the two nighttime images average 1.00 against 0.22 for daytime. One update moves the group weights from 0.50 each to 0.32 for day and 0.68 for night, so the backpropagated loss rises to 0.76 and its gradient comes mostly from the nighttime images. Over many batches the weight keeps flowing to whichever group lags.

Group DRO is a direct remedy for shortcut learning. On the Waterbirds benchmark, most training photos of water birds show water backgrounds, so standard training learns the background and fails on water birds photographed over land. With strong regularization, the authors raised worst-group test accuracy from 21.3% with ERM to 84.6% with group DRO, and average accuracy also rose from 95.7% to 96.6%. Regularization matters because a large network can drive every group's training loss to zero, leaving the DRO objective nothing to prioritize.

Group DRO needs the group of every training example. When groups are unknown, a chi-squared divergence ball can stand in for them: Tatsunori Hashimoto and colleagues showed in 2018 that minimizing the worst-case loss over such a ball protects any sufficiently large subpopulation without knowing who belongs to it.

Finding the Worst Groups#

The groups that matter are often discovered from errors. For YOLO26 object detection models trained on a saved dataset version, Ultralytics Platform adds per-image diagnostics that rank validation images by per-image F1 score, correlate F1 with image size, aspect ratio, and instance count, and list the classes that appear most often in the weakest images. Together they break a single mean average precision (mAP) into candidate groups to collect, oversample, or weight.

DRO also has uses well beyond vision:

  • Fairness across subpopulations: When groups are defined by demographic attributes, minimizing the worst group's loss reduces performance gaps directly.
  • Real-world distribution shift: The WILDS benchmark from Stanford tests models on shifts such as tissue images from different hospitals and satellite images from different regions and years, and it includes group DRO among its standard baselines.
  • Operations research: DRO is applied to power grid scheduling, supply chain planning, and portfolio selection, where decisions face uncertain demand or prices and a plan tuned only to the historical average can fail badly in an unusual year.

DRO, Augmentation, and Drift Monitoring#

Data augmentation and DRO approach the same problem from opposite sides. Augmentation expands what the model sees with synthetic variations of the training images, while DRO changes the objective so rare but real variations count for more. They combine well: augmentation supplies varied examples, and a DRO objective keeps the hardest of them from being averaged away. Domain adaptation takes a third route, adapting to one known target distribution with unlabeled data from it. After deployment, monitoring for data drift reveals the shifts that no ambiguity set anticipated, and those new conditions become the next groups to collect and weight.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning