Displaying differences for changeset
 
display as  

src/java/m/cfa/ApplicationConfig.java

@@ -39,6 +39,7 @@
         resources.add(m.cfa.download.V1_0.class);
         resources.add(m.cfa.drought.V1_0.class);
         resources.add(m.cfa.durationcurve.V1_0.class);
+        resources.add(m.cfa.errorstats.V1_0.class);
         resources.add(m.cfa.flood.V1_0.class);
         resources.add(m.cfa.loadest.V1_0.class);
         resources.add(m.cfa.regionalfdc.V1_0.class);

src/java/m/cfa/DoubleMath.java

@@ -905,7 +905,6 @@
             denominator = denominator + (observed[i] - observed_ave)*(observed[i] - observed_ave);
         }
         double E = 1 - (numerator/denominator);
-        
         return E;
     }
     /**
@@ -948,4 +947,78 @@
         double tau = S / (n * (n-1) / 2);
         return tau;
     }
+    /**
+     * Computes the Mean Relative Error, note that the provided data must be match lists, aka
+     * the value of observed[i] must be at the same date as modeled[i] for the equation to work
+     * @param observed array of observed values, sorted by observation date
+     * @param modeled array of modeled values, sorted by model date, paired to the same dates as the above observed dates
+     * @return 
+     * @throws java.io.IOException 
+     */
+    public static double MeanRelativeError(double[] observed, double[] modeled) throws IOException{
+        //Check if arrays are the same size
+        if(observed.length != modeled.length){
+            throw(new IOException("Data arrays must be the same size to perform this statistic.  Observed data size:\t" + 
+                    observed.length + "\tModeled data size:\t" + modeled.length));
+        }
+        
+        double sum = 0;
+        for(int i=0; i<observed.length; i++){
+            sum += Math.abs( (observed[i] - modeled[i]) / observed[i] );
+        }
+        double mre = (100.0/observed.length) * sum;
+        return mre;
+    }
+    /**
+     * Computes the Mean Relative Error, note that the provided data must be match lists, aka
+     * the value of observed[i] must be at the same date as modeled[i] for the equation to work
+     * @param observed array of observed values, sorted by observation date
+     * @param modeled array of modeled values, sorted by model date, paired to the same dates as the above observed dates
+     * @return 
+     * @throws java.io.IOException 
+     */
+    public static double MeanRelativeError(ArrayList<Double> observed, ArrayList<Double> modeled) throws IOException{
+        double[] newObsArray = convertArray(observed);
+        double[] newModArray = convertArray(modeled);
+        double mre = MeanRelativeError(newObsArray, newModArray);
+        return mre;
+    }
+    /**
+     * Computes the Percent Bias (PBIAS), note that the provided data must be match lists, aka
+     * the value of observed[i] must be at the same date as modeled[i] for the equation to work
+     * @param observed array of observed values, sorted by observation date
+     * @param modeled array of modeled values, sorted by model date, paired to the same dates as the above observed dates
+     * @return 
+     * @throws java.io.IOException 
+     */
+    public static double PercentBias(double[] observed, double[] modeled) throws IOException{
+        //Check if arrays are the same size
+        if(observed.length != modeled.length){
+            throw(new IOException("Data arrays must be the same size to perform this statistic.  Observed data size:\t" + 
+                    observed.length + "\tModeled data size:\t" + modeled.length));
+        }
+        
+        double numerator = 0;
+        double denominator = 0;
+        for(int i=0; i<observed.length; i++){
+            numerator += (observed[i] - modeled[i]) * 100;
+            denominator += observed[i];
+        }
+        double pbias = numerator/denominator;
+        return pbias;
+    }
+    /**
+     * Computes the Percent Bias (PBIAS), note that the provided data must be match lists, aka
+     * the value of observed[i] must be at the same date as modeled[i] for the equation to work
+     * @param observed array of observed values, sorted by observation date
+     * @param modeled array of modeled values, sorted by model date, paired to the same dates as the above observed dates
+     * @return 
+     * @throws java.io.IOException 
+     */
+    public static double PercentBias(ArrayList<Double> observed, ArrayList<Double> modeled) throws IOException{
+        double[] newObsArray = convertArray(observed);
+        double[] newModArray = convertArray(modeled);
+        double pbias = PercentBias(newObsArray, newModArray);
+        return pbias;
+    }
 }
\ No newline at end of file