commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdigg...@apache.org
Subject cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate DescriptiveStatisticsImpl.java AbstractUnivariateStatistic.java SummaryStatistics.java AbstractStorelessUnivariateStatistic.java DescriptiveStatistics.java SummaryStatisticsImpl.java AbstractDescriptiveStatistics.java
Date Tue, 01 Jun 2004 21:34:35 GMT
mdiggory    2004/06/01 14:34:35

  Modified:    math/src/java/org/apache/commons/math/stat/univariate
                        DescriptiveStatisticsImpl.java
                        AbstractUnivariateStatistic.java
                        SummaryStatistics.java
                        AbstractStorelessUnivariateStatistic.java
                        DescriptiveStatistics.java
                        SummaryStatisticsImpl.java
  Removed:     math/src/java/org/apache/commons/math/stat/univariate
                        AbstractDescriptiveStatistics.java
  Log:
  Consolidated AbstractDescriptiveStatistics into DescriptiveStatistics. Added Serialization
interfaces where required.
  
  Revision  Changes    Path
  1.6       +5 -2      jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/DescriptiveStatisticsImpl.java
  
  Index: DescriptiveStatisticsImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/DescriptiveStatisticsImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DescriptiveStatisticsImpl.java	23 May 2004 00:30:01 -0000	1.5
  +++ DescriptiveStatisticsImpl.java	1 Jun 2004 21:34:35 -0000	1.6
  @@ -25,8 +25,11 @@
    * 
    * @version $Revision$ $Date$
    */
  -public class DescriptiveStatisticsImpl extends AbstractDescriptiveStatistics implements
