get Normal Deviation Value - Java java.lang

Java examples for java.lang:Math Value

Description

get Normal Deviation Value

Demo Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    public static float getNormalDeviationValue(ArrayList<Float> data) {
        if (data == null || data.size() == 0)
            return 0;

        float mean = getMeanValue(data);
        float sum = 0;
        for (int i = 0; i != data.size(); i++) {
            sum += (data.get(i) - mean) * (data.get(i) - mean);
        }/*www  .jav  a  2  s  .  c  o  m*/
        float result = (float) Math.sqrt(sum / data.size());
        return result;
    }

    public static float getNormalDeviationValue(float[] data) {
        if (data == null || data.length == 0)
            return 0;

        float mean = getMeanValue(data);
        float sum = 0;
        for (int i = 0; i != data.length; i++) {
            sum += (data[i] - mean) * (data[i] - mean);
        }
        float result = (float) Math.sqrt(sum / data.length);
        return result;
    }

    public static float getMeanValue(ArrayList<Float> data) {

        if (data == null || data.size() == 0)
            return 0;

        float sum = 0;
        for (int i = 0; i != data.size(); i++) {
            sum += data.get(i);
        }
        return sum / data.size();
    }

    public static float getMeanValue(float[] data) {

        if (data == null || data.length == 0)
            return 0;

        float sum = 0;
        for (int i = 0; i != data.length; i++) {
            sum += data[i];
        }
        return sum / data.length;
    }
}

Related Tutorials