comparison artifacts/src/main/java/org/dive4elements/river/artifacts/math/StdDevOutlier.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/math/StdDevOutlier.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.artifacts.math;
2
3 import java.util.List;
4
5 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
6
7 import org.apache.log4j.Logger;
8
9 public class StdDevOutlier
10 {
11 public static final double DEFAULT_FACTOR = 3;
12
13 private static Logger log = Logger.getLogger(StdDevOutlier.class);
14
15 protected StdDevOutlier() {
16 }
17
18 public static Integer findOutlier(List<Double> values) {
19 return findOutlier(values, DEFAULT_FACTOR, null);
20 }
21
22 public static Integer findOutlier(
23 List<Double> values,
24 double factor,
25 double [] stdDevResult
26 ) {
27 boolean debug = log.isDebugEnabled();
28
29 if (debug) {
30 log.debug("factor for std dev: " + factor);
31 }
32
33 int N = values.size();
34
35 if (debug) {
36 log.debug("Values to check: " + N);
37 }
38
39 if (N < 3) {
40 return null;
41 }
42
43 StandardDeviation stdDev = new StandardDeviation();
44
45 double maxValue = -Double.MAX_VALUE;
46 int maxIndex = -1;
47 for (int i = N-1; i >= 0; --i) {
48 double value = Math.abs(values.get(i));
49 stdDev.increment(value);
50 if (value > maxValue) {
51 maxValue = value;
52 maxIndex = i;
53 }
54 }
55
56 double sd = stdDev.getResult();
57
58 double accepted = factor * sd;
59
60 if (debug) {
61 log.debug("std dev: " + stdDev);
62 log.debug("accepted: " + accepted);
63 log.debug("max value: " + maxValue);
64 }
65
66 if (stdDevResult != null) {
67 stdDevResult[0] = sd;
68 }
69
70 return maxValue > accepted ? maxIndex : null;
71 }
72 }
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org