Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java @ 4355:d095b4267772
Added missing percentage cut off in extreme calculation.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 12:01:32 +0100 |
parents | 22f03e7b0ed1 |
children | 10e277c2fe0f |
comparison
equal
deleted
inserted
replaced
4354:e0add97c432b | 4355:d095b4267772 |
---|---|
9 | 9 |
10 import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer; | 10 import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer; |
11 | 11 |
12 import de.intevation.flys.artifacts.access.ExtremeAccess; | 12 import de.intevation.flys.artifacts.access.ExtremeAccess; |
13 | 13 |
14 import de.intevation.flys.artifacts.math.Linear; | |
14 import de.intevation.flys.artifacts.math.Utils; | 15 import de.intevation.flys.artifacts.math.Utils; |
15 | 16 |
16 import de.intevation.flys.artifacts.math.fitting.Function; | 17 import de.intevation.flys.artifacts.math.fitting.Function; |
17 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; | 18 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; |
18 | 19 |
252 | 253 |
253 ExtremeResult result = new ExtremeResult(curves, wqkms); | 254 ExtremeResult result = new ExtremeResult(curves, wqkms); |
254 return new CalculationResult(result, this); | 255 return new CalculationResult(result, this); |
255 } | 256 } |
256 | 257 |
257 protected static double [] doFitting( | 258 protected double [] doFitting( |
258 Function function, | 259 Function function, |
259 double [][] wqs, | 260 double [][] wqs, |
260 double [] chiSqr | 261 double [] chiSqr |
261 ) { | 262 ) { |
262 LevenbergMarquardtOptimizer lmo = null; | 263 LevenbergMarquardtOptimizer lmo = null; |
293 } | 294 } |
294 chiSqr[0] = lmo.getChiSquare(); | 295 chiSqr[0] = lmo.getChiSquare(); |
295 return coeffs; | 296 return coeffs; |
296 } | 297 } |
297 | 298 |
298 protected static double [][] extractPointsToFit(double [][] wqs) { | 299 protected double [][] extractPointsToFit(double [][] wqs) { |
299 TDoubleArrayList ows = new TDoubleArrayList(); | 300 TDoubleArrayList ows = new TDoubleArrayList(); |
300 TDoubleArrayList oqs = new TDoubleArrayList(); | 301 TDoubleArrayList oqs = new TDoubleArrayList(); |
301 | 302 |
302 double [] ws = wqs[0]; | 303 double [] ws = wqs[0]; |
303 double [] qs = wqs[1]; | 304 double [] qs = wqs[1]; |
344 } | 345 } |
345 q1 = cq; | 346 q1 = cq; |
346 w1 = cw; | 347 w1 = cw; |
347 } | 348 } |
348 | 349 |
349 // XXX: Not really needed for fitting. | 350 oqs.reverse(); |
350 // oqs.reverse(); | 351 ows.reverse(); |
351 // ows.reverse(); | 352 cutPercent(ows, oqs); |
352 | 353 |
353 return new double [][] { | 354 return new double [][] { |
354 ows.toNativeArray(), | 355 ows.toNativeArray(), |
355 oqs.toNativeArray() | 356 oqs.toNativeArray() |
356 }; | 357 }; |
357 } | 358 } |
359 | |
360 protected void cutPercent(TDoubleArrayList ws, TDoubleArrayList qs) { | |
361 int N = qs.size(); | |
362 if (percent <= 0d || N == 0) { | |
363 return; | |
364 } | |
365 | |
366 double minQ = qs.getQuick(0); | |
367 double maxQ = qs.getQuick(N-1); | |
368 double factor = Math.min(Math.max(0d, percent/100d), 1d); | |
369 double cutQ = Linear.weight(factor, minQ, maxQ); | |
370 int cutIndex = 0; | |
371 for (; cutIndex < N; ++cutIndex) { | |
372 double q = qs.getQuick(cutIndex); | |
373 if (minQ < maxQ) { | |
374 if (q > cutQ) { | |
375 break; | |
376 } | |
377 } | |
378 else { | |
379 if (q < cutQ) { | |
380 break; | |
381 } | |
382 } | |
383 } | |
384 ws.remove(0, cutIndex); | |
385 qs.remove(0, cutIndex); | |
386 } | |
358 } | 387 } |
359 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 388 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |