You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by md...@apache.org on 2003/07/15 05:37:11 UTC

cvs commit: jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary Sum.java

mdiggory    2003/07/14 20:37:11

  Modified:    math/src/java/org/apache/commons/math/stat/univariate
                        UnivariateStatistic.java
                        StorelessUnivariateStatistic.java
                        AbstractUnivariateStatistic.java
                        AbstractStorelessUnivariateStatistic.java
               math/src/java/org/apache/commons/math/stat/univariate/summary
                        Sum.java
  Added:       math/src/java/org/apache/commons/math/stat/univariate
                        package.html
  Log:
  minor javadoc cleanup
  
  Revision  Changes    Path
  1.5       +8 -5      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/UnivariateStatistic.java
  
  Index: UnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/UnivariateStatistic.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UnivariateStatistic.java	9 Jul 2003 20:04:13 -0000	1.4
  +++ UnivariateStatistic.java	15 Jul 2003 03:37:10 -0000	1.5
  @@ -55,7 +55,9 @@
   
   /**
    * UnivariateStatistic interface provides methods to evaluate 
  - * double[] based content using a particular algorithm.
  + * double[] based content using an implemented statistical approach. 
  + * The interface provides two "stateless" simple methods to calculate 
  + * a statistic from a double[] based parameter.
    * @version $Revision$ $Date$
    */
   public interface UnivariateStatistic {
  @@ -66,16 +68,17 @@
        * @return the result of the evaluation or Double.NaN 
        * if the array is empty
        */
  -    public double evaluate(double[] values);
  +    double evaluate(double[] values);
   
       /**
  -     * Evaluates part of a double[] returning the result of the evaluation.
  +     * Evaluates part of a double[] returning the result 
  +     * of the evaluation.
        * @param values Is a double[] containing the values
        * @param begin processing at this point in the array
        * @param length processing at this point in the array
        * @return the result of the evaluation or Double.NaN 
        * if the array is empty
        */
  -    public double evaluate(double[] values, int begin, int length); 
  +    double evaluate(double[] values, int begin, int length); 
   
   }
  
  
  
  1.6       +12 -10    jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/StorelessUnivariateStatistic.java
  
  Index: StorelessUnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/StorelessUnivariateStatistic.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StorelessUnivariateStatistic.java	9 Jul 2003 20:04:13 -0000	1.5
  +++ StorelessUnivariateStatistic.java	15 Jul 2003 03:37:10 -0000	1.6
  @@ -54,12 +54,14 @@
   package org.apache.commons.math.stat.univariate;
   
   /**
  - * StorelessUnivariate interface provides methods to increment and access
  - * the internal state of the Statistic. A StorelessUnivariateStatistic does
  - * not require that a double[] storage structure be maintained with the values
  - * in it. As such only a subset of known statistics can actually be implmented
  - * using it. If a Statistic cannot be implemented in a Storeless approach it
  - * should implement the UnivariateStatistic interface directly instead.
  + * Extends the capabilities of UnivariateStatistic with a statefull incremental
  + * strategy through three methods for calculating a statistic without having to
  + * maintain a double[] of the values. Because a StorelessUnivariateStatistic 
  + * does not require that a double[] storage structure be maintained with the 
  + * values in it, there are only a subset of known statistics can actually be 
  + * implemented using it. If a Statistic cannot be implemented in a Storeless 
  + * approach it should implement the UnivariateStatistic interface directly 
  + * instead.
    * @version $Revision$ $Date$
    */
   public interface StorelessUnivariateStatistic extends UnivariateStatistic {
  @@ -69,7 +71,7 @@
        * Implementation.
        * @param d is the value to increment the state by.
        */
  -    public void increment(double d);
  +    void increment(double d);
   
       /**
        * Returns the current state of the statistic after the
  @@ -77,12 +79,12 @@
        * @return value of the statistic, Double.NaN if it
        * has been cleared or just instantiated.
        */
  -    public double getResult();
  +    double getResult();
   
   
       /**
        * Clears all the internal state of the Statistic
        */
  -    public void clear();
  +    void clear();
   
   }
  
  
  
  1.5       +13 -7     jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java
  
  Index: AbstractUnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractUnivariateStatistic.java	9 Jul 2003 20:04:13 -0000	1.4
  +++ AbstractUnivariateStatistic.java	15 Jul 2003 03:37:10 -0000	1.5
  @@ -66,7 +66,8 @@
        * This implementation provides a simple wrapper around the double[]
        * and passes the request onto the evaluate(DoubleArray da) method.
        * 
  -     * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[])
  +     * @see org.apache.commons.math.stat.univariate.
  +     * UnivariateStatistic#evaluate(double[])
        */
       public double evaluate(double[] values) {
           return evaluate(values, 0, values.length);
  @@ -74,7 +75,8 @@
   
       /**
        * Subclasses of AbstractUnivariateStatistc need to implement this method.
  -     * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int)
  +     * @see org.apache.commons.math.stat.univariate.
  +     * UnivariateStatistic#evaluate(double[], int, int)
        */
       public abstract double evaluate(double[] values, int begin, int length);
   
  @@ -87,17 +89,21 @@
        */
       protected boolean test(double[] values, int begin, int length) {
   
  -        if (length > values.length)
  +        if (length > values.length) {
               throw new IllegalArgumentException("length > values.length");
  +        }
   
  -        if (begin + length > values.length)
  +        if (begin + length > values.length) {
               throw new IllegalArgumentException("begin + length > values.length");
  +        }
   
  -        if (values == null)
  +        if (values == null) {
               throw new IllegalArgumentException("input value array is null");
  +        }
   
  -        if (values.length == 0 || length == 0)
  +        if (values.length == 0 || length == 0) {
               return false;
  +        }
   
           return true;
   
  
  
  
  1.5       +5 -2      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java
  
  Index: AbstractStorelessUnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractStorelessUnivariateStatistic.java	9 Jul 2003 20:04:13 -0000	1.4
  +++ AbstractStorelessUnivariateStatistic.java	15 Jul 2003 03:37:10 -0000	1.5
  @@ -70,15 +70,18 @@
        * calculation off to the instantanious increment method. In most cases of
        * StorelessUnivariateStatistic this is never really used because more 
        * efficient algorithms are available for that statistic.
  -     * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int)
  +     * @see org.apache.commons.math.stat.univariate.
  +     * UnivariateStatistic#evaluate(double[], int, int)
        */
       public double evaluate(double[] values, int begin, int length) {
           if (this.test(values, begin, length)) {
               this.clear();
  +            int l = begin + length;
               for (int i = begin; i < begin + length; i++) {
                   increment(values[i]);
               }
           }
           return getResult();
       }
  +
   }
  
  
  
  1.1                  jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <body>
  <h3>UnivariateStatistic API Usage Examples:</h3>
  
  <h4>UnivariateStatistic:</h4>
  
  <code> 
  /* evaluation approach */<br/>
  double[] values = new double[] { 1, 2, 3, 4, 5 };<br/>
  <span style="font-weight: bold;">UnivariateStatistic stat = new Mean();</span><br/>
  System.out.println("mean = " + 
  <span style="font-weight: bold;">stat.evaluate(values)</span>);<br/>
  </code>
  
  <h4>StorelessUnivariateStatistic:</h4>
  
  <code> 
  /* incremental approach */<br>
  double[] values = new double[] { 1, 2, 3, 4, 5 };<br/>
  <span style="font-weight: bold;">StorelessUnivariateStatistic stat =
  new Mean();</span><br/>
  System.out.println("mean before adding a value is NaN = " + <span
   style="font-weight: bold;">stat.getResult()</span>);<br/>
  for (int i = 0; i &lt; values.length; i++) {<br/>
  &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">stat.increment(values[i]);</span><br>
  &nbsp;&nbsp;&nbsp; System.out.println("current mean = " + <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 = " + <span
   style="font-weight: bold;">stat.getResult()</span>); 
  </code>
  
  </body>
  </html>
  
  
  
  1.7       +6 -7      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java
  
  Index: Sum.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Sum.java	9 Jul 2003 20:04:13 -0000	1.6
  +++ Sum.java	15 Jul 2003 03:37:11 -0000	1.7
  @@ -53,6 +53,7 @@
    */
   package org.apache.commons.math.stat.univariate.summary;
   
  +import org.apache.commons.collections.primitives.DoubleIterator;
   import org
       .apache
       .commons
  @@ -75,10 +76,10 @@
        * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
        */
       public void increment(double d) {
  -        if (Double.isNaN(value )) {
  -            value  = d;
  +        if (Double.isNaN(value)) {
  +            value = d;
           } else {
  -            value  += d;
  +            value += d;
           }
       }
   
  @@ -88,7 +89,7 @@
       public double getResult() {
           return value;
       }
  -    
  +
       /**
        * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#clear()
        */
  @@ -114,7 +115,5 @@
           }
           return sum;
       }
  -
  -
   
   }
  
  
  

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