xtc.util
Class Statistics

java.lang.Object
  extended by xtc.util.Statistics

public class Statistics
extends java.lang.Object

Implementation of a simple statistics collector.

Version:
$Revision: 1.13 $
Author:
Robert Grimm

Constructor Summary
Statistics()
          Create a new statistics collector.
 
Method Summary
 void add(double d)
          Add the specified number.
static double fitSlope(Statistics x, Statistics y)
          Compute the least squares fit.
 double get(int idx)
          Get the specified number.
 double mean()
          Calculate the mean.
 double median()
          Calculate the median.
 void reset()
          Reset this statistics collector.
static double round(double d)
          Round the specified number to two digits after the decimal point.
 int size()
          Get the size of this collection.
 double stdev()
          Calculate the standard deviation.
 double sum()
          Calculate the sum.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Statistics

public Statistics()
Create a new statistics collector.

Method Detail

reset

public void reset()
Reset this statistics collector.


add

public void add(double d)
Add the specified number.

Parameters:
d - The number.

size

public int size()
Get the size of this collection.

Returns:
The size.

get

public double get(int idx)
Get the specified number.

Parameters:
idx - The index.
Returns:
The corresponding number.
Throws:
java.lang.IndexOutOfBoundsException - Signals that the index is out of range.

sum

public double sum()
Calculate the sum.

Returns:
The sum.

mean

public double mean()
Calculate the mean.

Returns:
The mean.

median

public double median()
Calculate the median. Note that this method does not change the order of numbers in this collection, i.e. it sorts a copy.

Returns:
The median.

stdev

public double stdev()
Calculate the standard deviation.

Returns:
The standard deviation.

round

public static double round(double d)
Round the specified number to two digits after the decimal point.

Parameters:
d - The number.
Returns:
The rounded number.

fitSlope

public static double fitSlope(Statistics x,
                              Statistics y)
Compute the least squares fit. This method computes the least squares fit to a straight line model without a constant term for the specified collections of numbers: y = mx.

Parameters:
x - The collection of x coordinates.
y - The collection of y coordiantes.
Returns:
The slope of the corresponding line model.
Throws:
java.lang.IllegalArgumentException - Signals that the two collections are empty or not of the same size.


Copyright © 2012. All Rights Reserved.