Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java @ 5803:948be49754c5
Removed obsolete import.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 24 Apr 2013 09:10:48 +0200 |
parents | 2fe120e1e4df |
children |
rev | line source |
---|---|
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model.sq; |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
3 import de.intevation.flys.artifacts.math.GrubbsOutlier; |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
4 import de.intevation.flys.artifacts.math.StdDevOutlier; |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
5 |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.util.ArrayList; |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.List; |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
3188
1e46ced2bb57
SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3187
diff
changeset
|
9 import org.apache.commons.math.MathException; |
1e46ced2bb57
SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3187
diff
changeset
|
10 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
11 import org.apache.log4j.Logger; |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
12 |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 public class Outlier |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 { |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
15 private static Logger log = Logger.getLogger(Outlier.class); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
16 |
5396
aaf810d4ec82
Use new state 'outlier mehtod selection' in SQ-relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
4816
diff
changeset
|
17 private static final String GRUBBS = "outlier.method.grubbs"; |
4794
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
18 |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
19 //private static final String STD_DEV = "std-dev"; |
4794
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
20 |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 public interface Callback { |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
3566
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
23 void initialize(List<SQ> sqs) throws MathException; |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
24 |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 double eval(SQ sq); |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
3566
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
27 void iterationFinished( |
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
28 double stdDev, |
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
29 SQ outlier, |
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
30 List<SQ> remaining); |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 } // interface Callback |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
34 public static void detectOutliers( |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 Callback callback, |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 List<SQ> sqs, |
5396
aaf810d4ec82
Use new state 'outlier mehtod selection' in SQ-relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
4816
diff
changeset
|
37 double stdDevFactor, |
aaf810d4ec82
Use new state 'outlier mehtod selection' in SQ-relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
4816
diff
changeset
|
38 String method |
3188
1e46ced2bb57
SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3187
diff
changeset
|
39 ) |
1e46ced2bb57
SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3187
diff
changeset
|
40 throws MathException |
1e46ced2bb57
SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3187
diff
changeset
|
41 { |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
42 boolean debug = log.isDebugEnabled(); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
43 |
4794
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
44 if (method == null) { |
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
45 method = "std-dev"; |
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
46 } |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
47 |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
48 if (debug) { |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
49 log.debug("stdDevFactor: " + stdDevFactor); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
50 log.debug("method: " + method); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
51 } |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
52 |
3566
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
53 List<SQ> data = new ArrayList<SQ>(sqs); |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
55 double [] stdDev = new double[1]; |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
56 |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
57 boolean useGrubbs = method.equals(GRUBBS); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
58 |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
59 if (useGrubbs) { |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
60 stdDevFactor = Math.max(0d, Math.min(stdDevFactor/100d, 1d)); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
61 } |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
62 |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
63 List<Double> values = new ArrayList<Double>(data.size()); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
64 |
3566
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
65 while (data.size() > 2) { |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
3566
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
67 callback.initialize(data); |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
4794
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
69 for (SQ sq: data) { |
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
70 values.add(callback.eval(sq)); |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
73 Integer ndx = useGrubbs |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
74 ? GrubbsOutlier.findOutlier(values, stdDevFactor, stdDev) |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
75 : StdDevOutlier.findOutlier(values, stdDevFactor, stdDev); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
76 |
4794
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
77 if (ndx == null) { |
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
78 callback.iterationFinished(stdDev[0], null, data); |
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
79 break; |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
82 SQ outlier = data.remove(ndx.intValue()); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
83 if (debug) { |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
84 log.debug("stdDev: " + stdDev[0]); |
4816
846b0441f905
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4795
diff
changeset
|
85 log.debug("removed " + ndx + |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
86 "; S: " + outlier.getS() + " Q: " + outlier.getQ()); |
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
87 } |
4794
a7d080347ac3
MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents:
3572
diff
changeset
|
88 callback.iterationFinished(stdDev[0], outlier, data); |
4795
8ee270a3ef25
Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4794
diff
changeset
|
89 values.clear(); |
3566
8d0f06b76e09
S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
90 } |
3188
1e46ced2bb57
SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3187
diff
changeset
|
91 } |
3187
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
1e2733f749b5
SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |