question: public static double calibrateThreshold ( ArrayList < double [ ] > Y , double LC_train ) { if ( Y . size ( ) <= 0 ) return 0.5 ; int N = Y . size ( ) ; ArrayList < Double > big = new ArrayList < Double > ( ) ; for ( double y [ ] : Y ) { for ( double y_ : y ) { big . add ( y_ ) ; } } Collections . sort ( big ) ; int i = big . size ( ) - ( int ) Math . round ( LC_train * ( double ) N ) ; if ( N == big . size ( ) ) { if ( i + 1 == N ) return ( big . get ( N - 2 ) + big . get ( N - 1 ) / 2.0 ) ; if ( i + 1 >= N ) return 1.0 ; else return Math . max ( ( ( double ) ( big . get ( i ) + big . get ( i + 1 ) ) / 2.0 ) , 0.00001 ) ; } return Math . max ( ( ( double ) ( big . get ( i ) + big . get ( Math . max ( i + 1 , N - 1 ) ) ) ) / 2.0 , 0.00001 ) ; }
target:  CalibrateThreshold - Calibrate a threshold using PCut: the threshold which results in the best approximation of the label cardinality of the training set.