comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java @ 3107:cbf308f5c41b

FixA: Store the standard deviation of delta Ws of reference points into parameters, too. flys-artifacts/trunk@4706 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Jun 2012 15:28:40 +0000
parents d7b0f52d6d04
children 71484036b6ae
comparison
equal deleted inserted replaced
3106:23de6d678fba 3107:cbf308f5c41b
1 package de.intevation.flys.artifacts.model.fixings; 1 package de.intevation.flys.artifacts.model.fixings;
2
3 import de.intevation.flys.artifacts.math.fitting.Function;
4
5 import de.intevation.flys.artifacts.math.Outlier;
6 2
7 import de.intevation.flys.artifacts.math.Outlier.IndexedValue; 3 import de.intevation.flys.artifacts.math.Outlier.IndexedValue;
8 import de.intevation.flys.artifacts.math.Outlier.Outliers; 4 import de.intevation.flys.artifacts.math.Outlier.Outliers;
9 5
10 import org.apache.commons.math.MathException; 6 import de.intevation.flys.artifacts.math.Outlier;
11 7
12 import org.apache.commons.math.optimization.fitting.CurveFitter; 8 import de.intevation.flys.artifacts.math.fitting.Function;
13
14 import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer;
15 9
16 import gnu.trove.TDoubleArrayList; 10 import gnu.trove.TDoubleArrayList;
17
18 import org.apache.log4j.Logger;
19 11
20 import java.util.ArrayList; 12 import java.util.ArrayList;
21 import java.util.List; 13 import java.util.List;
14
15 import org.apache.commons.math.MathException;
16
17 import org.apache.commons.math.optimization.fitting.CurveFitter;
18
19 import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer;
20
21 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
22
23 import org.apache.log4j.Logger;
22 24
23 public class Fitting 25 public class Fitting
24 { 26 {
25 private static Logger log = Logger.getLogger(Fitting.class); 27 private static Logger log = Logger.getLogger(Fitting.class);
26 28
43 protected QWDFactory qwdFactory; 45 protected QWDFactory qwdFactory;
44 protected double chiSqr; 46 protected double chiSqr;
45 protected double [] parameters; 47 protected double [] parameters;
46 protected ArrayList<QW> removed; 48 protected ArrayList<QW> removed;
47 protected QWD [] referenced; 49 protected QWD [] referenced;
50 protected double standardDeviation;
48 51
49 52
50 public Fitting() { 53 public Fitting() {
51 removed = new ArrayList<QW>(); 54 removed = new ArrayList<QW>();
52 } 55 }
93 public void reset() { 96 public void reset() {
94 chiSqr = 0.0; 97 chiSqr = 0.0;
95 parameters = null; 98 parameters = null;
96 removed.clear(); 99 removed.clear();
97 referenced = null; 100 referenced = null;
101 standardDeviation = 0.0;
98 } 102 }
99 103
100 public boolean hasOutliers() { 104 public boolean hasOutliers() {
101 return !removed.isEmpty(); 105 return !removed.isEmpty();
102 } 106 }
127 131
128 public double [] getParameters() { 132 public double [] getParameters() {
129 return parameters; 133 return parameters;
130 } 134 }
131 135
136 public double getStandardDeviation() {
137 return standardDeviation;
138 }
139
132 public boolean fit(double [] qs, double [] ws) { 140 public boolean fit(double [] qs, double [] ws) {
133 141
134 TDoubleArrayList xs = new TDoubleArrayList(qs.length); 142 TDoubleArrayList xs = new TDoubleArrayList(qs.length);
135 TDoubleArrayList ys = new TDoubleArrayList(ws.length); 143 TDoubleArrayList ys = new TDoubleArrayList(ws.length);
136 144
203 xs.remove(idx); 211 xs.remove(idx);
204 ys.remove(idx); 212 ys.remove(idx);
205 } 213 }
206 } 214 }
207 215
216 StandardDeviation stdDev = new StandardDeviation();
217
208 referenced = new QWD[xs.size()]; 218 referenced = new QWD[xs.size()];
209 for (int i = 0; i < referenced.length; ++i) { 219 for (int i = 0; i < referenced.length; ++i) {
210 QWD qwd = qwdFactory.create(xs.getQuick(i), ys.getQuick(i)); 220 QWD qwd = qwdFactory.create(xs.getQuick(i), ys.getQuick(i));
211 221
212 if (qwd == null) { 222 if (qwd == null) {
214 } 224 }
215 else { 225 else {
216 referenced[i] = qwd; 226 referenced[i] = qwd;
217 double dw = (qwd.getW() - instance.value(qwd.getQ()))*100.0; 227 double dw = (qwd.getW() - instance.value(qwd.getQ()))*100.0;
218 qwd.setDeltaW(dw); 228 qwd.setDeltaW(dw);
219 } 229 stdDev.increment(dw);
220 } 230 }
231 }
232
233 standardDeviation = stdDev.getResult();
221 234
222 chiSqr = lmo.getChiSquare(); 235 chiSqr = lmo.getChiSquare();
223 236
224 return true; 237 return true;
225 } 238 }

http://dive4elements.wald.intevation.org