Skip to content

Commit a569fd6

Browse files
committed
added plotting function of prob inconsist consist
1 parent f661dac commit a569fd6

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

validphys2/src/validphys/closuretest/multiclosure_nsigma.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ def def_of_nsigma_alpha(
183183
fit_idxs = np.where(nsigma_values < z_alpha)[0]
184184
else:
185185
fit_idxs = np.where(nsigma_values > z_alpha)[0]
186-
set1_alpha[alpha] = df.columns[fit_idxs].tolist()
186+
# save it as set to allow for easy intersection with other sets
187+
set1_alpha[alpha] = set(df.columns[fit_idxs])
187188

188189
return NsigmaAlpha(alpha_dict=set1_alpha, is_weighted=multiclosurefits_nsigma.is_weighted)
189190

@@ -326,9 +327,7 @@ def def_set_2(
326327
else:
327328
columns_bools = np.any((df_weight - df_ref).values > z_alpha, axis=0)
328329

329-
columns = df_weight.columns[columns_bools].to_list()
330-
331-
set2_alpha[alpha] = columns
330+
set2_alpha[alpha] = set(df_weight.columns[columns_bools])
332331

333332
return set2_alpha
334333

validphys2/src/validphys/closuretest/multiclosure_nsigma_output.py

+56
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,62 @@
55
import matplotlib.pyplot as plt
66

77

8+
@figure
9+
def plot_probability_inconsistent(set_2_alpha, set_1_alpha, set_3_alpha, comp_set_1_alpha, n_fits):
10+
"""
11+
P(inconsistent) = P(set 2 | set 1) + P(set 3) + P(set 2 | ~ set 1)
12+
"""
13+
14+
fig, ax = plt.subplots()
15+
16+
tagged_rates = []
17+
for alpha in set_2_alpha.keys():
18+
set_2_inters_1 = set_2_alpha[alpha].intersection(set_1_alpha[alpha])
19+
set_3 = set_3_alpha[alpha]
20+
set_2_inters_comp_1 = set_2_alpha[alpha].intersection(comp_set_1_alpha[alpha])
21+
22+
set_tagged_fits = set_2_inters_1.union(set_3).union(set_2_inters_comp_1)
23+
tagged_rates.append(len(set_tagged_fits) / n_fits)
24+
25+
ax.plot(set_2_alpha.keys(), tagged_rates, label="P(inconsistent)")
26+
ax.legend()
27+
return fig
28+
29+
@figure
30+
def plot_probability_consistent(set_2_alpha, set_1_alpha, set_3_alpha, comp_set_1_alpha, comp_set_2_alpha, comp_set_3_alpha, n_fits):
31+
"""
32+
P(consistent) = 1 - P(inconsistent) ?= P(~set 2 | ~set 1) + P(~set 2 and ~set 3| set 1)
33+
"""
34+
fig, ax = plt.subplots()
35+
36+
untagged_rates = []
37+
untagged_rates_method2 = []
38+
for alpha in set_2_alpha.keys():
39+
set_2_inters_1 = set_2_alpha[alpha].intersection(set_1_alpha[alpha])
40+
set_3 = set_3_alpha[alpha]
41+
set_2_inters_comp_1 = set_2_alpha[alpha].intersection(comp_set_1_alpha[alpha])
42+
43+
comp_set_2_inters_comp_set1 = comp_set_2_alpha[alpha].intersection(comp_set_1_alpha[alpha])
44+
comp_set_2_inters_comp_set3 = comp_set_2_alpha[alpha].intersection(comp_set_3_alpha[alpha])
45+
comp_set_2_inters_comp_set3_inter_set_1 = comp_set_2_inters_comp_set3.intersection(set_1_alpha[alpha])
46+
47+
set_untagged_fits = comp_set_2_inters_comp_set1.union(comp_set_2_inters_comp_set3_inter_set_1)
48+
49+
50+
set_tagged_fits = set_2_inters_1.union(set_3).union(set_2_inters_comp_1)
51+
untagged_rates.append(1 - len(set_tagged_fits) / n_fits)
52+
53+
untagged_rates_method2.append(len(set_untagged_fits) / n_fits)
54+
55+
56+
ax.plot(set_2_alpha.keys(), untagged_rates, label="1 - P(inconsistent)")
57+
ax.plot(set_2_alpha.keys(), untagged_rates_method2, label="P(~set 2 | ~set 1) + P(~set 2 and ~set 3| set 1)")
58+
ax.legend()
59+
60+
return fig
61+
62+
63+
864
@figure
965
def plot_set1_vs_set3_alpha(set_1_alpha, set_3_alpha, weighted_dataset, n_fits):
1066
"""

0 commit comments

Comments
 (0)