Java Utililty Methods Collection Mean

List of utility methods to do Collection Mean

Description

The list of methods to do Collection Mean are organized into topic(s).

Method

doublecalculateMean(Collection values)
Returns the mean of a collection of Number objects.
int count = 0;
double total = 0.0;
final Iterator<? extends Number> iterator = values.iterator();
while (iterator.hasNext()) {
    final double value = iterator.next().doubleValue();
    if (!Double.isNaN(value) && !Double.isInfinite(value)) {
        total += value;
        count++;
...
doublecalculateMean(Collection values)
Calculate a mean for the input
if (values.isEmpty()) {
    throw new IllegalArgumentException("can't calculate a mean for an empty collection");
} else {
    double sum = 0.0;
    for (Number currValue : values) {
        sum += currValue.doubleValue();
    return sum / values.size();
...
doublecalculateMean(Collection values)
calculate Mean
if (values == null || values.isEmpty()) {
    throw new IllegalArgumentException("Can not calculate mean of null or empty collection!");
return (calcSum(values) / values.size());
doublegetMean(Collection data)
get Mean
double sum = 0.0;
for (double d : data) {
    sum += d;
return sum / data.size();
double[]getMean(Collection cluster)
get Mean
int l = cluster.iterator().next().length;
double[] r = new double[l];
for (double[] d : cluster)
    for (int i = 0; i < l; i++)
        r[i] += d[i];
for (int i = 0; i < l; i++)
    r[i] /= cluster.size();
return r;
...
doublegetMean(final Collection collection)
get Mean
final int size = collection.size();
final List<T> sorted = new ArrayList<T>(collection);
Collections.sort(sorted, new Comparator<T>() {
    @Override
    public int compare(final T n1, final T n2) {
        return (int) Math.signum(n2.doubleValue() - n1.doubleValue());
});
...
doublegetVariance(Collection data, Number mean)
Returns the standard deviation of a set of numbers.
double result = Double.NaN;
if (data != null && data.size() > 0 && mean != null) {
    double sum = 0.0;
    for (final Number n : data) {
        final double diff = n.doubleValue() - mean.doubleValue();
        sum = sum + (diff * diff);
    result = sum / (data.size());
...
doublemean(Collection coll)
mean
if (coll == null || coll.size() < 1)
    throw new IllegalArgumentException();
double res = 0;
for (Number n : coll) {
    res += n.doubleValue();
return res / coll.size();
doublemean(Collection nums)
mean
if (nums == null || nums.isEmpty()) {
    return Double.NaN;
double sum = 0.0;
for (Number n : nums) {
    sum += n.doubleValue();
return sum / nums.size();
...
Doublemean(Collection data)
mean
return (sum(data) / (double) data.size());