comparison artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java @ 8581:073ea4bcea58

(issue1755) Interpolate BedQuality Results This adds an interpolation function to each various bedQuality result class. Imho this is ok as the interpolation function can be seen as part of the result. The interpolation function is initalized on first use and can be accessed through get.*Interpol functions.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 16 Mar 2015 15:36:38 +0100
parents e4606eae8ea5
children 07c9ac22f611
comparison
equal deleted inserted replaced
8580:d9f038b8e2ce 8581:073ea4bcea58
7 */ 7 */
8 8
9 package org.dive4elements.river.utils; 9 package org.dive4elements.river.utils;
10 10
11 import org.dive4elements.river.artifacts.math.Linear; 11 import org.dive4elements.river.artifacts.math.Linear;
12
13 import org.apache.commons.math.analysis.interpolation.LinearInterpolator;
14 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
15
16 import org.apache.commons.math.exception.DimensionMismatchException;
17 import org.apache.commons.math.exception.NumberIsTooSmallException;
18 import org.apache.commons.math.exception.NonMonotonousSequenceException;
12 19
13 import gnu.trove.TDoubleArrayList; 20 import gnu.trove.TDoubleArrayList;
14 21
15 import java.util.Arrays; 22 import java.util.Arrays;
16 import java.util.Comparator; 23 import java.util.Comparator;
303 for (int i = 0; i < A; ++i) { 310 for (int i = 0; i < A; ++i) {
304 arrays[i].remove(dest, N-dest); 311 arrays[i].remove(dest, N-dest);
305 } 312 }
306 } 313 }
307 } 314 }
315
316 /** Convieniance function for results to get an interpolator.
317 * This is basically a static wrapper to for LinearInterpolator.interpolate
318 * with error handling. Returns null on error.*/
319 public static PolynomialSplineFunction getLinearInterpolator(TDoubleArrayList x, TDoubleArrayList y) {
320 LinearInterpolator lpol = new LinearInterpolator();
321 try {
322 return lpol.interpolate(x.toNativeArray(), y.toNativeArray());
323 } catch (DimensionMismatchException e) {
324 log.error("KMs and Result values have different sizes. Failed to interpolate: " +
325 e.getMessage());
326 } catch (NonMonotonousSequenceException e) {
327 log.error("KMs are not monotonous. Failed to interpolate: " + e.getMessage());
328 } catch (NumberIsTooSmallException e) {
329 log.error("Result is to small. Failed to interpolate: " + e.getMessage());
330 }
331 return null;
332 }
308 } 333 }
309 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 334 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org