View Javadoc

1   /*
2    * @(#)$Id: BatchResult.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	Represents the result with key figures, etc. of the
7    * 					batch process.
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date             Who         Reason
14   *
15   * Dec 26, 2006     ukurmann    Initial Release
16   * Mar 20, 2007     bsigner     Cleanup
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
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   * Represents the result with key figures, etc. of the batch process.
42   * 
43   * @version 1.0 Dec 2006
44   * @author Ueli Kurmann, igesture@uelikurmann.ch
45   * @author Beat Signer, signer@inf.ethz.ch
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      * Returns the number of correctly recognised gestures.
92      * 
93      * @return number of correctly recognised gestures
94      */
95     public int getNumberOfCorrects() {
96        return numberOfCorrects;
97     } // getNumberOfCorrects
98  
99  
100    /**
101     * Returns the number of incorrectly recognised gestures.
102     * 
103     * @return number of incorrectly recognised gestures.
104     */
105    public int getNumberOfErrors() {
106       return numberOfErrors;
107    } // getNumberOfErrors
108 
109 
110    /**
111     * Returns the number of gestures which are rejected correctly.
112     * 
113     * @return number of correctly rejected gestures.
114     */
115    public int getNumberOfRejectCorrect() {
116       return numberOfRejectCorrect;
117    } // getNumberOfRejectCorrect
118 
119 
120    /**
121     * Returns the number of rejected gestures which should have been recognised.
122     * 
123     * @return number of wrongly rejected gestures.
124     */
125    public int getNumberOfRejectError() {
126       return numberOfRejectError;
127    } // getNumberOfRejectError
128 
129 
130    /**
131     * Returns the size of the complete test set.
132     * 
133     * @return size of the test set.
134     */
135    public int getNumberOfSamples() {
136       return numberOfSamples;
137    } // getNumberOfSamples
138 
139 
140    /**
141     * Returns the number of samples which should be rejected.
142     * 
143     * @return number of samples which should be rejected.
144     */
145    public int getNumberOfNoise() {
146       return numberOfNoise;
147    } // getNumberOfNoise
148 
149 
150    /**
151     * Increases the number of errors.
152     * 
153     * @param className the name of the gesture class for which the number of
154     *            errors has to be increased.
155     */
156    public void incError(String className) {
157       numberOfErrors++;
158       getClassStatistic(className).incError();
159    } // incError
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     * Increases the number of correct recognitions.
173     * 
174     * @param className the name of the gesture class.
175     */
176    public void incCorrect(String className) {
177       numberOfCorrects++;
178       getClassStatistic(className).incCorrect();
179    } // incCorrect
180 
181 
182    /**
183     * Increments the number of correctly rejected gestures.
184     * 
185     * @param className the name of the gesture class.
186     */
187    public void incRejectCorrect(String className) {
188       numberOfRejectCorrect++;
189       getClassStatistic(className).incRejectCorrect();
190    } // incRejectCorrect
191 
192 
193    /**
194     * Increments the number of wrongly rejected gestures.
195     * 
196     * @param className the name of the gesture class.
197     */
198    public void incRejectError(String className) {
199       numberOfRejectError++;
200       getClassStatistic(className).incRejectError();
201    } // incRejectError
202 
203 
204    /**
205     * Computes the precision.
206     * 
207     * @return the precision.
208     */
209    public double getPrecision() {
210       return (double)numberOfCorrects / (numberOfCorrects + numberOfErrors);
211    } // getPrecision
212 
213 
214    /**
215     * Computes the recall.
216     * 
217     * @return the recall.
218     */
219    public double getRecall() {
220       return (double)numberOfCorrects / (numberOfCorrects + numberOfRejectError);
221    } // getRecall
222 
223 
224    /**
225     * Sets the start time to the current system time.
226     * 
227     */
228    public void setStartTime() {
229       this.startTime = System.currentTimeMillis();
230    } // setStartTime
231 
232 
233    /**
234     * Sets the end time to the current system time.
235     * 
236     */
237    public void setEndTime() {
238       this.endTime = System.currentTimeMillis();
239    } // setEndTime
240 
241 
242    /**
243     * Returns the running time in milliseconds.
244     * 
245     * @return the running time in milliseconds.
246     */
247    public long getRunningTime() {
248       return endTime - startTime;
249    } // getRunningTime
250 
251 
252    /**
253     * Returns the configuration.
254     * 
255     * @return the configuration.
256     */
257    public Configuration getConfiguration() {
258       return configuration;
259    } // getConfiguration
260 
261 
262    /**
263     * Returns a list of statistics.
264     * 
265     * @return the list of statistics.
266     */
267    public List<Statistic> getStatistics() {
268       return new ArrayList<Statistic>(classStatistics.values());
269    }
270 
271 }