-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_sdp_paras.py
More file actions
124 lines (105 loc) · 5.88 KB
/
Copy pathplot_sdp_paras.py
File metadata and controls
124 lines (105 loc) · 5.88 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Plot worst-case GBP parameter curves using mpoptimize transforms."""
from __future__ import annotations
import argparse
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MultipleLocator
from mp_transform import loose_gbp, regular_gbp
from plot_common import save_figure
plt.rcParams.update({
"font.family": "serif",
"font.serif": ["Computer Modern Roman", "Times New Roman", "DejaVu Serif"],
"mathtext.fontset": "cm",
"font.size": 12,
"axes.labelsize": 14,
"axes.titlesize": 14,
"legend.fontsize": 11,
"xtick.labelsize": 11,
"ytick.labelsize": 11,
"axes.linewidth": 0.8,
"lines.linewidth": 1.8,
"figure.dpi": 150,
"savefig.dpi": 300,
"savefig.bbox": "tight",
"text.usetex": False,
})
COLOR_OMEGA = "#2166AC"
COLOR_KAPPA = "#B2182B"
COLOR_OMEGA2 = "#4393C3"
COLOR_KAPPA2 = "#D6604D"
COLOR_LINEAR = "#777777"
def _compute_parameter_curves():
c_vals_reg = np.linspace(0.01, 0.99, 2000)
c_vals_loose = np.linspace(0.01, 0.50, 1200)
omega_reg = np.array([float(regular_gbp(str(c))[0]) for c in c_vals_reg], dtype=float)
kappa_reg = np.array([float(regular_gbp(str(c))[1]) for c in c_vals_reg], dtype=float)
omega_loose = np.array([float(loose_gbp(str(c))[0]) for c in c_vals_loose], dtype=float)
kappa_loose = np.array([float(loose_gbp(str(c))[1]) for c in c_vals_loose], dtype=float)
return c_vals_reg, c_vals_loose, omega_reg, kappa_reg, omega_loose, kappa_loose
def plot_parameters(*, base_stem="wc_gbp_code"):
c_vals_reg, c_vals_loose, omega_reg, kappa_reg, omega_loose, kappa_loose = _compute_parameter_curves()
valid = ~np.isnan(omega_loose)
fig, axes = plt.subplots(1, 2, figsize=(12, 4.8), sharey=True)
ax1, ax2 = axes
ax1.plot(c_vals_reg, omega_reg, color=COLOR_OMEGA, linestyle="-", linewidth=2.0, label=r"$\omega_R = 2^{-1/c_R}$")
ax1.plot(c_vals_reg, 0.5 * c_vals_reg, color=COLOR_LINEAR, linestyle=":", linewidth=1.6, alpha=0.45)
ax1.text(0.72, 0.33, r"$\frac{1}{2}c$", color=COLOR_LINEAR, fontsize=12, alpha=0.8, va="top")
ax1.plot(c_vals_reg, kappa_reg, color=COLOR_KAPPA, linestyle="--", linewidth=2.0, label=r"$\kappa_R = 1 - \omega_R/c_R$")
ax1.set_xlabel(r"$c$")
ax1.set_ylabel(r"Value")
ax1.set_title(r"RSDP Parameter of Worst Case RGBP", fontweight="bold", pad=10)
ax1.legend(loc="best", frameon=True, fancybox=False, edgecolor="black", framealpha=0.9)
ax1.set_xlim(0, 1)
ax1.set_ylim(0, 1)
ax1.xaxis.set_major_locator(MultipleLocator(0.2))
ax1.yaxis.set_major_locator(MultipleLocator(0.2))
ax1.xaxis.set_minor_locator(MultipleLocator(0.05))
ax1.yaxis.set_minor_locator(MultipleLocator(0.05))
ax1.grid(True, which="major", linestyle="-", alpha=0.3, linewidth=0.5)
ax1.grid(True, which="minor", linestyle=":", alpha=0.15, linewidth=0.3)
ax2.plot(c_vals_loose[valid], omega_loose[valid], color=COLOR_OMEGA, linestyle="-", linewidth=2.0, label=r"$\omega_L = (\omega/H(\omega))^{-1}(c_L)$")
ax2.plot(c_vals_loose, c_vals_loose, color=COLOR_LINEAR, linestyle=":", linewidth=1.6, alpha=0.45)
ax2.text(0.34, 0.39, r"$c$", color=COLOR_LINEAR, fontsize=12, alpha=0.8)
ax2.plot(c_vals_loose[valid], kappa_loose[valid], color=COLOR_KAPPA, linestyle="--", linewidth=2.0, label=r"$\kappa_L = 1 - \omega_L/c_L$")
ax2.set_xlabel(r"$c$")
ax2.set_title(r"SDP Parameter of Worst Case LGBP", fontweight="bold", pad=10)
ax2.legend(loc="best", frameon=True, fancybox=False, edgecolor="black", framealpha=0.9)
ax2.set_xlim(0, 0.5)
ax2.xaxis.set_major_locator(MultipleLocator(0.1))
ax2.xaxis.set_minor_locator(MultipleLocator(0.025))
ax2.grid(True, which="major", linestyle="-", alpha=0.3, linewidth=0.5)
ax2.grid(True, which="minor", linestyle=":", alpha=0.15, linewidth=0.3)
pdf_path = save_figure(fig, base_stem)
plt.close(fig)
print(f"wrote {pdf_path}")
fig2, ax = plt.subplots(1, 1, figsize=(6, 4.8))
ax.plot(c_vals_reg, 0.5 * c_vals_reg, color=COLOR_LINEAR, linestyle=":", linewidth=1.4, alpha=0.35)
ax.plot(c_vals_loose, c_vals_loose, color=COLOR_LINEAR, linestyle=":", linewidth=1.4, alpha=0.35)
ax.text(0.72, 0.33, r"$\frac{1}{2}c$", color=COLOR_LINEAR, fontsize=12, alpha=0.65, va="top")
ax.text(0.34, 0.39, r"$c$", color=COLOR_LINEAR, fontsize=12, alpha=0.65)
ax.plot(c_vals_reg, omega_reg, color=COLOR_OMEGA, linestyle="-", linewidth=2.0, label=r"Regular: $\omega_R = 2^{-1/c_R}$")
ax.plot(c_vals_loose[valid], omega_loose[valid], color=COLOR_OMEGA2, linestyle="--", linewidth=2.0, label=r"Loose: $\omega_L = (\omega/H(\omega))^{-1}(c_L)$")
ax.plot(c_vals_reg, kappa_reg, color=COLOR_KAPPA, linestyle="-", linewidth=2.0, label=r"Regular: $\kappa_R = 1 - \omega_R/c_R$")
ax.plot(c_vals_loose[valid], kappa_loose[valid], color=COLOR_KAPPA2, linestyle="--", linewidth=2.0, label=r"Loose: $\kappa_L = 1 - \omega_L/c_L$")
ax.set_xlabel(r"$c$")
ax.set_ylabel(r"Value")
ax.set_title(r"Worst Case Parameters: RGBP vs. LGBP", fontweight="bold", pad=10)
ax.legend(loc="best", frameon=True, fancybox=False, edgecolor="black", framealpha=0.9, fontsize=10)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.xaxis.set_major_locator(MultipleLocator(0.2))
ax.yaxis.set_major_locator(MultipleLocator(0.2))
ax.xaxis.set_minor_locator(MultipleLocator(0.05))
ax.yaxis.set_minor_locator(MultipleLocator(0.05))
ax.grid(True, which="major", linestyle="-", alpha=0.3, linewidth=0.5)
ax.grid(True, which="minor", linestyle=":", alpha=0.15, linewidth=0.3)
overlay_pdf_path = save_figure(fig2, f"{base_stem}_overlay")
plt.close(fig2)
print(f"wrote {overlay_pdf_path}")
def main():
parser = argparse.ArgumentParser(description="Plot worst-case GBP parameter curves using mpoptimize transforms.")
parser.add_argument("--output-stem", default="wc_gbp_code")
args = parser.parse_args()
plot_parameters(base_stem=args.output_stem)
if __name__ == "__main__":
main()