"""Problem instances, paper ยง6 (spec: specs/exp00_core.md, ambiguity #1).""" import numpy as np def make_instance(n, weight_decay, seed=0): # alpha/beta are drawn once with default_rng(0) and held constant across # all seeds/configurations (ambiguity #1) -- callers should not vary seed. rng = np.random.default_rng(seed) alpha = rng.uniform(1.0, 5.0, n) beta = rng.uniform(1.0, 5.0, n) mu = 0.1 + 0.9 * alpha / (alpha + beta) if weight_decay == "exp": w = 0.9 ** np.arange(n) w = w / w.sum() elif weight_decay == "linear": i = np.arange(1.0, n + 1.0) w = 1.0 + (i - 1.0) / (n - 1.0) w = w / w.sum() else: raise ValueError(f"unknown weight_decay {weight_decay!r}") return dict(mu=mu, alpha=alpha, beta=beta, w=w, weight_decay=weight_decay) def gini_w(w, weight_decay): """Orient w for the Gini oracle: w_1>=...>=w_n paired with ascending-sorted u. Exponential decay is already non-increasing (use as-is). Linear decay is increasing in i, so for Gini the reversed vector is used (largest weight on the smallest-utility rank) -- see spec ambiguity note on App. E weights. """ w = np.asarray(w, dtype=float) if weight_decay == "exp": return w if weight_decay == "linear": return w[::-1] raise ValueError(f"unknown weight_decay {weight_decay!r}")