protected Distribution findBestFit ( final List < V > col , Adapter adapter , int d , double [ ] test ) { if ( estimators . size ( ) == 1 ) { return estimators . get ( 0 ) . estimate ( col , adapter ) ; } Distribution best = null ; double bestq = Double . POSITIVE_INFINITY ; trials : for ( DistributionEstimator < ? > est : estimators ) { try { Distribution dist = est . estimate ( col , adapter ) ; for ( int i = 0 ; i < test . length ; i ++ ) { test [ i ] = dist . cdf ( col . get ( i ) . doubleValue ( d ) ) ; if ( Double . isNaN ( test [ i ] ) ) { LOG . warning ( "Got NaN after fitting " + est + ": " + dist ) ; continue trials ; } if ( Double . isInfinite ( test [ i ] ) ) { LOG . warning ( "Got infinite value after fitting " + est + ": " + dist ) ; continue trials ; } } Arrays . sort ( test ) ; double q = KolmogorovSmirnovTest . simpleTest ( test ) ; if ( LOG . isVeryVerbose ( ) ) { LOG . veryverbose ( "Estimator " + est + " (" + dist + ") has maximum deviation " + q + " for dimension " + d ) ; } if ( best == null || q < bestq ) { best = dist ; bestq = q ; } } catch ( ArithmeticException e ) { if ( LOG . isVeryVerbose ( ) ) { LOG . veryverbose ( "Fitting distribution " + est + " failed: " + e . getMessage ( ) ) ; } continue trials ; } } if ( LOG . isVerbose ( ) ) { LOG . verbose ( "Best fit for dimension " + d + ": " + best ) ; } return best ; }
Find the best fitting distribution .