annotate artifacts/src/main/java/org/dive4elements/river/utils/DataUtil.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/utils/DataUtil.java@bd047b71ab37
children 4897a58c8746
rev   line source
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3076
diff changeset
1 package org.dive4elements.river.utils;
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
2
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
3 import java.util.Random;
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
4
1678
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
5 import gnu.trove.TDoubleArrayList;
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
6
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
7 public class DataUtil
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
8 {
1678
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
9 public static boolean guessWaterIncreasing(TDoubleArrayList data) {
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
10 return guessWaterIncreasing(data, 0.05f);
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 }
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
12
1678
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
13 public static boolean guessWaterIncreasing(TDoubleArrayList data, float factor) {
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
14 int N = data.size();
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15 if (N < 2) return false;
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1982
diff changeset
16
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17 int samples = (int)(factor*N) + 1;
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1982
diff changeset
18
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19 int up = 0;
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1982
diff changeset
20
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 Random rand = new Random();
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1982
diff changeset
22
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 for (int i = 0; i < samples; ++i) {
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 int pos2 = rand.nextInt(N-1) + 1;
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25 int pos1 = rand.nextInt(pos2);
1678
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
26 double w1 = data.getQuick(pos1);
03fbf1b30e72 Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1163
diff changeset
27 double w2 = data.getQuick(pos2);
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 if (w2 > w1) ++up;
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 }
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1982
diff changeset
30
1163
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
31 return up > samples/2;
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32 }
2e0739853807 Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33 }
1982
8afd6a9bb244 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1678
diff changeset
34 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org