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-sandbox/math/src/java/org/apache/commons/math/stat StatUtils.java
Date Tue, 17 Jun 2003 23:23:07 GMT
mdiggory    2003/06/17 16:23:07

  Modified:    math/src/java/org/apache/commons/math/stat StatUtils.java
  Log:
  Addition of product and geometericMean.
  
  Revision  Changes    Path
  1.3       +26 -0     jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StatUtils.java
  
  Index: StatUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StatUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StatUtils.java	17 Jun 2003 23:00:17 -0000	1.2
  +++ StatUtils.java	17 Jun 2003 23:23:07 -0000	1.3
  @@ -88,6 +88,32 @@
   		return accum;
   	}
   
  +    /**
  +     * Returns the product for this collection of values
  +     * @param values Is a double[] containing the values
  +     * @return the product values or Double.NaN if the array is empty
  +	 */
  +    public static double product(double[] values) {
  +        double product = Double.NaN;
  +        if( values.length > 0 ) {
  +            product = 1.0;
  +            for( int i = 0; i < values.length; i++) {
  +                product *= values[i];
  +            }
  +        }
  +        return product;
  +    }
  +    
  +    /**
  +     * Returns the geometric mean for this collection of values
  +     * @param values Is a double[] containing the values
  +     * @return the geometric mean or Double.NaN if the array is empty or
  +     * any of the values are &lt;= 0.
  +	 */
  +    public static double geometricMean(double[] values) {
  +        return Math.pow(product(values),(1.0/values.length));
  +    }
  +
   	/**
        * Returns the <a href=http://www.xycoon.com/arithmetic_mean.htm>
        * arithmetic mean </a> of the available values 
  
  
  

---------------------------------------------------------------------
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