vec_math
Class CentralMoments

java.lang.Object
  extended by vec_math.CentralMoments
All Implemented Interfaces:
Serializable

public class CentralMoments
extends Object
implements Serializable

Moments is a stastistic package that allows calculation of sample central moments of discrete samples. They are defined as

   M_k=1/n·Σ(x_i-μ)^k,
   
where μ is the sample mean and the summing is done over all smaple values x_i. The connection to the power sums S_k=Σx_i^k is
   M_k=Σ_0^n (-1)^(n-k)(n over k) 1/N(n-k+1)S_k*S_1^(n-k)
   
Note that sample moments are not identically to population moments, for the first moments, the following similarites hold
   μ=M_1
   μ_2=σ²=N/(N-1)·M_2 (μ_2=population variance)
   μ_3=N²/[(N-1)(N-2)]·M_3 
   μ_4=N²[(N+1)M_4-3(N-1)M_2²]/[(N-1)(N-2)(N-3)+3N/(N-1)M_2 
   
To normalize the moments, they are devided by the k/2-th power of the sample variance (roughly the k-th power of the standard deviation).

See Also:
Serialized Form

Nested Class Summary
static class CentralMoments.FitsMoments
          Grabs a fits file and displays the moments up to the order given in the optional second command line argument.
 
Field Summary
private  int n
          The number of values in the sample.
private  int order
          The order of the moments, defined at construction.
private static int ORDER
          Default order number.
private  double[] power
          The cummulated power sums.
 
Constructor Summary
CentralMoments()
          Constructs a new moments object.
CentralMoments(int k)
          Constructs a new moments object.
 
Method Summary
static CentralMoments constructListMoments(int k, List<Number> l)
          Constructs a new statistic from a list of numbers.
static CentralMoments constructVectorMoments(int k, VectorG v)
          Constructs a new statistic from a VectorG.
 double getAverage()
          Returns the sample average, which is equal to the first raw moment.
 double getCentralMoment(int k)
          Returns the k-th sample central moment.
 double getNormalizedCentralMoment(int k)
          Returns the normalized sample moments.
 int getOrder()
          Gets the order.
 double getSigma()
          Returns the unbias sample variance, losely speaking the standard deviation squared.
 double getVariance()
          Returns the unbias sample variance, losely speaking the standard deviation squared.
 void setValues(double[] xi)
          Sets the values as a double array.
 String toString()
          Returns average, etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ORDER

private static final int ORDER
Default order number.

See Also:
Constant Field Values

order

private int order
The order of the moments, defined at construction.


power

private double[] power
The cummulated power sums. Index equals power minus one.


n

private int n
The number of values in the sample.

Constructor Detail

CentralMoments

public CentralMoments()
Constructs a new moments object. Defaults the order to four.


CentralMoments

public CentralMoments(int k)
Constructs a new moments object. Moments available to the order specified here.

Method Detail

getOrder

public int getOrder()
Gets the order.


setValues

public void setValues(double[] xi)
Sets the values as a double array. We do a two-pass calculation of the moments to avoid too big round-off errors.


getAverage

public double getAverage()
Returns the sample average, which is equal to the first raw moment.


getVariance

public double getVariance()
Returns the unbias sample variance, losely speaking the standard deviation squared.


getSigma

public double getSigma()
Returns the unbias sample variance, losely speaking the standard deviation squared.


getCentralMoment

public double getCentralMoment(int k)
Returns the k-th sample central moment.


getNormalizedCentralMoment

public double getNormalizedCentralMoment(int k)
Returns the normalized sample moments.


constructListMoments

public static CentralMoments constructListMoments(int k,
                                                  List<Number> l)
Constructs a new statistic from a list of numbers.


constructVectorMoments

public static CentralMoments constructVectorMoments(int k,
                                                    VectorG v)
Constructs a new statistic from a VectorG.


toString

public String toString()
Returns average, etc.

Overrides:
toString in class Object