vec_math
Class ClassicStatistic

java.lang.Object
  extended by vec_math.WeightedStatistic
      extended by vec_math.ClassicStatistic

public class ClassicStatistic
extends WeightedStatistic

Class to implement a simple statistic: Average is the arithmetic average, Deviation the standard deviation. For definition of Skew see e.g. "Numerical recipes" p


Nested Class Summary
static class ClassicStatistic.FileStatistic
          A class to read in an ascii-column file and calculate average, sigma and so forth from the specified column.
 
Field Summary
protected  boolean ValidWeighSum
           
protected  double WeighSum
           
 
Fields inherited from class vec_math.WeightedStatistic
Average, Deviation, DeviationOfAverage, Kurt, N, sigma, Skew, TrueAverage, TrueDeviation, ValidAverage, ValidDeviation, ValidDeviationOfAverage, ValidKurt, ValidSkew, ValidTrueAverage, ValidTrueDeviation, Weighed, x, XMax, XMin, xValid
 
Constructor Summary
ClassicStatistic()
          Constructs an empty statistic object.
ClassicStatistic(double[] x, double[] s)
          Constructs a ready-to-use statistic object.
ClassicStatistic(Number[] x, Number[] s)
          Constructs a ready-to-use statistic object out of Double objects.
ClassicStatistic(VectorG[] val, int vi, int si)
          Constructs a ready-to-use statistic object out of a VectorG.
 
Method Summary
private static double[] getAsPrimitiveArray(Number[] z)
          Converts an array of Doubles into an array of its primitive type.
 double getAverage()
          Returns the weighed, aritmethic average.
 double getAverageSigma()
           
 double getDeviation()
          Return the standard deviation for beforehandly unknown Average.
 double getDeviationOfAverage()
          Estimate the Deviaiton of the Average as Deviaiton/sqrt(N).
 double getKurt()
          Returns the kurt of a distribution.
protected  int getNum()
          Returns the number of data.
 double getSkew()
          Returns the skew of a sample.
protected  double getSum()
          Calculates the Sum of the weighs and sets Valid flag.
 double getTrueAverage()
          Not calcable, return NaN.
 double getTrueDeviation()
          Approximate the true deviation (as for N->inf.) bye multiplying the Deviation with sqrt(N/(N-1)).
 void updateOnAdd(double xadd, double sadd)
          Only possible update is to recalculate everything from plain data.
 void updateOnDelete(double xdel, double sdel)
          Exactly the same rules as with adding, so simply call that routine.
 
Methods inherited from class vec_math.WeightedStatistic
addValue, addValue, clear, deleteValue, deleteValue, deleteValue, getMax, getMin, getSpan, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WeighSum

protected double WeighSum

ValidWeighSum

protected boolean ValidWeighSum
Constructor Detail

ClassicStatistic

public ClassicStatistic()
Constructs an empty statistic object. Data can be added with the WeightedStatistic.addValue(double) method.


ClassicStatistic

public ClassicStatistic(double[] x,
                        double[] s)
Constructs a ready-to-use statistic object. Note that the timly calculations are only done at a call to the appropriate method, e.g. getAverage()

Parameters:
x - The data set.
s - The weighs of the data or null if unweighed.

ClassicStatistic

public ClassicStatistic(Number[] x,
                        Number[] s)
Constructs a ready-to-use statistic object out of Double objects. Note that the timly calculations are only done at a call to the appropriate method, e.g. getAverage()

Parameters:
x - The data set.
s - The weighs of the data or null if unweighed.

ClassicStatistic

public ClassicStatistic(VectorG[] val,
                        int vi,
                        int si)
Constructs a ready-to-use statistic object out of a VectorG. The values are contained in the first index given, while the second one gives the weights or is -1 if no index carries the weights. calculations are only done at a call to the appropriate method, e.g. getAverage()

Parameters:
val - The data set with values and weights at some index.
vi - The index in a single VectorG that has the data.
si - Index in a single VectorG that has the weight or -1 for none.
Method Detail

getNum

protected int getNum()
Returns the number of data.


getSum

protected double getSum()
Calculates the Sum of the weighs and sets Valid flag.


getAverageSigma

public double getAverageSigma()
Returns:
The average of the weighs.

getAverage

public double getAverage()
Returns the weighed, aritmethic average. x must be valid. Timely calculations are only done at the first method call.

Specified by:
getAverage in class WeightedStatistic
Returns:
double

getTrueAverage

public double getTrueAverage()
Not calcable, return NaN.

Specified by:
getTrueAverage in class WeightedStatistic
Returns:
Double.NaN

getDeviationOfAverage

public double getDeviationOfAverage()
Estimate the Deviaiton of the Average as Deviaiton/sqrt(N).

Specified by:
getDeviationOfAverage in class WeightedStatistic
Returns:
double

getDeviation

public double getDeviation()
Return the standard deviation for beforehandly unknown Average. This implies dividing the Variance by N-1, rather than N. Timely calculation are only done at first method call. Note that after this method, the data average is also available at no cost.

Specified by:
getDeviation in class WeightedStatistic
Returns:
double

getTrueDeviation

public double getTrueDeviation()
Approximate the true deviation (as for N->inf.) bye multiplying the Deviation with sqrt(N/(N-1)).

Specified by:
getTrueDeviation in class WeightedStatistic
Returns:
double

getSkew

public double getSkew()
Returns the skew of a sample. Skew(x1,...,xN)=1/N*Sum((xi-x)/sig)^3. Lit.: e.g. Numerical Recipes p612.

Specified by:
getSkew in class WeightedStatistic
Returns:
double

getKurt

public double getKurt()
Returns the kurt of a distribution. Kurt=(1/N*Sum((xi-x)/sig)^4)-3. Lit.: e.g. Numerical Recipes p612.

Specified by:
getKurt in class WeightedStatistic
Returns:
double

updateOnAdd

public void updateOnAdd(double xadd,
                        double sadd)
Only possible update is to recalculate everything from plain data.

Specified by:
updateOnAdd in class WeightedStatistic
Parameters:
xadd - The value added.
sadd - The weigh of the added value.

updateOnDelete

public void updateOnDelete(double xdel,
                           double sdel)
Exactly the same rules as with adding, so simply call that routine.

Specified by:
updateOnDelete in class WeightedStatistic
Parameters:
xdel - The value deleted.
sdel - The weigh of the deleted value.

getAsPrimitiveArray

private static final double[] getAsPrimitiveArray(Number[] z)
Converts an array of Doubles into an array of its primitive type.