-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_normal.py
188 lines (159 loc) · 4.36 KB
/
test_normal.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import pytest
from bayesian_testing.experiments import NormalDataTest
@pytest.fixture
def norm_test():
norm = NormalDataTest()
norm.add_variant_data(
"A",
[
11.8,
12.2,
12.4,
9.5,
2.2,
3.3,
16.2,
4.9,
12.4,
6.8,
8.7,
9.8,
5.4,
9.0,
15.0,
12.3,
9.6,
12.5,
9.1,
10.2,
],
m_prior=9,
)
norm.add_variant_data(
"B",
[
10.6,
5.1,
9.4,
11.2,
2.0,
13.4,
14.1,
15.4,
16.3,
11.7,
7.3,
6.8,
8.2,
16.2,
10.8,
7.1,
12.2,
11.2,
],
w_prior=0.03,
)
norm.add_variant_data(
"C",
[
25.3,
10.3,
24.7,
-8.1,
8.4,
10.3,
14.8,
13.4,
11.5,
-4.7,
5.3,
7.4,
17.2,
15.4,
13.0,
12.9,
19.2,
11.6,
0.4,
5.7,
23.5,
15.2,
],
b_prior_ig=2,
)
norm.add_variant_data_agg("A", 20, 193.3, 2127.71, replace=False)
norm.add_variant_data("D", [0, 10.7, 0, 8, 0, 0, 0, 0, 0, 11.22])
norm.add_variant_data("D", [0, 10.7, 0, 8, 0, 0, 0, 0, 0, 11.22], replace=False)
norm.add_variant_data("D", [0, 10.7, 0, 8, 0, 0, 0, 0, 0, 11.22], replace=True)
norm.delete_variant("D")
return norm
def test_variants(norm_test):
assert norm_test.variant_names == ["A", "B", "C"]
def test_totals(norm_test):
assert norm_test.totals == [40, 18, 22]
def test_sum_values(norm_test):
assert norm_test.sum_values == [386.6, 188.99999999999997, 252.69999999999996]
def test_sum_values_2(norm_test):
assert norm_test.sum_values_2 == [4255.42, 2244.8200000000006, 4421.87]
def test_m_priors(norm_test):
assert norm_test.m_priors == [9, 1, 1]
def test_a_priors_ig(norm_test):
assert norm_test.a_priors_ig == [0, 0, 0]
def test_b_priors_ig(norm_test):
assert norm_test.b_priors_ig == [0, 0, 2]
def test_w_priors(norm_test):
assert norm_test.w_priors == [0.01, 0.03, 0.01]
def test_probabs_of_being_best(norm_test):
pbbs = norm_test.probabs_of_being_best(sim_count=20000, seed=52)
assert pbbs == {"A": 0.05105, "B": 0.27935, "C": 0.6696}
def test_expected_loss(norm_test):
loss = norm_test.expected_loss(sim_count=20000, seed=52)
assert loss == {"A": 2.2696341, "B": 1.4580033, "C": 0.4464154}
def test_credible_intervals_95(norm_test):
ci = norm_test.credible_intervals(sim_count=20000, seed=52)
assert ci == {
"A": [8.5300072, 10.8231841],
"B": [8.5577171, 12.3448628],
"C": [7.8915125, 15.1179586],
}
def test_credible_intervals_99(norm_test):
ci = norm_test.credible_intervals(sim_count=20000, seed=52, interval_alpha=0.99)
assert ci == {
"A": [8.1196181, 11.2023581],
"B": [7.8792145, 13.0964176],
"C": [6.5669908, 16.5226358],
}
def test_evaluate(norm_test):
eval_report = norm_test.evaluate(sim_count=20000, seed=52)
assert eval_report == [
{
"variant": "A",
"totals": 40,
"sum_values": 386.6,
"avg_values": 9.665,
"posterior_mean": 9.66483,
"credible_interval": [8.5300072, 10.8231841],
"prob_being_best": 0.05105,
"expected_loss": 2.2696341,
},
{
"variant": "B",
"totals": 18,
"sum_values": 189.0,
"avg_values": 10.5,
"posterior_mean": 10.48419,
"credible_interval": [8.5577171, 12.3448628],
"prob_being_best": 0.27935,
"expected_loss": 1.4580033,
},
{
"variant": "C",
"totals": 22,
"sum_values": 252.7,
"avg_values": 11.48636,
"posterior_mean": 11.4816,
"credible_interval": [7.8915125, 15.1179586],
"prob_being_best": 0.6696,
"expected_loss": 0.4464154,
},
]