Pareto Front and Latency-Budgeted Trial Selection
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: medium
Interview Round: Other
Given a DataFrame of tuning trials with columns `trial_id`, `f1` (maximise) and `latency_ms` (P95, minimise), implement `pareto_front(trials)` returning the ids of all non-dominated trials, and `best_under_budget(trials, latency_budget_ms)` returning the id of the best feasible trial.
```python
def pareto_front(trials: pd.DataFrame) -> list[int]: ...
def best_under_budget(trials: pd.DataFrame, latency_budget_ms: float) -> int | None: ...
```
Requirements:
- A trial is dominated if another trial is ≥ on `f1`, ≤ on `latency_ms`, and strictly better on one of them. Exact duplicates are both kept.
- `pareto_front` orders ids by latency ascending, ties by `trial_id` ascending. Empty input returns `[]`.
- Feasible means `latency_ms <= latency_budget_ms` (inclusive). Highest `f1` wins, ties by lower latency, then lowest `trial_id`.
- If no trial is feasible, return `None`.
- Rows with NaN `f1` or `latency_ms` are ignored. Return plain Python `int` ids (not NumPy scalars).
Example:
```python
trials = pd.DataFrame({
"trial_id": [0, 1, 2, 3, 4, 5, 6],
"f1": [0.80, 0.85, 0.83, 0.90, 0.78, 0.90, 0.92],
"latency_ms": [10.0, 20.0, 25.0, 40.0, 12.0, 35.0, 60.0],
})
pareto_front(trials) # [0, 1, 5, 6]
best_under_budget(trials, 35.0) # 5 (budget inclusive)
best_under_budget(trials, 34.9) # 1
best_under_budget(trials, 5.0) # None
```
```hint Self-comparison
Write the dominance test so that comparing a trial with itself, or with an exact copy of itself, never marks it as dominated.
```
```hint Consistency
Ask whether the trial `best_under_budget` returns could ever be missing from `pareto_front`, given the tie rules.
```
### Constraints & Assumptions
- `trial_id` values are unique integers. Extra columns (for example hyperparameters) may be present.
- Non-NaN `f1` and `latency_ms` values are finite floats.
### What a Strong Answer Covers
- A dominance test with the right mix of weak and strict inequalities, so exact duplicates both survive.
- NaN filtering before either computation, and plain `int` output.
- A deterministic order for the front, and a lexicographic pick for the budget with an inclusive bound and a `None` case.
- How the budgeted pick relates to the front.
- The complexity of the pairwise check, and a faster approach for two objectives.
### Follow-up Questions
- Can you compute the 2-D front faster than $O(n^2)$?
- P95 latency is a noisy measurement. How does that affect selection?
- How would you extend this to a third objective such as memory footprint?
Overview: Implement two helpers over a table of hyperparameter tuning trials: the Pareto front of F1 against P95 latency, and the best trial under a latency budget. It tests the dominance definition, tie-breaking, NaN handling and how budgeted selection relates to the front.