Here you can find the source of std(float[][] arr)
Parameter | Description |
---|---|
arr | a parameter |
public static float std(float[][] arr)
//package com.java2s; public class Main { /**//from w w w . j av a2s . c om * Calculate the standard deviation of a 2D array. Calls * {@link FloatArrayStatsUtils#var(float[][])} and does a Math.sqrt. * * @param arr * @return the standard deviation */ public static float std(float[][] arr) { return (float) Math.sqrt(var(arr)); } /** * Calculate the standard deviation of a 1D array. Calls * {@link FloatArrayStatsUtils#var(float[])} and does a Math.sqrt. * * @param arr * @return the standard deviation */ public static float std(float[] arr) { return (float) Math.sqrt(var(arr)); } /** * Calculate the variance of a one dimensional float array. If the length of * the array is less than 2, variance is 0. * * @param arr * @return the variance */ public static float var(float[] arr) { if (arr.length < 2) { return 0; } int count = 1; float oldMean = arr[0]; float newMean = arr[0]; float var = 0; for (int i = 1; i < arr.length; i++) { count++; final float x = arr[i]; newMean = oldMean + (x - oldMean) / count; var = var + (x - oldMean) * (x - newMean); oldMean = newMean; } return var / (count - 1); } /** * Calculate the variance of a one dimensional float array. If the length of * the array is less than 2, variance is 0. * * @param arr * @return the variance */ public static float var(float[][] arr) { if (arr.length == 0) { return 0; } int firstRowIndex = 0; while (arr[firstRowIndex].length == 0) firstRowIndex++; int firstColIndex = 1; int count = 1; float oldMean = arr[firstRowIndex][0]; float newMean = arr[firstRowIndex][0]; float var = 0; for (int i = firstRowIndex; i < arr.length; i++) { for (int j = firstColIndex; j < arr[i].length; j++) { count++; final float x = arr[i][j]; newMean = oldMean + (x - oldMean) / count; var = var + (x - oldMean) * (x - newMean); oldMean = newMean; } firstColIndex = 0; } return count > 1 ? var / (count - 1) : 0; } }