[Dive4elements-commits] [PATCH] Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set
Wald Commits
scm-commit at wald.intevation.org
Sun Jun 2 13:51:44 CEST 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1370173887 -7200
# Node ID 63d1e2a9b311d9a6f777810a341edb61c8370bc7
# Parent 1f057463765b5bef1dcdd436edeab0977f7114c6
Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
diff -r 1f057463765b -r 63d1e2a9b311 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java Sun Jun 02 13:45:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java Sun Jun 02 13:51:27 2013 +0200
@@ -299,22 +299,25 @@
public double calculateDeviation(QualityMeasurement qm) {
Map<String, Double> dm = qm.getAllDiameter();
- double phiM = 0;
- double[] phis = new double[dm.size()];
- double[] ps = new double[dm.size()];
+ int size = dm.size();
+
+ double phiM = 0;
+ double [] phis = new double[size];
+ double [] ps = new double[size];
+ double scale = -1d/Math.log(2d);
+
int i = 0;
- for (String key : dm.keySet()) {
- double d = dm.get(key);
- double phi = -Math.log(d)/Math.log(2);
+ for (Map.Entry<String, Double> entry: dm.entrySet()) {
+ double phi = scale*Math.log(entry.getValue());
+ double p = calculateWeight(qm, entry.getKey());
+ phiM += phi * p;
+ ps[i] = p;
phis[i] = phi;
- double p = calculateWeight(qm, key);
- ps[i] = p;
- phiM += phi * p;
i++;
}
double sig = 0d;
- for (i = 0; i < dm.size(); i++) {
+ for (i = 0; i < size; i++) {
sig += ps[i] * Math.exp(phis[i] - phiM);
}
double deviation = Math.sqrt(sig);
More information about the Dive4elements-commits
mailing list