-
Notifications
You must be signed in to change notification settings - Fork 3
/
jmx_stats_plots.py
executable file
·134 lines (93 loc) · 3.5 KB
/
jmx_stats_plots.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
#!/usr/bin/python3
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
from ecgdetectors import Detectors
import json
experiment_names = ['sitting','maths','walking','hand_bike','jogging']
einth = 'einthoven_ii'
cs = 'chest_strap_V2_V1'
detectors = Detectors()
det_names = [i[1].__name__ for i in detectors.get_detector_list()]
plot_names = [i[0] for i in detectors.get_detector_list()]
resultsdir = "results"
alpha = 0.05
minjmx = 90 # %
def get_jmx(detector_name, leads, experiment):
f = open(resultsdir+"/jmx_"+detector_name+".json","r")
js = f.read()
data = json.loads(js)
s = []
for i in data[leads][experiment]:
if i["jmx"]:
s.append(i["jmx"]*100)
return np.array(s)
def get_result(det, leads, experiment):
m = []
s = []
for det in det_names:
print(det,experiment,get_jmx(det, leads, experiment))
m.append(np.mean(get_jmx(det, leads, experiment)))
s.append(np.std(get_jmx(det, leads, experiment)))
return np.array(m),np.array(s)
def print_stat(p):
if p == None:
print('--- & ',end='')
return
s = ""
if p < alpha:
s = "*"
print('{:03.2f}{} & '.format(p,s),end='')
def calc_stats(leads, experiment):
print("Stats:",leads, experiment)
print(" & ",end='')
for det1 in det_names:
print(det1," & ",end='')
print("\\\\")
for det1 in det_names:
r1 = get_jmx(det1, leads, experiment)
t,p = stats.ttest_1samp(r1,minjmx,alternative='greater')
print_stat(p)
print()
def double_plot(data1, std1, data2, std2, y_label, legend1, legend2, title=None):
fig, ax = plt.subplots()
x_pos = np.arange(len(plot_names))
fig.set_size_inches(10, 7)
width = 0.4
rects1 = ax.bar(x_pos, data1, width, yerr=std1, alpha=0.5, ecolor='black', capsize=10)
rects2 = ax.bar(x_pos+width, data2, width, yerr=std2, alpha=0.5, ecolor='black', capsize=10)
ax.set_ylim([0,150])
ax.set_ylabel(y_label)
ax.set_xlabel('Detector')
ax.set_xticks(x_pos + width / 2)
ax.set_xticklabels(plot_names)
ax.legend((rects1[0], rects2[0]), (legend1, legend2))
if title!=None:
ax.set_title(title)
plt.tight_layout()
return rects1, rects2
def print_result(title,data,std,legend):
print("JMX Score:",title)
for i in zip(legend,data,std):
print("{}: {:1.1f}+/-{:1.1f}".format(i[0],i[1],i[2]))
print()
cs_sitting_avg,cs_sitting_std = get_result(det_names, cs, 'sitting')
einthoven_sitting_avg,einthoven_sitting_std = get_result(det_names, einth, 'sitting')
cs_jogging_avg,cs_jogging_std = get_result(det_names, cs, 'jogging')
einthoven_jogging_avg,einthoven_jogging_std = get_result(det_names, einth, 'jogging')
print_result('sitting Einthoven',einthoven_sitting_avg,einthoven_sitting_std,det_names)
print_result('jogging Einthoven',einthoven_jogging_avg,einthoven_jogging_std,det_names)
print_result('sitting chest strap',cs_sitting_avg,cs_sitting_std,det_names)
print_result('jogging chest strap',cs_jogging_avg,cs_jogging_std,det_names)
double_plot(einthoven_sitting_avg, einthoven_sitting_std,
einthoven_jogging_avg,einthoven_jogging_std,
'JMX (%)', 'Sitting', 'Jogging', 'Einthoven')
double_plot(cs_sitting_avg, cs_sitting_std,
cs_jogging_avg, cs_jogging_std,
'JMX (%)', 'Sitting', 'Jogging', 'Chest strap')
calc_stats(einth,"sitting")
calc_stats(einth,"jogging")
print()
calc_stats(cs,"sitting")
calc_stats(cs,"jogging")
plt.show()