Java mean meandiff(double[] v1, double[] v2)

Here you can find the source of meandiff(double[] v1, double[] v2)

Description

Returns the difference in the means of the two lists.

License

Open Source License

Declaration

public static double meandiff(double[] v1, double[] v2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w w w.  ja  v a 2  s .c  o m*/
     * Returns the difference in the means of the two lists. 
     */
    public static double meandiff(double[] v1, double[] v2) {
        double s1 = 0, c1 = 0;
        for (int i = 0; i < v1.length; i++) {
            s1 += v1[i];
            c1++;
        }
        double m1 = s1 / c1;

        double s2 = 0, c2 = 0;
        for (int i = 0; i < v2.length; i++) {
            s2 += v2[i];
            c2++;
        }
        double m2 = s2 / c2;
        double diff = m1 - m2;

        // Want to normalize it, so that the values are somewhat comparable..
        double rval = 0.000000001; // Just to prevent ugly divide by zero. 
        if (m2 != 0)
            rval = diff / m2;
        return (rval);
    }
}

Related

  1. meanAbortedExecutionTime( double totalExecutionTime, int totalOps, double granuleAbortProb)
  2. meanAndStandardDeviation(final double[] inp, final int startIndex, final int pastEnd)
  3. meanAndVariance(double[] a, boolean useUnbiasedEstimate)
  4. meanArithmetic(LinkedList a)
  5. meanArray(double[] arr)
  6. meanEnt(double[] nums)
  7. meanFast(final double[] values)
  8. meanFilter(float[] weights, int context)
  9. meanGreenwichSideralTime(double t)