Serializable {
  +public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements Serializable
{
   
  +    /** Serializable version identifier */
  +    static final long serialVersionUID = -1868088725461221010L;
  +    
   	/** hold the window size **/
   	protected int windowSize;
       
  
  
  
  1.17      +7 -2      jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java
  
  Index: AbstractUnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractUnivariateStatistic.java	27 Apr 2004 16:42:34 -0000	1.16
  +++ AbstractUnivariateStatistic.java	1 Jun 2004 21:34:35 -0000	1.17
  @@ -15,6 +15,8 @@
    */
   package org.apache.commons.math.stat.univariate;
   
  +import java.io.Serializable;
  +
   /**
    * Abstract Implementation for UnivariateStatistics.
    * Provides the ability to extend polymophically so that
  @@ -22,7 +24,10 @@
    * @version $Revision$ $Date$
    */
   public abstract class AbstractUnivariateStatistic
  -    implements UnivariateStatistic {
  +    implements UnivariateStatistic, Serializable {
  +    
  +    /** Serialization UID */
  +    static final long serialVersionUID = -8007759382851708045L;
   
       /**
        * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[])
  
  
  
  1.6       +5 -2      jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/SummaryStatistics.java
  
  Index: SummaryStatistics.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/SummaryStatistics.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SummaryStatistics.java	19 May 2004 14:16:31 -0000	1.5
  +++ SummaryStatistics.java	1 Jun 2004 21:34:35 -0000	1.6
  @@ -24,8 +24,11 @@
    * 
    * @version $Revision$ $Date$
    */
  -public abstract class SummaryStatistics implements Serializable, StatisticalSummary {
  +public abstract class SummaryStatistics implements StatisticalSummary, Serializable {
   
  +    /** Serialization UID */
  +    static final long serialVersionUID = -6400596334135654825L;
  +    
   	/**
   	 * Create an instance of a <code>SummaryStatistics</code>
        * @param cls the type of <code>SummaryStatistics</code> object to
  
  
  
  1.15      +7 -2      jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java
  
  Index: AbstractStorelessUnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AbstractStorelessUnivariateStatistic.java	21 Mar 2004 21:57:18 -0000	1.14
  +++ AbstractStorelessUnivariateStatistic.java	1 Jun 2004 21:34:35 -0000	1.15
  @@ -15,6 +15,8 @@
    */
   package org.apache.commons.math.stat.univariate;
   
  +import java.io.Serializable;
  +
   /**
    *
    * Abstract Implementation for the {@link StorelessUnivariateStatistic} interface.
  @@ -25,8 +27,11 @@
    */
   public abstract class AbstractStorelessUnivariateStatistic
       extends AbstractUnivariateStatistic
  -    implements StorelessUnivariateStatistic {
  +    implements StorelessUnivariateStatistic, Serializable {
   
  +    /** Serialization UID */
  +    static final long serialVersionUID = -44915725420072521L;
  +    
       /**
        * This default implementation just calls {@link #increment} in a loop over the input
array and 
        * then {@link #getResult} to compute the return value.  
  
  
  
  1.6       +82 -15    jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/DescriptiveStatistics.java
  
  Index: DescriptiveStatistics.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/DescriptiveStatistics.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DescriptiveStatistics.java	23 May 2004 00:56:15 -0000	1.5
  +++ DescriptiveStatistics.java	1 Jun 2004 21:34:35 -0000	1.6
  @@ -16,8 +16,19 @@
   package org.apache.commons.math.stat.univariate;
   
   import java.io.Serializable;
  +import java.util.Arrays;
   
   import org.apache.commons.discovery.tools.DiscoverClass;
  +import org.apache.commons.math.stat.univariate.moment.GeometricMean;
  +import org.apache.commons.math.stat.univariate.moment.Kurtosis;
  +import org.apache.commons.math.stat.univariate.moment.Mean;
  +import org.apache.commons.math.stat.univariate.moment.Skewness;
  +import org.apache.commons.math.stat.univariate.moment.Variance;
  +import org.apache.commons.math.stat.univariate.rank.Max;
  +import org.apache.commons.math.stat.univariate.rank.Min;
  +import org.apache.commons.math.stat.univariate.rank.Percentile;
  +import org.apache.commons.math.stat.univariate.summary.Sum;
  +import org.apache.commons.math.stat.univariate.summary.SumOfSquares;
   
   
   /**
  @@ -25,8 +36,11 @@
    * 
    * @version $Revision$ $Date$
    */
  -public abstract class DescriptiveStatistics implements Serializable, StatisticalSummary
{
  -
  +public abstract class DescriptiveStatistics implements StatisticalSummary, Serializable
{
  +    
  +    /** Serialization UID */
  +    static final long serialVersionUID = 5188298269533339922L;
  +    
   	/**
   	 * Create an instance of a <code>DescriptiveStatistics</code>
        * @param cls the type of <code>DescriptiveStatistics</code> object to
  @@ -94,7 +108,9 @@
   	 * arithmetic mean </a> of the available values 
   	 * @return The mean or Double.NaN if no values have been added.
   	 */
  -	public abstract double getMean();
  +    public double getMean() {
  +    	return apply(new Mean());
  +    }
   
   	/** 
   	 * Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
  @@ -102,21 +118,35 @@
   	 * @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();
  +    public double getGeometricMean() {
  +    	return apply(new GeometricMean());
  +    }
   
   	/** 
   	 * 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();
  +    public double getVariance() {
  +    	return apply(new Variance());
  +    }
   
   	/** 
   	 * 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();
  +    public double getStandardDeviation() {
  +    	double stdDev = Double.NaN;
  +    	if (getN() > 0) {
  +    		if (getN() > 1) {
  +    			stdDev = Math.sqrt(getVariance());
  +    		} else {
  +    			stdDev = 0.0;
  +    		}
  +    	}
  +    	return (stdDev);
  +    }
   
   	/**
   	 * Returns the skewness of the available values. Skewness is a 
  @@ -124,7 +154,9 @@
   	 * @return The skewness, Double.NaN if no values have been added 
   	 * or 0.0 for a value set &lt;=2. 
   	 */
  -	public abstract double getSkewness();
  +    public double getSkewness() {
  +    	return apply(new Skewness());
  +    }
   
   	/**
   	 * Returns the Kurtosis of the available values. Kurtosis is a 
  @@ -132,19 +164,25 @@
   	 * @return The kurtosis, Double.NaN if no values have been added, or 0.0 
   	 * for a value set &lt;=3. 
   	 */
  -	public abstract double getKurtosis();
  +    public double getKurtosis() {
  +    	return apply(new Kurtosis());
  +    }
   
   	/** 
   	 * Returns the maximum of the available values
   	 * @return The max or Double.NaN if no values have been added.
   	 */
  -	public abstract double getMax();
  +    public double getMax() {
  +    	return apply(new Max());
  +    }
   
   	/** 
   	* Returns the minimum of the available values
   	* @return The min or Double.NaN if no values have been added.
   	*/
  -	public abstract double getMin();
  +    public double getMin() {
  +    	return apply(new Min());
  +    }
   
   	/** 
   	 * Returns the number of available values
  @@ -156,14 +194,18 @@
   	 * 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();
  +    public double getSum() {
  +    	return apply(new Sum());
  +    }
   
   	/**
   	 * 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();
  +    public double getSumsq() {
  +    	return apply(new SumOfSquares());
  +    }
   
   	/** 
   	 * Resets all statistics and storage
  @@ -208,7 +250,11 @@
        * @return returns the current set of 
        * numbers sorted in ascending order        
        */
  -	public abstract double[] getSortedValues();
  +    public double[] getSortedValues() {
  +        double[] sort = getValues();
  +        Arrays.sort(sort);
  +        return sort;
  +    }
   
       /**
        * Returns the element at the specified index
  @@ -234,8 +280,29 @@
        * @return An estimate for the pth percentile of the stored data 
        * values
        */
  -	public abstract double getPercentile(double p);
  +    public double getPercentile(double p) {
  +    	return apply(new Percentile(p));
  +    }
   	
  +    /**
  +     * Generates a text report displaying
  +     * univariate statistics from values that
  +     * have been added.
  +     * @return String with line feeds displaying statistics
  +     */
  +    public String toString() {
  +    	StringBuffer outBuffer = new StringBuffer();
  +    	outBuffer.append("UnivariateImpl:\n");
  +    	outBuffer.append("n: " + getN() + "\n");
  +    	outBuffer.append("min: " + getMin() + "\n");
  +    	outBuffer.append("max: " + getMax() + "\n");
  +    	outBuffer.append("mean: " + getMean() + "\n");
  +    	outBuffer.append("std dev: " + getStandardDeviation() + "\n");
  +    	outBuffer.append("skewness: " + getSkewness() + "\n");
  +    	outBuffer.append("kurtosis: " + getKurtosis() + "\n");
  +    	return outBuffer.toString();
  +    }
  +    
   	/**
   	 * Apply the given statistic to the data associated with this set of statistics.
   	 * @param stat the statistic to apply
  
  
  
  1.3       +6 -2      jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/SummaryStatisticsImpl.java
  
  Index: SummaryStatisticsImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/SummaryStatisticsImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SummaryStatisticsImpl.java	27 Apr 2004 04:37:59 -0000	1.2
  +++ SummaryStatisticsImpl.java	1 Jun 2004 21:34:35 -0000	1.3
  @@ -15,6 +15,7 @@
    */
   package org.apache.commons.math.stat.univariate;
   
  +import java.io.Serializable;
   import org.apache.commons.math.stat.univariate.moment.SecondMoment;
   import org.apache.commons.math.stat.univariate.moment.GeometricMean;
   import org.apache.commons.math.stat.univariate.moment.Mean;
  @@ -30,7 +31,10 @@
    * 
    * @version $Revision$ $Date$  
    */
  -public class SummaryStatisticsImpl extends SummaryStatistics {
  +public class SummaryStatisticsImpl extends SummaryStatistics implements Serializable {
  +
  +    /** Serializable version identifier */
  +    static final long serialVersionUID = 8787174276883311692L;
   
       /** count of values that have been added */
       protected long n = 0;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message