changeset 6151:63d1e2a9b311

Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 02 Jun 2013 13:51:27 +0200
parents 1f057463765b
children 0587819960c3
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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);

http://dive4elements.wald.intevation.org