Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MovingAverage.java @ 4627:d5821c6f0ab0
Fixed validation in parameter matrix panel. Single selections are allowed now.
Avoid adding duplicates of user selection in parameter matrix.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 03 Dec 2012 17:25:49 +0100 |
parents | d6d16b5ab2f0 |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; public class MovingAverage { public static double[][] simple(double[][] values, double radius) { TreeMap<Double, Double> map = toMap(values); double[][] result = new double[values.length][values[0].length]; int ndx = 0; for (double x: map.keySet()) { SortedMap<Double, Double> range = map.subMap(x-radius, true, x+radius, true); double avg = 0d; for (Double v: range.values()) { avg += v; } avg /= range.size(); result[0][ndx] = x; result[1][ndx] = avg; ndx++; } return result; } public static double[][] weighted(double[][] values, double radius) { TreeMap<Double, Double> map = toMap(values); double[][] result = new double[values.length][values[0].length]; int ndx = 0; for (double x: map.keySet()) { double avg = 0d; double weights = 0d; for (Map.Entry<Double, Double> e: map.subMap(x-radius, false, x+radius, false).entrySet() ) { double weight = 1d - Math.abs(x - e.getKey())/radius; avg += weight*e.getValue(); weights += weight; } avg /= weights; result[0][ndx] = x; result[1][ndx] = avg; ndx++; } return result; } private static TreeMap<Double, Double> toMap(double[][] values) { TreeMap<Double, Double> map = new TreeMap<Double, Double>(); for(int i = 0; i < values[0].length; i++) { map.put(values[0][i], values[1][i]); } return map; } }