File size: 2,402 Bytes
d44a7b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Regenerate illustrative tables using 80-digit arithmetic.

These evaluate the explicit circle design. They are not interval-certified
finite-length global optima. No randomness, downloads, or external services.
"""
from pathlib import Path
import csv
import json
import mpmath as mp


def main() -> None:
    mp.mp.dps = 80
    output = Path(__file__).resolve().parent / "results"
    output.mkdir(exist_ok=True)
    sigma = mp.mpf("0.0001")
    alpha = mp.mpf("0.05")
    quantile = mp.sqrt(2) * mp.erfinv(1 - 2 * alpha)
    rows = []
    for parameter, length in [("0.5", "0.5"), ("0.1", "0.5"),
                              ("0.01", "0.5"), ("0.5", "0.2"),
                              ("0.5", "0.1"), ("0.001", "0.5")]:
        lam, ell = mp.mpf(parameter), mp.mpf(length)
        kappa = lam * (1-lam)
        z = kappa*ell**2/(4*mp.pi**2)
        beta = 2*mp.pi*z/(1+mp.sqrt(1-z))
        deficit = 2*mp.sin(beta/2)**2
        gram_min = mp.mpf(3)/2*mp.sin(beta)**2
        condition = 2/mp.tan(beta)**2
        real_samples = 4*sigma**2*quantile**2/deficit**2
        rows.append({"lambda": parameter, "L": length,
                     "kappa": mp.nstr(kappa, 30),
                     "writer_angle": mp.nstr(beta, 35),
                     "writer_deficit": mp.nstr(deficit, 35),
                     "gram_min_d3": mp.nstr(gram_min, 35),
                     "gram_condition_d3": mp.nstr(condition, 35),
                     "real_sample_threshold": mp.nstr(real_samples, 35),
                     "illustrative_ceiling": str(int(mp.ceil(real_samples)))})
    with (output/"circle_examples.csv").open("w", newline="", encoding="utf-8") as f:
        writer = csv.DictWriter(f, fieldnames=list(rows[0]))
        writer.writeheader(); writer.writerows(rows)
    report = {"digits": 80, "sigma": str(sigma), "equal_prior_risk": str(alpha),
              "scope": "Explicit circle design; not certified finite-L global optima.",
              "rows": rows}
    (output/"circle_examples.json").write_text(json.dumps(report, indent=2), encoding="utf-8")
    for row in rows:
        print(row["lambda"], row["L"],
              "gap="+mp.nstr(mp.mpf(row["writer_deficit"]),7),
              "Gram="+mp.nstr(mp.mpf(row["gram_min_d3"]),7),
              "cond="+mp.nstr(mp.mpf(row["gram_condition_d3"]),7),
              "n="+row["illustrative_ceiling"])


if __name__ == "__main__":
    main()