comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 3818:dc18457b1cef

merged flys-artifacts/pre2.7-2012-03-16
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:59 +0200
parents 8afd6a9bb244
children 5642a83420f2
comparison
equal deleted inserted replaced
2456:60ab1054069d 3818:dc18457b1cef
1 package de.intevation.flys.utils;
2
3 import java.util.Random;
4
5 import gnu.trove.TDoubleArrayList;
6
7 public class DataUtil
8 {
9 public static boolean guessWaterIncreasing(TDoubleArrayList data) {
10 return guessWaterIncreasing(data, 0.05f);
11 }
12
13 public static boolean guessWaterIncreasing(TDoubleArrayList data, float factor) {
14 int N = data.size();
15 if (N < 2) return false;
16
17 int samples = (int)(factor*N) + 1;
18
19 int up = 0;
20
21 Random rand = new Random();
22
23 for (int i = 0; i < samples; ++i) {
24 int pos2 = rand.nextInt(N-1) + 1;
25 int pos1 = rand.nextInt(pos2);
26 double w1 = data.getQuick(pos1);
27 double w2 = data.getQuick(pos2);
28 if (w2 > w1) ++up;
29 }
30
31 return up > samples/2;
32 }
33 }
34 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org