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 package org.ximtec.igesture.batch;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 import org.ximtec.igesture.configuration.Configuration;
36 import org.ximtec.igesture.core.GestureClass;
37 import org.ximtec.igesture.core.TestSet;
38
39
40
41
42
43
44
45
46
47 public class BatchResult {
48
49 private int numberOfSamples;
50
51 private int numberOfNoise;
52
53 private int numberOfRejectError;
54
55 private int numberOfRejectCorrect;
56
57 private int numberOfErrors;
58
59 private int numberOfCorrects;
60
61 private long startTime;
62
63 private long endTime;
64
65 private Map<String, Statistic> classStatistics;
66
67 private Configuration configuration;
68
69
70 public BatchResult(TestSet testSet, Configuration configuration) {
71 this.numberOfCorrects = 0;
72 this.numberOfRejectError = 0;
73 this.numberOfRejectCorrect = 0;
74 this.numberOfErrors = 0;
75 this.numberOfNoise = testSet.getNoiseSize();
76 this.numberOfSamples = testSet.getNumberOfSamples();
77 this.configuration = configuration;
78
79 this.classStatistics = new HashMap<String, Statistic>();
80
81 for (GestureClass gestureClass : configuration.getGestureSet()
82 .getGestureClasses()) {
83 this.classStatistics.put(gestureClass.getName(), new Statistic(gestureClass));
84 }
85
86 this.classStatistics.put(TestSet.NOISE, new Statistic(new GestureClass(TestSet.NOISE)));
87 }
88
89
90
91
92
93
94
95 public int getNumberOfCorrects() {
96 return numberOfCorrects;
97 }
98
99
100
101
102
103
104
105 public int getNumberOfErrors() {
106 return numberOfErrors;
107 }
108
109
110
111
112
113
114
115 public int getNumberOfRejectCorrect() {
116 return numberOfRejectCorrect;
117 }
118
119
120
121
122
123
124
125 public int getNumberOfRejectError() {
126 return numberOfRejectError;
127 }
128
129
130
131
132
133
134
135 public int getNumberOfSamples() {
136 return numberOfSamples;
137 }
138
139
140
141
142
143
144
145 public int getNumberOfNoise() {
146 return numberOfNoise;
147 }
148
149
150
151
152
153
154
155
156 public void incError(String className) {
157 numberOfErrors++;
158 getClassStatistic(className).incError();
159 }
160
161
162 private Statistic getClassStatistic(String className) {
163 Statistic classStatistic = classStatistics.get(className);
164 if (classStatistic == null) {
165 classStatistic = classStatistics.get(TestSet.NOISE);
166 }
167 return classStatistic;
168 }
169
170
171
172
173
174
175
176 public void incCorrect(String className) {
177 numberOfCorrects++;
178 getClassStatistic(className).incCorrect();
179 }
180
181
182
183
184
185
186
187 public void incRejectCorrect(String className) {
188 numberOfRejectCorrect++;
189 getClassStatistic(className).incRejectCorrect();
190 }
191
192
193
194
195
196
197
198 public void incRejectError(String className) {
199 numberOfRejectError++;
200 getClassStatistic(className).incRejectError();
201 }
202
203
204
205
206
207
208
209 public double getPrecision() {
210 return (double)numberOfCorrects / (numberOfCorrects + numberOfErrors);
211 }
212
213
214
215
216
217
218
219 public double getRecall() {
220 return (double)numberOfCorrects / (numberOfCorrects + numberOfRejectError);
221 }
222
223
224
225
226
227
228 public void setStartTime() {
229 this.startTime = System.currentTimeMillis();
230 }
231
232
233
234
235
236
237 public void setEndTime() {
238 this.endTime = System.currentTimeMillis();
239 }
240
241
242
243
244
245
246
247 public long getRunningTime() {
248 return endTime - startTime;
249 }
250
251
252
253
254
255
256
257 public Configuration getConfiguration() {
258 return configuration;
259 }
260
261
262
263
264
265
266
267 public List<Statistic> getStatistics() {
268 return new ArrayList<Statistic>(classStatistics.values());
269 }
270
271 }