Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/StdDevOutlier.java @ 4794:a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
* Methods can be switched as option in conf.xml.
* Methods:
- Find outliers via multiples of the standard deviation.
- Grubbs (used in Fix-Analysis)
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 11 Jan 2013 13:57:38 +0100 |
parents | |
children | 8ee270a3ef25 |
comparison
equal
deleted
inserted
replaced
4793:c0d6391bec6f | 4794:a7d080347ac3 |
---|---|
1 package de.intevation.flys.artifacts.math; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.commons.math.MathException; | |
6 | |
7 import org.apache.commons.math.distribution.TDistributionImpl; | |
8 | |
9 import org.apache.commons.math.stat.descriptive.moment.Mean; | |
10 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 | |
14 import de.intevation.flys.artifacts.model.sq.SQ; | |
15 | |
16 public class StdDevOutlier | |
17 { | |
18 public static final double EPSILON = 1e-5; | |
19 | |
20 public static final double DEFAULT_FACTOR = 3; | |
21 | |
22 private static Logger log = Logger.getLogger(StdDevOutlier.class); | |
23 | |
24 protected StdDevOutlier() { | |
25 } | |
26 | |
27 public static Integer findOutlier(List<Double> values) { | |
28 return findOutlier(values, DEFAULT_FACTOR, null); | |
29 } | |
30 | |
31 public static Integer findOutlier(List<Double> values, double factor, double[] stdDevResult) { | |
32 boolean debug = log.isDebugEnabled(); | |
33 | |
34 if (debug) { | |
35 log.debug("factor for std dev: " + factor); | |
36 } | |
37 | |
38 int N = values.size(); | |
39 | |
40 if (debug) { | |
41 log.debug("Values to check: " + N); | |
42 } | |
43 | |
44 if (values.size() < 3) { | |
45 return null; | |
46 } | |
47 | |
48 StandardDeviation stdDev = new StandardDeviation(); | |
49 | |
50 double maxValue = -Double.MAX_VALUE; | |
51 int maxIndex = -1; | |
52 int ndx = 0; | |
53 for (int i = values.size()-1; i >= 0; --i) { | |
54 double value = Math.abs(values.get(i)); | |
55 stdDev.increment(value); | |
56 if (value > maxValue) { | |
57 maxValue = value; | |
58 maxIndex = ndx; | |
59 } | |
60 ++ndx; | |
61 } | |
62 | |
63 double sd = stdDev.getResult(); | |
64 | |
65 double accepted = factor * sd; | |
66 | |
67 if (debug) { | |
68 log.debug("std dev: " + stdDev); | |
69 log.debug("accepted: " + accepted); | |
70 log.debug("max value: " + maxValue); | |
71 } | |
72 if (stdDevResult != null) { | |
73 stdDevResult[0] = sd; | |
74 } | |
75 return maxValue > accepted ? maxIndex : null; | |
76 } | |
77 } | |
78 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |