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 22 47 public class FirstMoment extends AbstractStorelessUnivariateStatistic 48 implements Serializable { 49 50 51 static final long serialVersionUID = -803343206421984070L; 52 53 54 protected long n; 55 56 57 protected double m1; 58 59 63 protected double dev; 64 65 70 protected double nDev; 71 72 75 public FirstMoment() { 76 n = 0; 77 m1 = Double.NaN; 78 dev = Double.NaN; 79 nDev = Double.NaN; 80 } 81 82 85 public void increment(final double d) { 86 if (n == 0) { 87 m1 = 0.0; 88 } 89 n++; 90 double n0 = (double) n; 91 dev = d - m1; 92 nDev = dev / n0; 93 m1 += nDev; 94 } 95 96 99 public void clear() { 100 m1 = Double.NaN; 101 n = 0; 102 dev = Double.NaN; 103 nDev = Double.NaN; 104 } 105 106 109 public double getResult() { 110 return m1; 111 } 112 113 116 public long getN() { 117 return n; 118 } 119 } | Popular Tags |