Java List Variance variance(List values)

Here you can find the source of variance(List values)

Description

variance

License

LGPL

Declaration

public static float variance(List<Float> values) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.List;

public class Main {
    public static float variance(List<Float> values) {
        float mean = mean(values);

        float variance = 0;
        for (float value : values) {
            variance += Math.pow(value - mean, 2);
        }//  w w  w . j  a  v  a 2s .c om
        variance = variance / ((float) values.size());
        return variance;
    }

    public static float variance(float[] values) {
        float mean = mean(values);

        float variance = 0;
        for (float value : values) {
            variance += Math.pow(value - mean, 2);
        }
        variance = variance / ((float) values.length - 1);
        return variance;
    }

    public static float mean(List<Float> values) {
        float mean = 0;
        for (float value : values) {
            mean += value;
        }
        mean = mean / (float) values.size();
        return mean;
    }

    public static float mean(float[] values) {
        float mean = 0;
        for (float value : values) {
            mean += value;
        }
        mean = mean / (float) values.length;
        return mean;
    }
}

Related

  1. variance(ArrayList doubleArrayList)
  2. variance(final List list)
  3. variance(List data)
  4. variance(List observations)
  5. variance(List data)