Seed-Averaged Selection With Top-k Re-evaluation

Quick Overview

Implement seed-averaged evaluation of hyperparameter configs that reports the mean and standard error, screens every config on initial seeds and re-evaluates only the top k with extra seeds before picking a winner. It tests noise-aware model selection, seed bookkeeping, tie rules and a fixed call budget.

Seed-Averaged Selection With Top-k Re-evaluation

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Implement `evaluate_config(objective, config, seeds)`, which returns `(mean, standard_error)` of `objective(config, seed)` over `seeds`. Then implement `select_with_reevaluation`, which screens every config on initial seeds, re-evaluates the top `k` with extra seeds, and returns a dict describing the winner. The signatures are: ```python def evaluate_config(objective, config, seeds): ... def select_with_reevaluation(objective, configs, n_initial_seeds, k, n_extra_seeds, base_seed=0, maximize=True): ... ``` The functions must follow these rules: - The standard error is `std(ddof=1) / sqrt(n)`, and it is `0.0` for one seed. No seeds or no configs raises `ValueError`. - The initial seeds are `base_seed + i` for `i < n_initial_seeds`. The extra seeds continue from `base_seed + n_initial_seeds`. - Rank by initial mean (descending if `maximize`, else ascending), and break ties by the lower index. Clip `k` to `[1, len(configs)]`. - The final stats pool the initial and extra scores. Call `objective` exactly `n * n_initial_seeds + k * n_extra_seeds` times, where `n` is the number of configs and `k` is the clipped value. The winner uses the same ranking rule on the final means. - The returned dict has the keys `means` and `stderrs` (arrays of length n), `top_k` (a list of indices in rank order), `final_means` and `final_stderrs` (arrays aligned with `top_k`), and `best_index` (an int). Example: ```python configs = [{"v": 1.0}, {"v": 3.0}, {"v": 3.0}, {"v": 2.0}] out = select_with_reevaluation(lambda c, s: c["v"], configs, n_initial_seeds=2, k=2, n_extra_seeds=1) out["means"] # [1.0, 3.0, 3.0, 2.0] out["top_k"] # [1, 2] (tie -> lower index first) out["final_means"] # [3.0, 3.0] out["best_index"] # 1 ``` ```hint Count the calls Write down how many times your plan calls `objective` and compare it with the required total. Any repeated work on the initial seeds shows up in that count. ``` ```hint Direction and ties When you switch between maximizing and minimizing, check that a tie still goes to the lower index in both directions. ``` ### What a Strong Answer Covers - How the mean and standard error are computed, including the single-seed case and the `ValueError` cases. - Which seeds each phase uses and how the extra seeds stay disjoint from the initial ones. - How the ranking handles the direction of the objective and ties, and how `k` is clipped. - How the final statistics are pooled and how the number of objective calls stays at the required total. - Why re-evaluating the top `k` protects the final pick from a lucky screening result. ### Follow-up Questions - Why should re-evaluation reuse the initial scores instead of discarding them? - How would you use the standard errors, in addition to the means, to decide the winner? - The extra seeds are split evenly across the top `k`. How would you allocate them adaptively instead?

Overview: Implement seed-averaged evaluation of hyperparameter configs that reports the mean and standard error, screens every config on initial seeds and re-evaluates only the top k with extra seeds before picking a winner. It tests noise-aware model selection, seed bookkeeping, tie rules and a fixed call budget.

General logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

Implement evaluate_config(objective, config, seeds), which returns (mean, standard_error) of objective(config, seed) over seeds. Then implement select_with_reevaluation, which screens every config on initial seeds, re-evaluates the top k with extra seeds, and returns a dict describing the winner.

The signatures are:

def evaluate_config(objective, config, seeds):
    ...


def select_with_reevaluation(objective, configs, n_initial_seeds, k,
                             n_extra_seeds, base_seed=0, maximize=True):
    ...

The functions must follow these rules:

  • The standard error is std(ddof=1) / sqrt(n) , and it is 0.0 for one seed. No seeds or no configs raises ValueError .
  • The initial seeds are base_seed + i for i < n_initial_seeds . The extra seeds continue from base_seed + n_initial_seeds .
  • Rank by initial mean (descending if maximize , else ascending), and break ties by the lower index. Clip k to [1, len(configs)] .
  • The final stats pool the initial and extra scores. Call objective exactly n * n_initial_seeds + k * n_extra_seeds times, where n is the number of configs and k is the clipped value. The winner uses the same ranking rule on the final means.
  • The returned dict has the keys means and stderrs (arrays of length n), top_k (a list of indices in rank order), final_means and final_stderrs (arrays aligned with top_k ), and best_index (an int).

Example:

configs = [{"v": 1.0}, {"v": 3.0}, {"v": 3.0}, {"v": 2.0}]
out = select_with_reevaluation(lambda c, s: c["v"], configs,
                               n_initial_seeds=2, k=2, n_extra_seeds=1)
out["means"]       # [1.0, 3.0, 3.0, 2.0]
out["top_k"]       # [1, 2]   (tie -> lower index first)
out["final_means"] # [3.0, 3.0]
out["best_index"]  # 1

What a Strong Answer Covers Guidance

  • How the mean and standard error are computed, including the single-seed case and the ValueError cases.
  • Which seeds each phase uses and how the extra seeds stay disjoint from the initial ones.
  • How the ranking handles the direction of the objective and ties, and how k is clipped.
  • How the final statistics are pooled and how the number of objective calls stays at the required total.
  • Why re-evaluating the top k protects the final pick from a lucky screening result.

Follow-up Questions Guidance

  • Why should re-evaluation reuse the initial scores instead of discarding them?
  • How would you use the standard errors, in addition to the means, to decide the winner?
  • The extra seeds are split evenly across the top k . How would you allocate them adaptively instead?