public static Range [ ] scoresToRanges ( float [ ] scores , float probability ) { assert scores != null && scores . length > 0 ; assert probability > 0 && probability < 1 ; int count = 0 ; int regionLen = 0 ; List < Range > ranges = new ArrayList < Range > ( ) ; for ( float score : scores ) { count ++ ; // Round to 2 decimal points before comparison score = ( float ) ( Math . round ( score * 100.0 ) / 100.0 ) ; if ( score > probability ) { regionLen ++ ; } else { if ( regionLen > 0 ) { ranges . add ( new Range ( count - regionLen , count - 1 , score ) ) ; } regionLen = 0 ; } } // In case of the range to boundary runs to the very end of the sequence if ( regionLen > 1 ) { ranges . add ( new Range ( count - regionLen + 1 , count , scores [ scores . length - 1 ] ) ) ; } return ranges . toArray ( new Range [ ranges . size ( ) ] ) ; }
Convert raw scores to ranges . Gives ranges for given probability of disorder value