diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java @ 3552:1df6984628c3

S/Q: Extented the result data model of the S/Q calculation to store the curve coefficients for each iteration step of the outlier elimination. flys-artifacts/trunk@5146 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 27 Jul 2012 12:36:09 +0000
parents 49fe2ed03c12
children 8d0f06b76e09
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java	Fri Jul 27 08:36:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java	Fri Jul 27 12:36:09 2012 +0000
@@ -8,23 +8,27 @@
 
 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
 
+import org.apache.log4j.Logger;
+
 public class Outlier
 {
+    private static Logger log = Logger.getLogger(Outlier.class);
+
     public static final int MAX_ITERATIONS = 1000;
 
     public interface Callback {
 
+        void initialize(Iterator<SQ> good) throws MathException;
+
         double eval(SQ sq);
 
-        void iteration(int i);
-
         void outlier(SQ sq);
 
+        void remaining(SQ sq);
+
         void standardDeviation(double stdDev);
 
-        void reinitialize(Iterator<SQ> good) throws MathException;
-
-        void finished();
+        void iterationFinished();
 
     } // interface Callback
 
@@ -37,13 +41,19 @@
         }
     } // class EvalSQ
 
-    public static SQ [] detectOutliers(
+    public static void detectOutliers(
         Callback callback,
         List<SQ> sqs,
         double   stdDevFactor
     )
     throws MathException
     {
+        boolean debug = log.isDebugEnabled();
+
+        if (debug) {
+            log.debug("stdDevFactor: " + stdDevFactor);
+        }
+
         List<EvalSQ> data = new ArrayList<EvalSQ>(sqs.size());
 
         for (SQ sq: sqs) {
@@ -52,7 +62,9 @@
 
         List<EvalSQ> good = new ArrayList<EvalSQ>(sqs.size());
 
-        for (int i = 1; i <= MAX_ITERATIONS && data.size() > 2; ++i) {
+        for (int i = 0; i < MAX_ITERATIONS && data.size() > 2; ++i) {
+
+            callback.initialize(asSQIterator(data));
 
             StandardDeviation stdDev = new StandardDeviation();
 
@@ -66,38 +78,35 @@
 
             double accepted = stdDevFactor * sd;
 
-            callback.iteration(i);
+            if (debug) {
+                log.debug("accepted: " + accepted);
+            }
 
             for (EvalSQ esq: data) {
+                if (debug) {
+                    log.debug(" value: " + Math.abs(esq.value));
+                }
+
                 if (Math.abs(esq.value) > accepted) {
                     callback.outlier(esq.sq);
                 }
                 else {
+                    callback.remaining(esq.sq);
                     good.add(esq);
                 }
             }
 
+            callback.iterationFinished();
+
             if (good.size() == data.size()) {
                 break;
             }
 
-            callback.reinitialize(asSQIterator(good));
-
             List<EvalSQ> tmp = good;
             good = data;
             data = tmp;
             good.clear();
         }
-
-        callback.finished();
-
-        SQ [] result = new SQ[good.size()];
-
-        for (int i = 0; i < result.length; ++i) {
-            result[i] = good.get(i).sq;
-        }
-
-        return result;
     }
 
     protected static Iterator<SQ> asSQIterator(List<EvalSQ> esqs) {

http://dive4elements.wald.intevation.org