-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_hypothesis_tests.py
60 lines (55 loc) · 1.73 KB
/
plot_hypothesis_tests.py
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
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
import subprocess
from io import StringIO
import scipy.stats
matplotlib.use("Agg")
sns.set()
matplotlib.rcParams["text.usetex"] = True
plt.rc("font", family="serif")
sns.set_style("whitegrid")
num_samples = 1000000
output = subprocess.run(["./build/test/MMD", str(num_samples)], capture_output=True)
mmd_df = pd.read_csv(StringIO(output.stdout.decode("utf-8")))
output = subprocess.run(
["./build/test/ChiSquared", str(num_samples)], capture_output=True
)
chi_df = pd.read_csv(StringIO(output.stdout.decode("utf-8")))
# Add p value
sig1 = scipy.stats.chi2.ppf(1 - 0.01, df=119)
for r in range(chi_df["Rounds"].min(), chi_df["Rounds"].max() + 1):
chi_df = chi_df.append(
{"Algorithm": "$\\alpha=0.01$", "$\chi^2$": sig1, "Rounds": r},
ignore_index=True,
)
commbined = mmd_df["Algorithm"].append(chi_df["Algorithm"])
unique = commbined.unique()
palette = dict(zip(unique, sns.color_palette(n_colors=len(unique))))
for n in mmd_df["n"].unique():
plt.figure(figsize=(6, 4.5))
algs = mmd_df["Algorithm"].unique()
sns.lineplot(
data=mmd_df.loc[mmd_df["n"] == n],
x="Rounds",
y="$|\hat{\mathrm{MMD}}^2|$",
hue="Algorithm",
style="Algorithm",
palette=palette,
)
plt.yscale("log")
plt.savefig("MMD_n{}.png".format(n), bbox_inches="tight", dpi=1000)
plt.clf()
plt.figure(figsize=(6, 4.5))
sns.lineplot(
data=chi_df,
x="Rounds",
y="$\chi^2$",
hue="Algorithm",
style="Algorithm",
palette=palette,
)
plt.yscale("log")
plt.savefig("ChiSquared.png", bbox_inches="tight", dpi=1000)