Java mean std(double[] array, double mean)

Here you can find the source of std(double[] array, double mean)

Description

Computes the standard deviation of the values in the array.

License

Open Source License

Parameter

Parameter Description
array Array of doubles whose standard deviation is to be computed.
mean Mean value of the array.

Return

Standard deviation of the array.

Declaration

public static double std(double[] array, double mean) 

Method Source Code

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

public class Main {
    /**/* w ww  .  ja v a  2 s. c  o  m*/
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of integers whose standard deviation is to be
     * computed.
     * @param mean   Mean value of the matrix.
     * @return   Standard deviation of the matrix.
     */
    public static double std(int[][] matrix, double mean) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += Math.pow((matrix[j][i] - mean), 2);
            }
        }
        double stDev = Math.sqrt(sum / (width * height - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of doubles whose standard deviation is to be
     * computed.
     * @param mean   Mean value of the matrix.
     * @return   Standard deviation of the matrix.
     */
    public static double std(double[][] matrix, double mean) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += Math.pow((matrix[j][i] - mean), 2);
            }
        }
        double stDev = Math.sqrt(sum / (width * height - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of longs whose standard deviation is to be computed.
     * @param mean   Mean value of the matrix.
     * @return   Standard deviation of the matrix.
     */
    public static double std(long[][] matrix, double mean) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += Math.pow((matrix[j][i] - mean), 2);
            }
        }
        double stDev = Math.sqrt(sum / (width * height - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of longs whose standard deviation is to be computed.
     * @param mean   Mean value of the matrix.
     * @return   Standard deviation of the matrix.
     */
    public static float std(float[][] matrix, double mean) {

        int width = matrix.length;
        int height = matrix[0].length;
        float sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += Math.pow((matrix[j][i] - mean), 2);
            }
        }
        float stDev = (float) Math.sqrt(sum / (width * height - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of doubles whose standard deviation is to be
     * computed.
     * @param mean   Mean value of the matrix.
     * @return   Standard deviation of the matrix.
     */
    public static float std(byte[][] matrix, double mean) {

        int width = matrix.length;
        int height = matrix[0].length;
        float sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += Math.pow((matrix[j][i] - mean), 2);
            }
        }
        float stDev = (float) Math.sqrt(sum / (width * height - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of doubles whose standard deviation is to be
     * computed.
     * @return   Standard deviation of the matrix.
     */
    public static double std(double[][] matrix) {

        double mean = mean(matrix);
        return std(matrix, mean);

    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of integers whose standard deviation is to be
     * computed.
     * @return   Standard deviation of the matrix.
     */
    public static double std(int[][] matrix) {

        double mean = mean(matrix);
        return std(matrix, mean);

    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of floats whose standard deviation is to be
     * computed.
     * @return   Standard deviation of the matrix.
     */
    public static float std(float[][] matrix) {

        float mean = mean(matrix);
        return std(matrix, mean);

    }

    /**
     * Computes the standard deviation of the values in the matrix.
     *
     * @param matrix   Matrix of bytes whose standard deviation is to be computed.
     * @return   Standard deviation of the matrix.
     */
    public static double std(byte[][] matrix) {

        float mean = mean(matrix);
        return std(matrix, mean);

    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of doubles whose standard deviation is to be computed.
     * @param mean   Mean value of the array.
     * @return   Standard deviation of the array.
     */
    public static double std(double[] array, double mean) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += Math.pow((array[i] - mean), 2);
        }
        double stDev = Math.sqrt(sum / (array.length - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of integers whose standard deviation is to be
     * computed.
     * @param mean   Mean value of the array.
     * @return   Standard deviation of the array.
     */
    public static double std(int[] array, double mean) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += Math.pow((array[i] - mean), 2);
        }
        double stDev = Math.sqrt(sum / (array.length - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of floats whose standard deviation is to be computed.
     * @param mean   Mean value of the array.
     * @return   Standard deviation of the array.
     */
    public static float std(float[] array, double mean) {

        float sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += Math.pow((array[i] - mean), 2);
        }
        float stDev = (float) Math.sqrt(sum / (array.length - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of longs whose standard deviation is to be computed.
     * @param mean   Mean value of the array.
     * @return   Standard deviation of the array.
     */
    public static double std(long[] array, double mean) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += Math.pow((array[i] - mean), 2);
        }
        double stDev = Math.sqrt(sum / (array.length - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of bytes whose standard deviation is to be computed.
     * @param mean   Mean value of the array.
     * @return   Standard deviation of the array.
     */
    public static float std(byte[] array, double mean) {

        float sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += Math.pow((array[i] - mean), 2);
        }
        float stDev = (float) Math.sqrt(sum / (array.length - 1));

        return stDev;
    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of doubles whose standard deviation is to be computed.
     * @return   Standard deviation of the array.
     */
    public static double std(double[] array) {

        double mean = mean(array);
        return std(array, mean);

    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of integers whose standard deviation is to be
     * computed.
     * @return   Standard deviation of the array.
     */
    public static double std(int[] array) {

        double mean = mean(array);
        return std(array, mean);

    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of floats whose standard deviation is to be computed.
     * @return   Standard deviation of the array.
     */
    public static float std(float[] array) {

        double mean = mean(array);
        return std(array, mean);

    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of longs whose standard deviation is to be computed.
     * @return   Standard deviation of the array.
     */
    public static double std(long[] array) {

        double mean = mean(array);
        return std(array, mean);

    }

    /**
     * Computes the standard deviation of the values in the array.
     *
     * @param array Array of bytes whose standard deviation is to be computed.
     * @return   Standard deviation of the array.
     */
    public static float std(byte[] array) {

        double mean = mean(array);
        return std(array, mean);

    }

    /**
     * Computes the mean value of a matrix of integers.
     *
     * @param matrix   A matrix of integers whose mean is to be computed.
     * @return   Mean value of the matrix.
     */
    public static double mean(int[][] matrix) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += matrix[j][i];
            }
        }
        double mean = sum / (width * height);

        return mean;
    }

    /**
     * Computes the mean value of a matrix of doubles.
     *
     * @param matrix   Matrix of doubles whose mean is to be computed.
     * @return   Mean value of the matrix.
     */
    public static double mean(double[][] matrix) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += matrix[j][i];
            }
        }
        double mean = sum / (width * height);

        return mean;
    }

    /**
     * Computes the mean value of a matrix of longs.
     *
     * @param matrix   Matrix of longs whose mean is to be computed.
     * @return   Mean value of the matrix.
     */
    public static double mean(long[][] matrix) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += matrix[j][i];
            }
        }
        double mean = sum / (width * height);

        return mean;
    }

    /**
     * Computes the mean value of a matrix of floats.
     *
     * @param matrix   Matrix of floats whose mean is to be computed.
     * @return   Mean value of the matrix.
     */
    public static float mean(float[][] matrix) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += matrix[j][i];
            }
        }
        float mean = (float) (sum / (width * height));

        return mean;
    }

    /**
     * Computes the mean value of a matrix of bytes.
     *
     * @param matrix   Matrix of bytes whose mean is to be computed.
     * @return   Mean value of the matrix.
     */
    public static float mean(byte[][] matrix) {

        int width = matrix.length;
        int height = matrix[0].length;
        double sum = 0;

        for (int j = 0; j < width; j++) {
            for (int i = 0; i < height; i++) {
                sum += matrix[j][i];
            }
        }
        float mean = (float) (sum / (width * height));

        return mean;
    }

    /**
     * Computes the mean value of an array of integers.
     *
     * @param array   Array of integers whose mean is to be computed.
     * @return   Mean value of the array.
     */
    public static double mean(int[] array) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        double mean = sum / array.length;

        return mean;
    }

    /**
     * Computes the mean value of an array of doubles.
     *
     * @param array   Array of doubles whose mean is to be computed.
     * @return   Mean value of the array.
     */
    public static double mean(double[] array) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        double mean = sum / array.length;

        return mean;
    }

    /**
     * Computes the mean value of an array of longs.
     *
     * @param array   Array of longs whose mean is to be computed.
     * @return   Mean value of the array.
     */
    public static double mean(long[] array) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        double mean = sum / array.length;

        return mean;
    }

    /**
     * Computes the mean value of an array of floats.
     *
     * @param array   Array of floats whose mean is to be computed.
     * @return   Mean value of the array.
     */
    public static double mean(float[] array) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        double mean = sum / array.length;

        return mean;
    }

    /**
     * Computes the mean value of an array of bytes.
     *
     * @param array   Array of bytes whose mean is to be computed.
     * @return   Mean value of the array.
     */
    public static double mean(byte[] array) {

        double sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        double mean = sum / array.length;

        return mean;
    }
}

Related

  1. meanSquaredError(double[][] vectorBatch1, double[][] vectorBatch2)
  2. meanWithoutZeros(int[] in, int x1, int x2)
  3. meanWithoutZerosCentered(int[] in, int center, int width)
  4. std(double[] a, double mean, boolean isUnbiasedEstimator)
  5. std(double[] a, int size, double mean)
  6. stdDeviation(int[] values, double mean)
  7. stdDevsOfRows(double[][] matrix, double[] means)
  8. stdev(final double[] values, final double mean)
  9. stdevm(double[] values, double mean)