Java Mean Calculate computeMeanSquareError(double[] x, double[] y)

Here you can find the source of computeMeanSquareError(double[] x, double[] y)

Description

computes the mean square error of array x to array y

License

Open Source License

Parameter

Parameter Description
x the one array
y the other array

Return

the mean square error

Declaration

public static double computeMeanSquareError(double[] x, double[] y) 

Method Source Code

//package com.java2s;
/*/*from   w w  w.  j a va 2s  .  c o  m*/
 * Copyright (C) 2010-2014  Andreas Maier
 * CONRAD is developed as an Open Source project under the GNU General Public License (GPL).
*/

public class Main {
    /**
     * computes the mean square error of array x to array y
     *
     * @param x the one array
     * @param y the other array
     * @return the mean square error
     */
    public static double computeMeanSquareError(double[] x, double[] y) {
        double sum = 0;
        for (int i = 0; i < x.length; i++) {
            sum += Math.pow(x[i] - y[i], 2);
        }
        return sum / x.length;
    }

    /**
     * calls Math.pow for each element of the array
     * @param array
     * @param exp the exponent.
     * @return reference to the input array
     */
    public static double[] pow(double[] array, double exp) {
        for (int i = 0; i < array.length; i++) {
            array[i] = Math.pow(array[i], exp);
        }
        return array;
    }
}

Related

  1. computeMean(float[] array)
  2. computeMean(float[] data)
  3. computeMean(int val1, int val2, float ratio)
  4. computeMean(int[][] pixels)
  5. computeMeanSquaredError(double[] trueValues, double[] predValues)
  6. mean(ArrayList values)
  7. mean(ArrayList a)
  8. mean(Double... values)