Formatting only. Removed tabs.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141293 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2004-06-14 23:26:54 +00:00
parent fc26642480
commit a6b433d257
15 changed files with 370 additions and 370 deletions

View File

@ -30,7 +30,7 @@ import org.apache.commons.math.stat.univariate.summary.SumOfSquares;
* StatUtils provides static implementations of common double[] based * StatUtils provides static implementations of common double[] based
* statistical methods. These return a single result value or in some cases, as * statistical methods. These return a single result value or in some cases, as
* identified in the javadoc for each method, <code>Double.NaN.</code> * identified in the javadoc for each method, <code>Double.NaN.</code>
* @version $Revision: 1.27 $ $Date: 2004/05/24 05:30:33 $ * @version $Revision: 1.28 $ $Date: 2004/06/14 23:26:53 $
*/ */
public final class StatUtils { public final class StatUtils {
@ -326,11 +326,11 @@ public final class StatUtils {
* (positive) length * (positive) length
*/ */
public static double sumDifference(final double[] sample1, final double[] sample2) public static double sumDifference(final double[] sample1, final double[] sample2)
throws IllegalArgumentException { throws IllegalArgumentException {
int n = sample1.length; int n = sample1.length;
if (n != sample2.length || n < 1) { if (n != sample2.length || n < 1) {
throw new IllegalArgumentException throw new IllegalArgumentException
("Input arrays must have the same (positive) length."); ("Input arrays must have the same (positive) length.");
} }
double result = 0; double result = 0;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {

View File

@ -22,7 +22,7 @@ import org.apache.commons.math.distribution.ChiSquaredDistribution;
/** /**
* Implements Chi-Square test statistics defined in the {@link ChiSquareTest} interface. * Implements Chi-Square test statistics defined in the {@link ChiSquareTest} interface.
* *
* @version $Revision: 1.5 $ $Date: 2004/06/06 23:14:09 $ * @version $Revision: 1.6 $ $Date: 2004/06/14 23:26:53 $
*/ */
public class ChiSquareTestImpl implements ChiSquareTest { public class ChiSquareTestImpl implements ChiSquareTest {
@ -119,7 +119,7 @@ public class ChiSquareTestImpl implements ChiSquareTest {
for (int col = 0; col < nCols; col++) { for (int col = 0; col < nCols; col++) {
expected = (rowSum[row] * colSum[col]) / total; expected = (rowSum[row] * colSum[col]) / total;
sumSq += (((double) counts[row][col] - expected) * ((double) counts[row][col] - expected)) sumSq += (((double) counts[row][col] - expected) * ((double) counts[row][col] - expected))
/ expected; / expected;
} }
} }
return sumSq; return sumSq;

View File

@ -24,7 +24,7 @@ import org.apache.commons.math.stat.univariate.StatisticalSummary;
/** /**
* Implements t-test statistics defined in the {@link TTest} interface. * Implements t-test statistics defined in the {@link TTest} interface.
* *
* @version $Revision: 1.6 $ $Date: 2004/06/06 22:28:25 $ * @version $Revision: 1.7 $ $Date: 2004/06/14 23:26:53 $
*/ */
public class TTestImpl implements TTest { public class TTestImpl implements TTest {
@ -753,7 +753,7 @@ public class TTestImpl implements TTest {
double pooledVariance = ((n1 - 1) * v1 + (n2 -1) * v2 ) / (n1 + n2 - 2); double pooledVariance = ((n1 - 1) * v1 + (n2 -1) * v2 ) / (n1 + n2 - 2);
return (m1 - m2) / Math.sqrt(pooledVariance * (1d / n1 + 1d / n2)); return (m1 - m2) / Math.sqrt(pooledVariance * (1d / n1 + 1d / n2));
} else { } else {
return (m1 - m2) / Math.sqrt((v1 / n1) + (v2 / n2)); return (m1 - m2) / Math.sqrt((v1 / n1) + (v2 / n2));
} }
} }
@ -798,7 +798,7 @@ public class TTestImpl implements TTest {
if (equalVariances) { if (equalVariances) {
degreesOfFreedom = (double) (n1 + n2 - 2); degreesOfFreedom = (double) (n1 + n2 - 2);
} else { } else {
degreesOfFreedom= df(v1, v2, n1, n2); degreesOfFreedom= df(v1, v2, n1, n2);
} }
TDistribution tDistribution = TDistribution tDistribution =
getDistributionFactory().createTDistribution(degreesOfFreedom); getDistributionFactory().createTDistribution(degreesOfFreedom);

View File

@ -14,9 +14,9 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.1 $ $Date: 2004/04/26 18:28:17 $ --> <!-- $Revision: 1.2 $ $Date: 2004/06/14 23:26:53 $ -->
<body> <body>
Classes providing hypothesis testing and confidence interval Classes providing hypothesis testing and confidence interval
construction. construction.
</body> </body>
</html> </html>

View File

@ -14,8 +14,8 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.1 $ $Date: 2004/04/26 18:28:16 $ --> <!-- $Revision: 1.2 $ $Date: 2004/06/14 23:26:53 $ -->
<body> <body>
Statistical routines involving multivariate data. Statistical routines involving multivariate data.
</body> </body>
</html> </html>

View File

@ -14,6 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.5 $ $Date: 2004/04/26 18:28:17 $ --> <!-- $Revision: 1.6 $ $Date: 2004/06/14 23:26:53 $ -->
<body>Data storage, manipulation and summary routines.</body> <body>Data storage, manipulation and summary routines.</body>
</html> </html>

View File

@ -34,203 +34,203 @@ import org.apache.commons.math.stat.univariate.summary.SumOfSquares;
/** /**
* Abstract factory class for univariate statistical summaries. * Abstract factory class for univariate statistical summaries.
* *
* @version $Revision: 1.6 $ $Date: 2004/06/01 21:34:35 $ * @version $Revision: 1.7 $ $Date: 2004/06/14 23:26:53 $
*/ */
public abstract class DescriptiveStatistics implements StatisticalSummary, Serializable { public abstract class DescriptiveStatistics implements StatisticalSummary, Serializable {
/** Serialization UID */ /** Serialization UID */
static final long serialVersionUID = 5188298269533339922L; static final long serialVersionUID = 5188298269533339922L;
/** /**
* Create an instance of a <code>DescriptiveStatistics</code> * Create an instance of a <code>DescriptiveStatistics</code>
* @param cls the type of <code>DescriptiveStatistics</code> object to * @param cls the type of <code>DescriptiveStatistics</code> object to
* create. * create.
* @return a new factory. * @return a new factory.
* @throws InstantiationException is thrown if the object can not be * @throws InstantiationException is thrown if the object can not be
* created. * created.
* @throws IllegalAccessException is thrown if the type's default * @throws IllegalAccessException is thrown if the type's default
* constructor is not accessible. * constructor is not accessible.
* @throws ClassNotFoundException if the named * @throws ClassNotFoundException if the named
* <code>DescriptiveStatistics</code> type can not be found. * <code>DescriptiveStatistics</code> type can not be found.
*/ */
public static DescriptiveStatistics newInstance(String cls) throws InstantiationException, IllegalAccessException, ClassNotFoundException { public static DescriptiveStatistics newInstance(String cls) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return newInstance(Class.forName(cls)); return newInstance(Class.forName(cls));
} }
/** /**
* Create an instance of a <code>DescriptiveStatistics</code> * Create an instance of a <code>DescriptiveStatistics</code>
* @param cls the type of <code>DescriptiveStatistics</code> object to * @param cls the type of <code>DescriptiveStatistics</code> object to
* create. * create.
* @return a new factory. * @return a new factory.
* @throws InstantiationException is thrown if the object can not be * @throws InstantiationException is thrown if the object can not be
* created. * created.
* @throws IllegalAccessException is thrown if the type's default * @throws IllegalAccessException is thrown if the type's default
* constructor is not accessible. * constructor is not accessible.
*/ */
public static DescriptiveStatistics newInstance(Class cls) throws InstantiationException, IllegalAccessException { public static DescriptiveStatistics newInstance(Class cls) throws InstantiationException, IllegalAccessException {
return (DescriptiveStatistics)cls.newInstance(); return (DescriptiveStatistics)cls.newInstance();
} }
/** /**
* Create an instance of a <code>DescriptiveStatistics</code> * Create an instance of a <code>DescriptiveStatistics</code>
* @return a new factory. * @return a new factory.
*/ */
public static DescriptiveStatistics newInstance() { public static DescriptiveStatistics newInstance() {
DescriptiveStatistics factory = null; DescriptiveStatistics factory = null;
try { try {
DiscoverClass dc = new DiscoverClass(); DiscoverClass dc = new DiscoverClass();
factory = (DescriptiveStatistics) dc.newInstance( factory = (DescriptiveStatistics) dc.newInstance(
DescriptiveStatistics.class, DescriptiveStatistics.class,
"org.apache.commons.math.stat.univariate.DescriptiveStatisticsImpl"); "org.apache.commons.math.stat.univariate.DescriptiveStatisticsImpl");
} catch(Exception ex) { } catch(Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
// ignore as default implementation will be used. // ignore as default implementation will be used.
} }
return factory; return factory;
} }
/** /**
* This constant signals that a Univariate implementation * This constant signals that a Univariate implementation
* takes into account the contributions of an infinite number of * takes into account the contributions of an infinite number of
* elements. In other words, if getWindow returns this * elements. In other words, if getWindow returns this
* constant, there is, in effect, no "window". * constant, there is, in effect, no "window".
*/ */
public static final int INFINITE_WINDOW = -1; public static final int INFINITE_WINDOW = -1;
/** /**
* Adds the value to the set of numbers * Adds the value to the set of numbers
* @param v the value to be added * @param v the value to be added
*/ */
public abstract void addValue(double v); public abstract void addValue(double v);
/** /**
* Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm"> * Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm">
* arithmetic mean </a> of the available values * arithmetic mean </a> of the available values
* @return The mean or Double.NaN if no values have been added. * @return The mean or Double.NaN if no values have been added.
*/ */
public double getMean() { public double getMean() {
return apply(new Mean()); return apply(new Mean());
} }
/** /**
* Returns the <a href="http://www.xycoon.com/geometric_mean.htm"> * Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
* geometric mean </a> of the available values * geometric mean </a> of the available values
* @return The geometricMean, Double.NaN if no values have been added, * @return The geometricMean, Double.NaN if no values have been added,
* or if the productof the available values is less than or equal to 0. * or if the productof the available values is less than or equal to 0.
*/ */
public double getGeometricMean() { public double getGeometricMean() {
return apply(new GeometricMean()); return apply(new GeometricMean());
} }
/** /**
* Returns the variance of the available values. * Returns the variance of the available values.
* @return The variance, Double.NaN if no values have been added * @return The variance, Double.NaN if no values have been added
* or 0.0 for a single value set. * or 0.0 for a single value set.
*/ */
public double getVariance() { public double getVariance() {
return apply(new Variance()); return apply(new Variance());
} }
/** /**
* Returns the standard deviation of the available values. * Returns the standard deviation of the available values.
* @return The standard deviation, Double.NaN if no values have been added * @return The standard deviation, Double.NaN if no values have been added
* or 0.0 for a single value set. * or 0.0 for a single value set.
*/ */
public double getStandardDeviation() { public double getStandardDeviation() {
double stdDev = Double.NaN; double stdDev = Double.NaN;
if (getN() > 0) { if (getN() > 0) {
if (getN() > 1) { if (getN() > 1) {
stdDev = Math.sqrt(getVariance()); stdDev = Math.sqrt(getVariance());
} else { } else {
stdDev = 0.0; stdDev = 0.0;
} }
} }
return (stdDev); return (stdDev);
} }
/** /**
* Returns the skewness of the available values. Skewness is a * Returns the skewness of the available values. Skewness is a
* measure of the assymetry of a given distribution. * measure of the assymetry of a given distribution.
* @return The skewness, Double.NaN if no values have been added * @return The skewness, Double.NaN if no values have been added
* or 0.0 for a value set &lt;=2. * or 0.0 for a value set &lt;=2.
*/ */
public double getSkewness() { public double getSkewness() {
return apply(new Skewness()); return apply(new Skewness());
} }
/** /**
* Returns the Kurtosis of the available values. Kurtosis is a * Returns the Kurtosis of the available values. Kurtosis is a
* measure of the "peakedness" of a distribution * measure of the "peakedness" of a distribution
* @return The kurtosis, Double.NaN if no values have been added, or 0.0 * @return The kurtosis, Double.NaN if no values have been added, or 0.0
* for a value set &lt;=3. * for a value set &lt;=3.
*/ */
public double getKurtosis() { public double getKurtosis() {
return apply(new Kurtosis()); return apply(new Kurtosis());
} }
/** /**
* Returns the maximum of the available values * Returns the maximum of the available values
* @return The max or Double.NaN if no values have been added. * @return The max or Double.NaN if no values have been added.
*/ */
public double getMax() { public double getMax() {
return apply(new Max()); return apply(new Max());
} }
/** /**
* Returns the minimum of the available values * Returns the minimum of the available values
* @return The min or Double.NaN if no values have been added. * @return The min or Double.NaN if no values have been added.
*/ */
public double getMin() { public double getMin() {
return apply(new Min()); return apply(new Min());
} }
/** /**
* Returns the number of available values * Returns the number of available values
* @return The number of available values * @return The number of available values
*/ */
public abstract long getN(); public abstract long getN();
/** /**
* Returns the sum of the values that have been added to Univariate. * Returns the sum of the values that have been added to Univariate.
* @return The sum or Double.NaN if no values have been added * @return The sum or Double.NaN if no values have been added
*/ */
public double getSum() { public double getSum() {
return apply(new Sum()); return apply(new Sum());
} }
/** /**
* Returns the sum of the squares of the available values. * Returns the sum of the squares of the available values.
* @return The sum of the squares or Double.NaN if no * @return The sum of the squares or Double.NaN if no
* values have been added. * values have been added.
*/ */
public double getSumsq() { public double getSumsq() {
return apply(new SumOfSquares()); return apply(new SumOfSquares());
} }
/** /**
* Resets all statistics and storage * Resets all statistics and storage
*/ */
public abstract void clear(); public abstract void clear();
/** /**
* Univariate has the ability to return only measures for the * Univariate has the ability to return only measures for the
* last N elements added to the set of values. * last N elements added to the set of values.
* @return The current window size or -1 if its Infinite. * @return The current window size or -1 if its Infinite.
*/ */
public abstract int getWindowSize(); public abstract int getWindowSize();
/** /**
* WindowSize controls the number of values which contribute * WindowSize controls the number of values which contribute
* to the values returned by Univariate. For example, if * to the values returned by Univariate. For example, if
* windowSize is set to 3 and the values {1,2,3,4,5} * windowSize is set to 3 and the values {1,2,3,4,5}
* have been added <strong> in that order</strong> * have been added <strong> in that order</strong>
* then the <i>available values</i> are {3,4,5} and all * then the <i>available values</i> are {3,4,5} and all
* reported statistics will be based on these values * reported statistics will be based on these values
* @param windowSize sets the size of the window. * @param windowSize sets the size of the window.
*/ */
public abstract void setWindowSize(int windowSize); public abstract void setWindowSize(int windowSize);
/** /**
* Returns the current set of values in an array of double primitives. * Returns the current set of values in an array of double primitives.
* The order of addition is preserved. The returned array is a fresh * The order of addition is preserved. The returned array is a fresh
@ -240,7 +240,7 @@ public abstract class DescriptiveStatistics implements StatisticalSummary, Seria
* @return returns the current set of numbers in the order in which they * @return returns the current set of numbers in the order in which they
* were added to this set * were added to this set
*/ */
public abstract double[] getValues(); public abstract double[] getValues();
/** /**
* Returns the current set of values in an array of double primitives, * Returns the current set of values in an array of double primitives,
@ -261,7 +261,7 @@ public abstract class DescriptiveStatistics implements StatisticalSummary, Seria
* @param index The Index of the element * @param index The Index of the element
* @return return the element at the specified index * @return return the element at the specified index
*/ */
public abstract double getElement(int index); public abstract double getElement(int index);
/** /**
* Returns an estimate for the pth percentile of the stored values. * Returns an estimate for the pth percentile of the stored values.
@ -281,9 +281,9 @@ public abstract class DescriptiveStatistics implements StatisticalSummary, Seria
* values * values
*/ */
public double getPercentile(double p) { public double getPercentile(double p) {
return apply(new Percentile(p)); return apply(new Percentile(p));
} }
/** /**
* Generates a text report displaying * Generates a text report displaying
* univariate statistics from values that * univariate statistics from values that
@ -291,23 +291,23 @@ public abstract class DescriptiveStatistics implements StatisticalSummary, Seria
* @return String with line feeds displaying statistics * @return String with line feeds displaying statistics
*/ */
public String toString() { public String toString() {
StringBuffer outBuffer = new StringBuffer(); StringBuffer outBuffer = new StringBuffer();
outBuffer.append("UnivariateImpl:\n"); outBuffer.append("UnivariateImpl:\n");
outBuffer.append("n: " + getN() + "\n"); outBuffer.append("n: " + getN() + "\n");
outBuffer.append("min: " + getMin() + "\n"); outBuffer.append("min: " + getMin() + "\n");
outBuffer.append("max: " + getMax() + "\n"); outBuffer.append("max: " + getMax() + "\n");
outBuffer.append("mean: " + getMean() + "\n"); outBuffer.append("mean: " + getMean() + "\n");
outBuffer.append("std dev: " + getStandardDeviation() + "\n"); outBuffer.append("std dev: " + getStandardDeviation() + "\n");
outBuffer.append("skewness: " + getSkewness() + "\n"); outBuffer.append("skewness: " + getSkewness() + "\n");
outBuffer.append("kurtosis: " + getKurtosis() + "\n"); outBuffer.append("kurtosis: " + getKurtosis() + "\n");
return outBuffer.toString(); return outBuffer.toString();
} }
/** /**
* Apply the given statistic to the data associated with this set of statistics. * Apply the given statistic to the data associated with this set of statistics.
* @param stat the statistic to apply * @param stat the statistic to apply
* @return the computed value of the statistic. * @return the computed value of the statistic.
*/ */
public abstract double apply(UnivariateStatistic stat); public abstract double apply(UnivariateStatistic stat);
} }

View File

@ -23,15 +23,15 @@ import org.apache.commons.math.util.ResizableDoubleArray;
* Default implementation of * Default implementation of
* {@link org.apache.commons.math.stat.univariate.DescriptiveStatistics}. * {@link org.apache.commons.math.stat.univariate.DescriptiveStatistics}.
* *
* @version $Revision: 1.7 $ $Date: 2004/06/14 21:41:33 $ * @version $Revision: 1.8 $ $Date: 2004/06/14 23:26:53 $
*/ */
public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements Serializable { public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements Serializable {
/** Serializable version identifier */ /** Serializable version identifier */
static final long serialVersionUID = -1868088725461221010L; static final long serialVersionUID = -1868088725461221010L;
/** hold the window size **/ /** hold the window size **/
protected int windowSize; protected int windowSize;
/** /**
* Stored data values * Stored data values
@ -42,7 +42,7 @@ public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements
* Construct a DescriptiveStatisticsImpl with infinite window * Construct a DescriptiveStatisticsImpl with infinite window
*/ */
public DescriptiveStatisticsImpl() { public DescriptiveStatisticsImpl() {
this(INFINITE_WINDOW); this(INFINITE_WINDOW);
} }
/** /**
@ -50,8 +50,8 @@ public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements
* @param window the finite window size. * @param window the finite window size.
*/ */
public DescriptiveStatisticsImpl(int window) { public DescriptiveStatisticsImpl(int window) {
super(); super();
eDA = new ResizableDoubleArray(); eDA = new ResizableDoubleArray();
setWindowSize(window); setWindowSize(window);
} }
@ -60,7 +60,7 @@ public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements
* @return the current window size. * @return the current window size.
*/ */
public int getWindowSize() { public int getWindowSize() {
return windowSize; return windowSize;
} }
/** /**

View File

@ -18,45 +18,45 @@ package org.apache.commons.math.stat.univariate;
/** /**
* Reporting interface for basic univariate statistics. * Reporting interface for basic univariate statistics.
* *
* @version $Revision: 1.2 $ $Date: 2004/04/27 04:37:59 $ * @version $Revision: 1.3 $ $Date: 2004/06/14 23:26:53 $
*/ */
public interface StatisticalSummary { public interface StatisticalSummary {
/** /**
* Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm"> * Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm">
* arithmetic mean </a> of the available values * arithmetic mean </a> of the available values
* @return The mean or Double.NaN if no values have been added. * @return The mean or Double.NaN if no values have been added.
*/ */
public abstract double getMean(); public abstract double getMean();
/** /**
* Returns the variance of the available values. * Returns the variance of the available values.
* @return The variance, Double.NaN if no values have been added * @return The variance, Double.NaN if no values have been added
* or 0.0 for a single value set. * or 0.0 for a single value set.
*/ */
public abstract double getVariance(); public abstract double getVariance();
/** /**
* Returns the standard deviation of the available values. * Returns the standard deviation of the available values.
* @return The standard deviation, Double.NaN if no values have been added * @return The standard deviation, Double.NaN if no values have been added
* or 0.0 for a single value set. * or 0.0 for a single value set.
*/ */
public abstract double getStandardDeviation(); public abstract double getStandardDeviation();
/** /**
* Returns the maximum of the available values * Returns the maximum of the available values
* @return The max or Double.NaN if no values have been added. * @return The max or Double.NaN if no values have been added.
*/ */
public abstract double getMax(); public abstract double getMax();
/** /**
* Returns the minimum of the available values * Returns the minimum of the available values
* @return The min or Double.NaN if no values have been added. * @return The min or Double.NaN if no values have been added.
*/ */
public abstract double getMin(); public abstract double getMin();
/** /**
* Returns the number of available values * Returns the number of available values
* @return The number of available values * @return The number of available values
*/ */
public abstract long getN(); public abstract long getN();
/** /**
* Returns the sum of the values that have been added to Univariate. * Returns the sum of the values that have been added to Univariate.
* @return The sum or Double.NaN if no values have been added * @return The sum or Double.NaN if no values have been added
*/ */
public abstract double getSum(); public abstract double getSum();
} }

View File

@ -22,15 +22,15 @@ import org.apache.commons.discovery.tools.DiscoverClass;
/** /**
* Abstract factory class for univariate statistical summaries. * Abstract factory class for univariate statistical summaries.
* *
* @version $Revision: 1.6 $ $Date: 2004/06/01 21:34:35 $ * @version $Revision: 1.7 $ $Date: 2004/06/14 23:26:53 $
*/ */
public abstract class SummaryStatistics implements StatisticalSummary, Serializable { public abstract class SummaryStatistics implements StatisticalSummary, Serializable {
/** Serialization UID */ /** Serialization UID */
static final long serialVersionUID = -6400596334135654825L; static final long serialVersionUID = -6400596334135654825L;
/** /**
* Create an instance of a <code>SummaryStatistics</code> * Create an instance of a <code>SummaryStatistics</code>
* @param cls the type of <code>SummaryStatistics</code> object to * @param cls the type of <code>SummaryStatistics</code> object to
* create. * create.
* @return a new factory. * @return a new factory.
@ -40,13 +40,13 @@ public abstract class SummaryStatistics implements StatisticalSummary, Serializa
* constructor is not accessible. * constructor is not accessible.
* @throws ClassNotFoundException if the named * @throws ClassNotFoundException if the named
* <code>SummaryStatistics</code> type can not be found. * <code>SummaryStatistics</code> type can not be found.
*/ */
public static SummaryStatistics newInstance(String cls) throws InstantiationException, IllegalAccessException, ClassNotFoundException { public static SummaryStatistics newInstance(String cls) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return newInstance(Class.forName(cls)); return newInstance(Class.forName(cls));
} }
/** /**
* Create an instance of a <code>DescriptiveStatistics</code> * Create an instance of a <code>DescriptiveStatistics</code>
* @param cls the type of <code>SummaryStatistics</code> object to * @param cls the type of <code>SummaryStatistics</code> object to
* create. * create.
* @return a new factory. * @return a new factory.
@ -54,108 +54,108 @@ public abstract class SummaryStatistics implements StatisticalSummary, Serializa
* created. * created.
* @throws IllegalAccessException is thrown if the type's default * @throws IllegalAccessException is thrown if the type's default
* constructor is not accessible. * constructor is not accessible.
*/ */
public static SummaryStatistics newInstance(Class cls) throws InstantiationException, IllegalAccessException { public static SummaryStatistics newInstance(Class cls) throws InstantiationException, IllegalAccessException {
return (SummaryStatistics)cls.newInstance(); return (SummaryStatistics)cls.newInstance();
} }
/** /**
* Create an instance of a <code>DescriptiveStatistics</code> * Create an instance of a <code>DescriptiveStatistics</code>
* @return a new factory. * @return a new factory.
*/ */
public static SummaryStatistics newInstance() { public static SummaryStatistics newInstance() {
SummaryStatistics factory = null; SummaryStatistics factory = null;
try { try {
DiscoverClass dc = new DiscoverClass(); DiscoverClass dc = new DiscoverClass();
factory = (SummaryStatistics) dc.newInstance( factory = (SummaryStatistics) dc.newInstance(
SummaryStatistics.class, SummaryStatistics.class,
"org.apache.commons.math.stat.univariate.SummaryStatisticsImpl"); "org.apache.commons.math.stat.univariate.SummaryStatisticsImpl");
} catch(Exception ex) { } catch(Exception ex) {
// ignore as default implementation will be used. // ignore as default implementation will be used.
} }
return factory; return factory;
} }
/**
* Return a StatisticalSummaryValues instance reporting current statistics.
*
* @return Current values of statistics
*/
public StatisticalSummary getSummary() {
return new StatisticalSummaryValues(getMean(), getVariance(), getN(),
getMax(), getMin(), getSum());
}
/**
* Adds the value to the data to be summarized
* @param v the value to be added
*/
public abstract void addValue(double v);
/**
* Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm">
* arithmetic mean </a> of the available values
* @return The mean or Double.NaN if no values have been added.
*/
public abstract double getMean();
/**
* Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
* geometric mean </a> of the available values
* @return The geometricMean, Double.NaN if no values have been added,
* or if the productof the available values is less than or equal to 0.
*/
public abstract double getGeometricMean();
/**
* Returns the variance of the available values.
* @return The variance, Double.NaN if no values have been added
* or 0.0 for a single value set.
*/
public abstract double getVariance();
/**
* Returns the standard deviation of the available values.
* @return The standard deviation, Double.NaN if no values have been added
* or 0.0 for a single value set.
*/
public abstract double getStandardDeviation();
/**
* Returns the maximum of the available values
* @return The max or Double.NaN if no values have been added.
*/
public abstract double getMax();
/** /**
* Returns the minimum of the available values * Return a StatisticalSummaryValues instance reporting current statistics.
* @return The min or Double.NaN if no values have been added. *
*/ * @return Current values of statistics
public abstract double getMin(); */
public StatisticalSummary getSummary() {
return new StatisticalSummaryValues(getMean(), getVariance(), getN(),
getMax(), getMin(), getSum());
}
/**
* Adds the value to the data to be summarized
* @param v the value to be added
*/
public abstract void addValue(double v);
/** /**
* Returns the number of available values * Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm">
* @return The number of available values * arithmetic mean </a> of the available values
*/ * @return The mean or Double.NaN if no values have been added.
public abstract long getN(); */
public abstract double getMean();
/** /**
* Returns the sum of the values that have been added to Univariate. * Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
* @return The sum or Double.NaN if no values have been added * geometric mean </a> of the available values
*/ * @return The geometricMean, Double.NaN if no values have been added,
public abstract double getSum(); * or if the productof the available values is less than or equal to 0.
*/
public abstract double getGeometricMean();
/** /**
* Returns the sum of the squares of the available values. * Returns the variance of the available values.
* @return The sum of the squares or Double.NaN if no * @return The variance, Double.NaN if no values have been added
* values have been added. * or 0.0 for a single value set.
*/ */
public abstract double getSumsq(); public abstract double getVariance();
/** /**
* Resets all statistics * Returns the standard deviation of the available values.
*/ * @return The standard deviation, Double.NaN if no values have been added
public abstract void clear(); * or 0.0 for a single value set.
*/
public abstract double getStandardDeviation();
/**
* Returns the maximum of the available values
* @return The max or Double.NaN if no values have been added.
*/
public abstract double getMax();
/**
* Returns the minimum of the available values
* @return The min or Double.NaN if no values have been added.
*/
public abstract double getMin();
/**
* Returns the number of available values
* @return The number of available values
*/
public abstract long getN();
/**
* Returns the sum of the values that have been added to Univariate.
* @return The sum or Double.NaN if no values have been added
*/
public abstract double getSum();
/**
* Returns the sum of the squares of the available values.
* @return The sum of the squares or Double.NaN if no
* values have been added.
*/
public abstract double getSumsq();
/**
* Resets all statistics
*/
public abstract void clear();
} }

View File

@ -29,7 +29,7 @@ import org.apache.commons.math.stat.univariate.summary.SumOfSquares;
/** /**
* Provides a default {@link SummaryStatistics} implementation. * Provides a default {@link SummaryStatistics} implementation.
* *
* @version $Revision: 1.3 $ $Date: 2004/06/01 21:34:35 $ * @version $Revision: 1.4 $ $Date: 2004/06/14 23:26:53 $
*/ */
public class SummaryStatisticsImpl extends SummaryStatistics implements Serializable { public class SummaryStatisticsImpl extends SummaryStatistics implements Serializable {
@ -85,14 +85,14 @@ public class SummaryStatisticsImpl extends SummaryStatistics implements Serializ
* @param value the value to add * @param value the value to add
*/ */
public void addValue(double value) { public void addValue(double value) {
sum.increment(value); sum.increment(value);
sumsq.increment(value); sumsq.increment(value);
min.increment(value); min.increment(value);
max.increment(value); max.increment(value);
sumLog.increment(value); sumLog.increment(value);
geoMean.increment(value); geoMean.increment(value);
secondMoment.increment(value); secondMoment.increment(value);
n++; n++;
} }
/** /**
@ -214,8 +214,8 @@ public class SummaryStatisticsImpl extends SummaryStatistics implements Serializ
} }
/** /**
* Resets all statistics and storage * Resets all statistics and storage
*/ */
public void clear() { public void clear() {
this.n = 0; this.n = 0;
min.clear(); min.clear();

View File

@ -14,6 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.4 $ $Date: 2004/04/26 18:28:17 $ --> <!-- $Revision: 1.5 $ $Date: 2004/06/14 23:26:53 $ -->
<body>Summary statistics based on moments.</body> <body>Summary statistics based on moments.</body>
</html> </html>

View File

@ -14,27 +14,27 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.5 $ $Date: 2004/04/26 18:28:18 $ --> <!-- $Revision: 1.6 $ $Date: 2004/06/14 23:26:53 $ -->
<body> <body>
Generic univariate summary statistic objects. Generic univariate summary statistic objects.
<h3>UnivariateStatistic API Usage Examples:</h3> <h3>UnivariateStatistic API Usage Examples:</h3>
<h4>UnivariateStatistic:</h4> <h4>UnivariateStatistic:</h4>
<code>/* evaluation approach */<br/> double[] values = new double[] { 1, 2, <code>/* evaluation approach */<br/> double[] values = new double[] { 1, 2,
3, 4, 5 };<br/> <span style="font-weight: bold;">UnivariateStatistic stat 3, 4, 5 };<br/> <span style="font-weight: bold;">UnivariateStatistic stat
= new Mean();</span><br/> System.out.println("mean = " + <span = new Mean();</span><br/> System.out.println("mean = " + <span
style="font-weight: bold;">stat.evaluate(values)</span>);<br/> </code> style="font-weight: bold;">stat.evaluate(values)</span>);<br/> </code>
<h4>StorelessUnivariateStatistic:</h4> <h4>StorelessUnivariateStatistic:</h4>
<code>/* incremental approach */<br/> double[] values = new double[] { 1, 2, <code>/* incremental approach */<br/> double[] values = new double[] { 1, 2,
3, 4, 5 };<br/> <span style="font-weight: bold;"> 3, 4, 5 };<br/> <span style="font-weight: bold;">
StorelessUnivariateStatistic stat = new Mean();</span><br/> StorelessUnivariateStatistic stat = new Mean();</span><br/>
System.out.println("mean before adding a value is NaN = " + <span System.out.println("mean before adding a value is NaN = " + <span
style="font-weight: bold;">stat.getResult()</span>);<br/> for (int i = 0; style="font-weight: bold;">stat.getResult()</span>);<br/> for (int i = 0;
i &lt; values.length; i++) {<br/> &nbsp;&nbsp;&nbsp; <span i &lt; values.length; i++) {<br/> &nbsp;&nbsp;&nbsp; <span
style="font-weight: bold;">stat.increment(values[i]);</span><br/> &nbsp;&nbsp;&nbsp; style="font-weight: bold;">stat.increment(values[i]);</span><br/> &nbsp;&nbsp;&nbsp;
System.out.println("current mean = " + <span style="font-weight: bold;"> System.out.println("current mean = " + <span style="font-weight: bold;">
stat2.getResult()</span>);<br/> }<br/> <span style="font-weight: bold;"> stat2.getResult()</span>);<br/> }<br/> <span style="font-weight: bold;">
stat.clear();</span><br/> System.out.println("mean after clear is NaN = " stat.clear();</span><br/> System.out.println("mean after clear is NaN = "
+ <span style="font-weight: bold;">stat.getResult()</span>);</code> + <span style="font-weight: bold;">stat.getResult()</span>);</code>
</body> </body>
</html> </html>

View File

@ -14,6 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.4 $ $Date: 2004/04/26 18:28:17 $ --> <!-- $Revision: 1.5 $ $Date: 2004/06/14 23:26:54 $ -->
<body>Summary statistics based on ranks.</body> <body>Summary statistics based on ranks.</body>
</html> </html>

View File

@ -14,6 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- $Revision: 1.4 $ $Date: 2004/04/26 18:28:16 $ --> <!-- $Revision: 1.5 $ $Date: 2004/06/14 23:26:54 $ -->
<body>Other summary statistics.</body> <body>Other summary statistics.</body>
</html> </html>