1 16 package org.apache.commons.math.stat.descriptive.moment; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; 21 import org.apache.commons.math.stat.descriptive.summary.Sum; 22 23 49 public class Mean extends AbstractStorelessUnivariateStatistic 50 implements Serializable { 51 52 53 static final long serialVersionUID = -1296043746617791564L; 54 55 56 protected FirstMoment moment; 57 58 64 protected boolean incMoment; 65 66 67 public Mean() { 68 incMoment = true; 69 moment = new FirstMoment(); 70 } 71 72 77 public Mean(final FirstMoment m1) { 78 this.moment = m1; 79 incMoment = false; 80 } 81 82 85 public void increment(final double d) { 86 if (incMoment) { 87 moment.increment(d); 88 } 89 } 90 91 94 public void clear() { 95 if (incMoment) { 96 moment.clear(); 97 } 98 } 99 100 103 public double getResult() { 104 return moment.m1; 105 } 106 107 110 public long getN() { 111 return moment.getN(); 112 } 113 114 130 public double evaluate(final double[] values,final int begin, final int length) { 131 if (test(values, begin, length)) { 132 Sum sum = new Sum(); 133 return sum.evaluate(values, begin, length) / ((double) length); 134 } 135 return Double.NaN; 136 } 137 } | Popular Tags |