-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.vue
206 lines (195 loc) · 5.81 KB
/
App.vue
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<style>
canvas {
width: 100%;
}
</style>
<template>
<v-app>
<v-app-bar app flat>
<v-toolbar-title> Bayesian Binomial Test Calculator</v-toolbar-title>
<v-spacer> </v-spacer>
<v-toolbar-items>
<v-btn text class="text-capitalize" href="https://github.com/tohtsky/bayesian-binomial-test">
<v-icon> mdi-github</v-icon>
Source code
</v-btn>
</v-toolbar-items>
</v-app-bar>
<v-main>
<v-container>
<v-row>
<v-col cols="12" lg="4">
<v-container>
<v-row>
<v-col cols="12">
<Group v-model="a" groupName="A" :posInitial="30" :totInitial="100"></Group>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
<Group v-model="b" groupName="B" :posInitial="b_init.pos" :totInitial="b_init.tot"></Group>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
<v-card outlined>
<v-card-title> Detailed settings </v-card-title>
<v-card-text>
<v-row>
<v-col cols="6">
<v-text-field label="alpha" type="Number" :error-messages="alphaError" v-model.number="alpha">
</v-text-field>
</v-col>
<v-col cols="6">
<v-text-field label="beta" type="Number" v-model.number="beta" :error-messages="betaError">
</v-text-field>
</v-col>
<v-col cols="6">
<v-text-field label="Number of samples" type="Number" v-model.number="nSamples"
:error-messages="nSamplesError"></v-text-field>
</v-col>
<v-col cols="6">
<v-text-field label="Random seed" type="Number" v-model.number="randomSeed"
:error-messages="randomSeedError"></v-text-field>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</v-col>
<v-col cols="12" lg="8" :style="{ opacity: payload === null ? 0.4 : 1.0 }">
<v-row>
<v-col cols="12">
<div class="text-center pt-4 text-h5">
Probability of B being the winner:
{{ (100 * this.result).toFixed(2) }} %
</div>
<v-row class="pt-4">
<v-col cols="1"></v-col>
<v-col cols="10">
<canvas ref="canvas_a_b" :width="800 * dpr" :height="300 * dpr"></canvas>
</v-col>
<v-col cols="1"></v-col>
<v-col cols="1"></v-col>
<v-col cols="10">
<canvas ref="canvas_diff" :width="800 * dpr" :height="300 * dpr"></canvas>
</v-col>
<v-col cols="1"></v-col>
</v-row>
</v-col>
</v-row>
</v-col>
</v-row>
</v-container>
</v-main>
</v-app>
</template>
<script>
import { compute } from "./bayesian-wasm/pkg";
import Group from "./components/Group.vue";
export default {
data() {
return {
a: null,
b: null,
a_init: {
tot: 100,
pos: 30,
},
b_init: {
tot: 10,
pos: 5,
},
alpha: 1.0,
alphaError: [],
beta: 1.0,
betaError: [],
nSamples: 100000,
nSamplesError: [],
randomSeed: 0,
randomSeedError: [],
n_bins: 100,
result: null,
dpr: 3,
};
},
computed: {
payload() {
let invalid = false;
if (this.a === null) invalid = true;
if (this.b === null) invalid = true;
let alpha = parseFloat(this.alpha);
let beta = parseFloat(this.beta);
let nSamples = parseFloat(this.nSamples, 10);
let randomSeed = parseFloat(this.randomSeed, 10);
if (isNaN(alpha) || alpha <= 0) {
this.alphaError = ["valid, positive floating number required."];
invalid = true;
} else {
this.alphaError = null;
}
if (isNaN(beta) || beta <= 0) {
this.betaError = ["valid, positive floating number required."];
invalid = true;
} else {
this.betaError = [];
}
if (isNaN(nSamples) || nSamples <= 0 || !Number.isInteger(nSamples)) {
this.nSamplesError = ["This field must be a strictly positive integer."];
invalid = true;
} else {
this.nSamplesError = [];
}
if (isNaN(randomSeed) || randomSeed < 0 || !Number.isInteger(randomSeed)) {
this.randomSeedError = ["This field must be a non-negative integer."];
invalid = true;
} else {
this.randomSeedError = [];
}
if (invalid) {
return null;
}
let data = {
prior_pos: alpha,
prior_neg: beta,
a_tot: this.a.tot,
a_pos: this.a.pos,
b_tot: this.b.tot,
b_pos: this.b.pos,
n_samples: nSamples,
n_bins: this.n_bins,
random_seed: randomSeed,
};
return JSON.stringify(data);
},
},
watch: {
payload(nv) {
this.compute(nv);
},
},
methods: {
async compute(payload) {
console.log(payload);
if (payload === null) {
return;
}
let res = compute(
payload,
this.dpr,
this.$refs.canvas_a_b,
this.$refs.canvas_diff
);
this.result = res;
},
},
async mounted() {
//this.compute(this.payload);
},
components: {
Group,
},
};
</script>