Download core/instance.py from JG1310/repro-swf-allocation-bundle: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/JG1310/repro-swf-allocation-bundle/resolve/main/core/instance.py
- Command line
-
hf download hf://datasets/JG1310/repro-swf-allocation-bundle/core/instance.py
-
curl -L -o instance.py https://huggingface.co/datasets/JG1310/repro-swf-allocation-bundle/resolve/main/core/instance.py
1.39 kB
| """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}") | |