comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Fitting.java @ 6780:b8f94e865875

S/Q relation: Part I of 'faking' fitting linear data. S/Qs can now be subclassed and processed through views. TODO: Add knob to setup a linear data path.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 08 Aug 2013 12:17:03 +0200
parents 48f6780c372d
children 51eb6491c537
comparison
equal deleted inserted replaced
6779:8e5adc56385c 6780:b8f94e865875
50 protected double stdDevFactor; 50 protected double stdDevFactor;
51 protected double chiSqr; 51 protected double chiSqr;
52 52
53 protected Callback callback; 53 protected Callback callback;
54 54
55 protected SQ.View sqView;
56
55 public Fitting() { 57 public Fitting() {
56 } 58 }
57 59
58 public Fitting(Function function, double stdDevFactor) { 60 public Fitting(Function function, double stdDevFactor, SQ.View sqView) {
59 this();
60 this.function = function; 61 this.function = function;
61 this.stdDevFactor = stdDevFactor; 62 this.stdDevFactor = stdDevFactor;
63 this.sqView = sqView;
62 } 64 }
63 65
64 public Function getFunction() { 66 public Function getFunction() {
65 return function; 67 return function;
66 } 68 }
149 chiSqr = optimizer.getChiSquare(); 151 chiSqr = optimizer.getChiSquare();
150 } 152 }
151 153
152 @Override 154 @Override
153 public double eval(SQ sq) { 155 public double eval(SQ sq) {
154 double s = instance.value(sq.q); 156 double s = instance.value(sqView.getQ(sq));
155 return sq.s - s; 157 return sqView.getS(sq) - s;
156 } 158 }
157 159
158 @Override 160 @Override
159 public void iterationFinished( 161 public void iterationFinished(
160 double standardDeviation, 162 double standardDeviation,
175 outlier != null ? new SQ [] { outlier} : new SQ [] {}, 177 outlier != null ? new SQ [] { outlier} : new SQ [] {},
176 standardDeviation, 178 standardDeviation,
177 chiSqr); 179 chiSqr);
178 } 180 }
179 181
180 protected static final List<SQ> onlyValid(List<SQ> sqs) { 182 public boolean fit(List<SQ> sqs, String method, Callback callback) {
181
182 List<SQ> good = new ArrayList<SQ>(sqs.size());
183
184 for (SQ sq: sqs) {
185 if (sq.isValid()) {
186 good.add(sq);
187 }
188 }
189
190 return good;
191 }
192
193 public boolean fit(List<SQ> sqs, String method, Callback callback) {
194
195 sqs = onlyValid(sqs);
196 183
197 if (sqs.size() < 2) { 184 if (sqs.size() < 2) {
198 log.warn("Too less points for fitting."); 185 log.warn("Too less points for fitting.");
199 return false; 186 return false;
200 } 187 }
201 188
189 sqs = new ArrayList<SQ>(sqs);
190
202 this.callback = callback; 191 this.callback = callback;
203 192
204 try { 193 try {
205 Outlier.detectOutliers(this, sqs, stdDevFactor, method); 194 Outlier.detectOutliers(this, sqs, stdDevFactor, method);
206 } 195 }

http://dive4elements.wald.intevation.org