annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java @ 9646:0380717105ba

Implemented alternative fitting strategy for Log-Linear function.
author Gernot Belger <g.belger@bjoernsen.de>
date Mon, 02 Dec 2019 17:56:15 +0100
parents bc50ecfc58c5
children
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: 4794
diff changeset
9 package org.dive4elements.river.artifacts.model.fixings;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
3107
cbf308f5c41b FixA: Store the standard deviation of delta Ws of reference points into parameters, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3096
diff changeset
11 import java.util.ArrayList;
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
12 import java.util.Date;
3107
cbf308f5c41b FixA: Store the standard deviation of delta Ws of reference points into parameters, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3096
diff changeset
13 import java.util.List;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
4794
a7d080347ac3 MINFO: Allow two methods for outlier test in SQ relation.
Raimund Renkert <rrenkert@intevation.de>
parents: 3729
diff changeset
15 import org.apache.log4j.Logger;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
16 import org.dive4elements.river.artifacts.math.GrubbsOutlier;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
17 import org.dive4elements.river.artifacts.math.fitting.Function;
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
18 import org.dive4elements.river.artifacts.math.fitting.LogLinearAlternative;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
9348
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
20 public class Fitting {
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 private static Logger log = Logger.getLogger(Fitting.class);
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 /** Use instance of this factory to find meta infos for outliers. */
3096
d7b0f52d6d04 FixA: Calculate Delta W(t) for reference points, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3073
diff changeset
24 public interface QWDFactory {
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
25 QWD create(double q, double w, double deltaW, boolean isOutlier);
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 }
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
28 private final double chiSqr;
3022
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
29
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
30 private final double[] parameters;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
32 private final double standardDeviation;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
34 private final double maxQ;
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
35
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
36 public Fitting(final double[] parameters, final double standardDeviation, final double chiSqr, final double maxQ) {
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
37 this.parameters = parameters;
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
38 this.standardDeviation = standardDeviation;
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
39 this.chiSqr = chiSqr;
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
40 this.maxQ = maxQ;
3022
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
41 }
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
42
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 public double getChiSquare() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
44 return this.chiSqr;
3022
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
45 }
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
46
3065
ee653971fa84 FixA: Figure out max Q during fitting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3030
diff changeset
47 public double getMaxQ() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
48 return this.maxQ;
3065
ee653971fa84 FixA: Figure out max Q during fitting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3030
diff changeset
49 }
ee653971fa84 FixA: Figure out max Q during fitting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3030
diff changeset
50
9348
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
51 public double[] getParameters() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
52 return this.parameters;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
3107
cbf308f5c41b FixA: Store the standard deviation of delta Ws of reference points into parameters, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3096
diff changeset
55 public double getStandardDeviation() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
56 return this.standardDeviation;
3107
cbf308f5c41b FixA: Store the standard deviation of delta Ws of reference points into parameters, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3096
diff changeset
57 }
cbf308f5c41b FixA: Store the standard deviation of delta Ws of reference points into parameters, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3096
diff changeset
58
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
59 public static Fitting fit(final FixResultColumns resultColumns, final double km, final Function function, final boolean checkOutliers,
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
60 final List<FixingColumnWithData> eventColumns) {
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
62 final int numEvents = eventColumns.size();
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
63 final List<FittingData> data = new ArrayList<>(numEvents);
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
65 final double[] wTemp = new double[1];
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
66
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
67 for (final FixingColumnWithData event : eventColumns) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
68
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
69 final double q = event.getQ(km);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
70 if (!Double.isNaN(q)) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
71 final boolean isInterpolated = !event.getW(km, wTemp, 0);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
72 final double w = wTemp[0];
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
73
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
74 if (!Double.isNaN(w))
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
75 data.add(new FittingData(event, w, q, isInterpolated));
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
79 if (data.size() < 2) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
80 log.warn("Not enough data for fitting.");
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
81 return null;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 }
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
84 final List<FittingData> outliers = new ArrayList<>(data.size());
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4794
diff changeset
86 org.dive4elements.river.artifacts.math.Function instance = null;
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
87 Fitting fitting = null;
3202
307842cf8d9e FixA: Make fitting more tolerant.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3127
diff changeset
88
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
89 final IFittingOperation operation = createOperation(function);
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 for (;;) {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
91
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
92 fitting = operation.execute(data);
3202
307842cf8d9e FixA: Make fitting more tolerant.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3127
diff changeset
93
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
94 if (fitting == null) {
7300
83bb52fa0c32 (issue1529) Be more tolerant in the fitting.
Andre Heinecke <aheinecke@intevation.de>
parents: 6868
diff changeset
95 /*
9348
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
96 * log.debug("Parameters is null");
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
97 * for (int i = 0, N = xs.size(); i < N; ++i) {
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
98 * log.debug("DATA: " + xs.getQuick(i) + " " + ys.getQuick(i));
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
99 * }
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
100 */
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
101 return null;
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
9628
bc50ecfc58c5 undo unwanted commit
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9627
diff changeset
103
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
104 // This is the parameterized function for a given km.
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
105 final double[] parameters = fitting.getParameters();
3127
71484036b6ae FixA: Moved function instantiation to always have a valid function instance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3107
diff changeset
106 instance = function.instantiate(parameters);
71484036b6ae FixA: Moved function instantiation to always have a valid function instance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3107
diff changeset
107
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
108 if (!checkOutliers)
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 break;
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
111 /* find the outlier */
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
112 final List<Double> inputs = new ArrayList<>(data.size());
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
113 for (final FittingData fittingData : data) {
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
115 double y = instance.value(fittingData.q);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
116 if (Double.isNaN(y))
3565
b136113dad53 FixA: Only evict only one(!) data point as outlier before recalculating the function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3203
diff changeset
117 y = Double.MAX_VALUE;
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
118
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
119 inputs.add(Double.valueOf(fittingData.w - y));
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
122 final Integer outlier = GrubbsOutlier.findOutlier(inputs);
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
123 if (outlier == null)
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 break;
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
126 final int idx = outlier.intValue();
3066
4c22194b733a Some minor bugfixes in fix analysis calculation and some more debug output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3065
diff changeset
127
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
128 // outliers.add(qwdFactory.create(xs.getQuick(idx), ys.getQuick(idx), Double.NaN, true));
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
129 final FittingData removed = data.remove(idx);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
130 outliers.add(removed);
3022
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
131 }
705d2058b682 FixA: Store the referenced QW for each km, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3011
diff changeset
132
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
133 /* now build result data */
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
134 final List<QWD> qwds = new ArrayList<>(data.size());
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
135
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
136 /* calculate dW of outliers against the resulting function and add them to results */
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
137 for (final FittingData outlier : outliers) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
138 final QWD qwd = createQWD(outlier, instance, true);
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
139 qwds.add(qwd);
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
140 resultColumns.addQWD(outlier.event, km, qwd);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
141 }
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
142
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
143 /*
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
144 * calculate dW of used values against the resulting function and add them to results
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
145 */
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
146 for (final FittingData fittingData : data) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
147
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
148 final QWD qwd = createQWD(fittingData, instance, false);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
149 qwds.add(qwd);
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
150 resultColumns.addQWD(fittingData.event, km, qwd);
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
151 }
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
152
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
153 return fitting;
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
154 }
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
155
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
156 private static IFittingOperation createOperation(final Function function) {
9360
ddcd52d239cd Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents: 9348
diff changeset
157
9646
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
158 if (function instanceof LogLinearAlternative)
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
159 return new LogLinearFittingOperation((LogLinearAlternative) function);
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
160
0380717105ba Implemented alternative fitting strategy for Log-Linear function.
Gernot Belger <g.belger@bjoernsen.de>
parents: 9628
diff changeset
161 return new LevenbergMarquardtFittingOperation(function);
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
162 }
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
163
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
164 private static QWD createQWD(final FittingData data, final org.dive4elements.river.artifacts.math.Function function, final boolean isOutlier) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
165
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
166 final FixingColumnWithData event = data.event;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
167 final Date date = event.getDate();
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
168 final boolean isInterpolated = data.isInterpolated;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
169
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
170 final double w = data.w;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
171 final double q = data.q;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
172 final double dw = (w - function.value(q)) * 100.0;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
173
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
174 return new QWD(q, w, date, isInterpolated, dw, isOutlier);
3011
ab81ffd1343e FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 }
9348
a3f318347707 Show wq outliers within same thems with different symbol: not ready yet
gernotbelger
parents: 7300
diff changeset
176 }

http://dive4elements.wald.intevation.org