question: public static < A > int [ ] discretize ( NumberArrayAdapter < ? , A > adapter , A data , final int len , final int bins ) { double min = adapter . getDouble ( data , 0 ) , max = min ; for ( int i = 1 ; i < len ; i ++ ) { double v = adapter . getDouble ( data , i ) ; if ( v < min ) { min = v ; } else if ( v > max ) { max = v ; } } final double scale = ( max > min ) ? bins / ( max - min ) : 1 ; int [ ] discData = new int [ len ] ; for ( int i = 0 ; i < len ; i ++ ) { int bin = ( int ) Math . floor ( ( adapter . getDouble ( data , i ) - min ) * scale ) ; discData [ i ] = bin < 0 ? 0 : bin >= bins ? bins - 1 : bin ; } return discData ; }
target:  Discretize a data set into equi-width bin numbers.