1 16 package org.apache.commons.math.stat.descriptive.moment; 17 18 import java.io.Serializable ; 19 20 52 public class FourthMoment extends ThirdMoment implements Serializable { 53 54 55 static final long serialVersionUID = 4763990447117157611L; 56 57 58 protected double m4; 59 60 63 public FourthMoment() { 64 super(); 65 m4 = Double.NaN; 66 } 67 68 71 public void increment(final double d) { 72 if (n < 1) { 73 m4 = 0.0; 74 m3 = 0.0; 75 m2 = 0.0; 76 m1 = 0.0; 77 } 78 79 double prevM3 = m3; 80 double prevM2 = m2; 81 82 super.increment(d); 83 84 double n0 = (double) n; 85 86 m4 = m4 - 4.0 * nDev * prevM3 + 6.0 * nDevSq * prevM2 + 87 ((n0 * n0) - 3 * (n0 -1)) * (nDevSq * nDevSq * (n0 - 1) * n0); 88 } 89 90 93 public double getResult() { 94 return m4; 95 } 96 97 100 public void clear() { 101 super.clear(); 102 m4 = Double.NaN; 103 } 104 105 } 106 | Popular Tags |