public static double geometricMean ( FlatDataCollection flatDataCollection ) { int n = 0 ; double geometricMean = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { if ( v <= 0.0 ) { throw new IllegalArgumentException ( "Negative or zero values are not allowed." ) ; } ++ n ; geometricMean += Math . log ( v ) ; } } geometricMean = Math . exp ( geometricMean / n ) ; return geometricMean ; }
Calculates Geometric Mean