Addition of product and geometericMean.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140919 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
175c7c5fce
commit
d4f6a5c818
|
@ -89,6 +89,32 @@ public class StatUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 <= 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
|
||||
* @param values Is a double[] containing the values
|
||||
|
|
Loading…
Reference in New Issue