List of utility methods to do Mean Calculation
double | calculateMean(double[] values) calculate Mean return calculateSum(values) / (double) values.length; |
float | calculateMean(float[] data) Calculates mean value of float array float sum = 0; for (int i = 0; i < data.length; i++) { sum += data[i]; return sum / data.length; |
float[] | calculateMeanAndStandardDeviation(float[] data) calculate Mean And Standard Deviation float sumMean = 0; float sumDev = 0; float mean, dev; int count = 0; for (int i = 0; i < data.length; i++) { sumMean += data[i]; count++; mean = sumMean / count; for (int i = 0; i < data.length; i++) { sumDev += (mean - data[i]) * (mean - data[i]); dev = (float) Math.sqrt(sumDev / count); float[] out = new float[2]; out[0] = mean; out[1] = dev; return out; |
float[] | calculateMeanAndStandardDeviationIgnoreNegatives(float[] data) All negative values in array are ignored float sumMean = 0; float sumDev = 0; float mean, dev; int count = 0; for (int i = 0; i < data.length; i++) { if (data[i] > 0) { sumMean += data[i]; count++; ... |
float[][] | calculateMeanAndStandardDeviationVectors(float[][] vectors) calculate Mean And Standard Deviation Vectors float[][] out = new float[2][vectors[0].length]; for (int i = 0; i < vectors[0].length; i++) { float[] inputVector = new float[vectors.length]; for (int j = 0; j < inputVector.length; j++) { inputVector[j] = vectors[j][i]; float[] data = calculateMeanAndStandardDeviation(inputVector); out[0][i] = data[0]; ... |
int | calculateMeanLevel(float[] distribution, int mid, int oldMid, float difference) calculate Mean Level return calculateMeanLevel(distribution, mid);
|
String | calculateMeanSD(double[] d) Calculate the mean and standard deviation for an array. double sum = 0; for (int i = 0; i < d.length; i++) { sum += d[i]; double mean = sum / d.length; for (int i = 0; i < d.length; i++) { sum += Math.pow(d[i] - mean, 2); double sd = Math.sqrt(mean / d.length); StringBuilder result = new StringBuilder(); result.append("[mean="); result.append(mean); result.append(",sd="); result.append(sd); result.append("]"); return result.toString(); |