1 16 package org.apache.commons.math.stat.descriptive.moment; 17 18 import java.io.Serializable ; 19 20 45 public class ThirdMoment extends SecondMoment implements Serializable { 46 47 48 static final long serialVersionUID = -7818711964045118679L; 49 50 51 protected double m3; 52 53 58 protected double nDevSq; 59 60 63 public ThirdMoment() { 64 super(); 65 m3 = Double.NaN; 66 nDevSq = Double.NaN; 67 } 68 69 72 public void increment(final double d) { 73 if (n < 1) { 74 m3 = m2 = m1 = 0.0; 75 } 76 77 double prevM2 = m2; 78 super.increment(d); 79 nDevSq = nDev * nDev; 80 double n0 = (double) n; 81 m3 = m3 - 3.0 * nDev * prevM2 + (n0 - 1) * (n0 - 2) * nDevSq * dev; 82 } 83 84 87 public double getResult() { 88 return m3; 89 } 90 91 94 public void clear() { 95 super.clear(); 96 m3 = Double.NaN; 97 nDevSq = Double.NaN; 98 } 99 100 } | Popular Tags |