# HG changeset patch # User Sascha L. Teichmann # Date 1351854092 -3600 # Node ID d095b426777295d6933972230520a9289e399997 # Parent e0add97c432b19faf311b41c6f75ef5ea1593f46 Added missing percentage cut off in extreme calculation. diff -r e0add97c432b -r d095b4267772 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java Fri Nov 02 11:02:15 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java Fri Nov 02 12:01:32 2012 +0100 @@ -11,6 +11,7 @@ import de.intevation.flys.artifacts.access.ExtremeAccess; +import de.intevation.flys.artifacts.math.Linear; import de.intevation.flys.artifacts.math.Utils; import de.intevation.flys.artifacts.math.fitting.Function; @@ -254,7 +255,7 @@ return new CalculationResult(result, this); } - protected static double [] doFitting( + protected double [] doFitting( Function function, double [][] wqs, double [] chiSqr @@ -295,7 +296,7 @@ return coeffs; } - protected static double [][] extractPointsToFit(double [][] wqs) { + protected double [][] extractPointsToFit(double [][] wqs) { TDoubleArrayList ows = new TDoubleArrayList(); TDoubleArrayList oqs = new TDoubleArrayList(); @@ -346,14 +347,42 @@ w1 = cw; } - // XXX: Not really needed for fitting. - // oqs.reverse(); - // ows.reverse(); + oqs.reverse(); + ows.reverse(); + cutPercent(ows, oqs); return new double [][] { ows.toNativeArray(), oqs.toNativeArray() }; } + + protected void cutPercent(TDoubleArrayList ws, TDoubleArrayList qs) { + int N = qs.size(); + if (percent <= 0d || N == 0) { + return; + } + + double minQ = qs.getQuick(0); + double maxQ = qs.getQuick(N-1); + double factor = Math.min(Math.max(0d, percent/100d), 1d); + double cutQ = Linear.weight(factor, minQ, maxQ); + int cutIndex = 0; + for (; cutIndex < N; ++cutIndex) { + double q = qs.getQuick(cutIndex); + if (minQ < maxQ) { + if (q > cutQ) { + break; + } + } + else { + if (q < cutQ) { + break; + } + } + } + ws.remove(0, cutIndex); + qs.remove(0, cutIndex); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :