1
2
3
4
5
6
7 package yawn.util;
8
9 /***
10 * Utility class that contains some usefull error metrics
11 *
12 * <p>$Id: ErrorUtils.java,v 1.4 2005/04/20 18:55:19 supermarti Exp $</p>
13 *
14 * @author Luis Martí (luis dot marti at uc3m dot es)
15 * @version $Revision: 1.4 $
16 */
17 public class ErrorUtils {
18
19 protected static void checkDimensions(Pattern[] desired, Pattern[] predictions) {
20 if (desired.length != predictions.length) {
21 throw new ArrayIndexOutOfBoundsException("Using arrays with different sizes.");
22 }
23 }
24
25 /***
26 *
27 * @param desired
28 * @param predictions
29 * @return the mean squared error
30 */
31 public static double meanSquaredError(Pattern[] desired, Pattern[] predictions) {
32 double res = 0;
33 checkDimensions(desired, predictions);
34 for (int i = 0; i < desired.length; i++) {
35 res += desired[i].dist(predictions[i]) / desired[i].size();
36 }
37 return res / desired.length;
38 }
39 }