annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Outlier.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents af13ceeba52a
children 0a5239a1e46e
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5431
diff changeset
9 package org.dive4elements.river.artifacts.model.sq;
3187
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5431
diff changeset
11 import org.dive4elements.river.artifacts.math.GrubbsOutlier;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5431
diff changeset
12 import org.dive4elements.river.artifacts.math.StdDevOutlier;
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
13
3187
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 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
15 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
16
3188
1e46ced2bb57 SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3187
diff changeset
17 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
18
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
19 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
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 class Outlier
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 {
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
23 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
24
5396
aaf810d4ec82 Use new state 'outlier mehtod selection' in SQ-relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4816
diff changeset
25 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
26
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
27 //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
28
3187
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public interface Callback {
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
3566
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
31 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
32
3187
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 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
34
3566
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
35 void iterationFinished(
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
36 double stdDev,
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
37 SQ outlier,
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
38 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
39
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 } // interface Callback
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 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
43 Callback callback,
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 List<SQ> sqs,
5396
aaf810d4ec82 Use new state 'outlier mehtod selection' in SQ-relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4816
diff changeset
45 double stdDevFactor,
aaf810d4ec82 Use new state 'outlier mehtod selection' in SQ-relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4816
diff changeset
46 String method
3188
1e46ced2bb57 SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3187
diff changeset
47 )
1e46ced2bb57 SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3187
diff changeset
48 throws MathException
1e46ced2bb57 SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3187
diff changeset
49 {
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
50 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
51
4794
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
52 if (method == null) {
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
53 method = "std-dev";
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
54 }
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
55
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
56 if (debug) {
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
57 log.debug("stdDevFactor: " + stdDevFactor);
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
58 log.debug("method: " + method);
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
59 }
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
60
3566
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
61 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
62
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
63 double [] stdDev = new double[1];
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
64
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
65 boolean useGrubbs = method.equals(GRUBBS);
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
66
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
67 if (useGrubbs) {
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
68 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
69 }
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
70
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
71 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
72
3566
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
73 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
74
3566
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
75 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
76
4794
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
77 for (SQ sq: data) {
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
78 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
79 }
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
81 Integer ndx = useGrubbs
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
82 ? GrubbsOutlier.findOutlier(values, stdDevFactor, stdDev)
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
83 : StdDevOutlier.findOutlier(values, stdDevFactor, stdDev);
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
84
4794
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
85 if (ndx == null) {
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
86 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
87 break;
3187
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 }
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
90 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
91 if (debug) {
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
92 log.debug("stdDev: " + stdDev[0]);
4816
846b0441f905 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4795
diff changeset
93 log.debug("removed " + ndx +
4795
8ee270a3ef25 Small code cleanups in S/Q outlier tests.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
94 "; 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
95 }
4794
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3572
diff changeset
96 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
97 values.clear();
3566
8d0f06b76e09 S/Q relation: Fixed flys/issue748
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
98 }
3188
1e46ced2bb57 SQ: Added fitting shell for SQ curves.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3187
diff changeset
99 }
3187
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 }
1e2733f749b5 SQ: Added specialized outlier test for the S/Q relation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org