2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * This class provides extended statistical informations about the inspected
23 * distribution. In particular, it provides functions to compute the skewness
24 * (the 3rd degree moment) and the kurtosis (4th degree moment).
26 * @author Gian Paolo Jesi
28 public class MomentStats extends IncrementalStats {
30 private double cubicsum, quadsum; // incremental sums
32 /** Calls {@link #reset} */
33 public MomentStats() {
39 cubicsum = quadsum = 0.0;
42 public void add(double item, int k) {
43 for(int i=0; i<k; ++i)
46 cubicsum += item * item * item;
47 quadsum += item * cubicsum;
51 /** Outputs on a single line the superclass statistics postfixed by the
52 * current skewness and kurtosis.
54 public String toString() {
55 return super.toString()+" "+getSkewness()+" "+getKurtosis();
58 /** Computes the skewness on the node values distribution and
59 * returns the asymmetry coefficient. It gives an indication about the
60 * distribution symmetry compared to the average.
62 *@return The skewness value as a double.
64 public double getSkewness() {
66 double m3 = (((double)n) / (n-1)) * (cubicsum/n - Math.pow(getAverage(), 3) );
67 return ( m3 / Math.pow(getStD(), 3 ) );
70 /** Computes the kurtosis on the node values distribution and
71 * returns the flatness coefficient. It gives an indication about the
72 * distribution sharpness or flatness.
74 * @return The kurtosis momentus value as a double.
76 public double getKurtosis(){
78 double m4 = (((double)n) / (n-1)) * (quadsum/n - Math.pow(getAverage(), 4) );
79 return ( m4 / Math.pow(getStD(), 4) )-3;