File size: 1,392 Bytes
4780f16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""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}")