changeset 3022:705d2058b682

FixA: Store the referenced QW for each km, too. flys-artifacts/trunk@4589 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 05 Jun 2012 14:56:57 +0000
parents 84a7314244b5
children e19ff9086035
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java
diffstat 3 files changed, 83 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Tue Jun 05 13:56:55 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Tue Jun 05 14:56:57 2012 +0000
@@ -31,11 +31,20 @@
 
     } // interface QWFactory
 
+    public static final QWFactory QW_FACTORY = new QWFactory() {
+        @Override
+        public QW create(double q, double w) {
+            return new QW(q, w);
+        }
+    };
+
+    protected boolean       checkOutliers;
     protected Function      function;
     protected QWFactory     qwFactory;
     protected double        chiSqr;
     protected double []     parameters;
     protected ArrayList<QW> removed;
+    protected QW []         referenced;
 
 
     public Fitting() {
@@ -43,13 +52,22 @@
     }
 
     public Fitting(Function function) {
-        this();
-        this.function = function;
+        this(function, QW_FACTORY);
     }
 
     public Fitting(Function function, QWFactory qwFactory) {
-        this(function);
-        this.qwFactory = qwFactory;
+        this(function, qwFactory, false);
+    }
+
+    public Fitting(
+        Function  function,
+        QWFactory qwFactory,
+        boolean   checkOutliers
+    ) {
+        this();
+        this.function      = function;
+        this.qwFactory     = qwFactory;
+        this.checkOutliers = checkOutliers;
     }
 
     public Function getFunction() {
@@ -60,6 +78,14 @@
         this.function = function;
     }
 
+    public boolean getCheckOutliers() {
+        return checkOutliers;
+    }
+
+    public void setCheckOutliers(boolean checkOutliers) {
+        this.checkOutliers = checkOutliers;
+    }
+
     public double getChiSquare() {
         return chiSqr;
     }
@@ -68,6 +94,7 @@
         chiSqr     = 0.0;
         parameters = null;
         removed.clear();
+        referenced = null;
     }
 
     public boolean hasOutliers() {
@@ -82,6 +109,10 @@
         return removed.toArray(new QW[removed.size()]);
     }
 
+    public QW [] referencedToArray() {
+        return referenced != null ? (QW [])referenced.clone() : null;
+    }
+
     public double [] getParameters() {
         return parameters;
     }
@@ -126,7 +157,7 @@
                 return false;
             }
 
-            if (qwFactory == null) {
+            if (!checkOutliers) {
                 break;
             }
 
@@ -162,6 +193,11 @@
             }
         }
 
+        referenced = new QW[xs.size()];
+        for (int i = 0; i < referenced.length; ++i) {
+            referenced[i] = qwFactory.create(xs.getQuick(i), ys.getQuick(i));
+        }
+
         chiSqr = lmo.getChiSquare();
 
         return true;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Tue Jun 05 13:56:55 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Tue Jun 05 14:56:57 2012 +0000
@@ -169,30 +169,27 @@
         final double [] qs = new double[eventColumns.size()];
         final double [] ws = new double[qs.length];
 
-        // Depending on preprocessing we need to find the outliers.
-        Fitting.QWFactory qwFactory = !preprocessing
-            ? null // No outliers
-            : new Fitting.QWFactory() {
-                @Override
-                public QW create(double q, double w) {
-                    // Check all the event columns for close match
-                    // and take the description and the date from meta.
-                    for (int i = 0; i < qs.length; ++i) {
-                        if (Math.abs(qs[i]-q) < EPSILON
-                        &&  Math.abs(ws[i]-w) < EPSILON) {
-                            Column column = eventColumns.get(i);
-                            return new QW(
-                                q, w,
-                                column.getDescription(),
-                                column.getDate());
-                        }
+        Fitting.QWFactory qwFactory = new Fitting.QWFactory() {
+            @Override
+            public QW create(double q, double w) {
+                // Check all the event columns for close match
+                // and take the description and the date from meta.
+                for (int i = 0; i < qs.length; ++i) {
+                    if (Math.abs(qs[i]-q) < EPSILON
+                    &&  Math.abs(ws[i]-w) < EPSILON) {
+                        Column column = eventColumns.get(i);
+                        return new QW(
+                            q, w,
+                            column.getDescription(),
+                            column.getDate());
                     }
-                    log.warn("cannot find column for (" + q + ", " + w + ")");
-                    return new QW(q, w);
                 }
-            };
+                log.warn("cannot find column for (" + q + ", " + w + ")");
+                return new QW(q, w);
+            }
+        };
 
-        Fitting fitting = new Fitting(func, qwFactory);
+        Fitting fitting = new Fitting(func, qwFactory, preprocessing);
 
         String [] parameterNames = func.getParameterNames();
 
@@ -205,7 +202,8 @@
             log.debug("number of kms: " + kms.length);
         }
 
-        KMIndex<QW []> outliers = new KMIndex<QW []>();
+        KMIndex<QW []> outliers   = new KMIndex<QW []>();
+        KMIndex<QW []> referenced = new KMIndex<QW []>(kms.length);
 
         int kmIndex             = results.columnIndex("km");
         int chiSqrIndex         = results.columnIndex("chi_sqr");
@@ -232,6 +230,8 @@
                 continue;
             }
 
+            referenced.add(km, fitting.referencedToArray());
+
             if (fitting.hasOutliers()) {
                 outliers.add(km, fitting.outliersToArray());
             }
@@ -259,9 +259,13 @@
             calculateAnalysisPeriods(func, results, overview);
 
         outliers.sort();
+        referenced.sort();
         analysisPeriods.sort();
 
-        FixResult fr = new FixResult(results, analysisPeriods, outliers);
+        FixResult fr = new FixResult(
+            results, 
+            referenced, outliers,
+            analysisPeriods);
 
         return new CalculationResult(fr, this);
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Tue Jun 05 13:56:55 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Tue Jun 05 14:56:57 2012 +0000
@@ -10,20 +10,23 @@
 implements   Serializable
 {
     protected Parameters                 parameters;
+    protected KMIndex<QW []>             referenced;
+    protected KMIndex<QW []>             outliers;
     protected KMIndex<AnalysisPeriod []> analysisPeriods;
-    protected KMIndex<QW []>             outliers;
 
     public FixResult() {
     }
 
     public FixResult(
         Parameters                 parameters,
-        KMIndex<AnalysisPeriod []> analysisPeriods,
-        KMIndex<QW []>             outliers
+        KMIndex<QW []>             referenced,
+        KMIndex<QW []>             outliers,
+        KMIndex<AnalysisPeriod []> analysisPeriods
     ) {
         this.parameters      = parameters;
+        this.referenced      = referenced;
+        this.outliers        = outliers;
         this.analysisPeriods = analysisPeriods;
-        this.outliers        = outliers;
     }
 
     public Parameters getParameters() {
@@ -42,6 +45,14 @@
         this.analysisPeriods = analysisPeriods;
     }
 
+    public KMIndex<QW []> getReferenced() {
+        return referenced;
+    }
+
+    public void setReferenced(KMIndex<QW []> referenced) {
+        this.referenced = referenced;
+    }
+
     public KMIndex<QW []> getOutliers() {
         return outliers;
     }

http://dive4elements.wald.intevation.org