public static Discretization discretize(double[] _data,double[] cutoffs,String variableName,List<String> categories){
  if (cutoffs == null) {
    throw new NullPointerException();
  }
  for (int i=0; i < cutoffs.length - 1; i++) {
    if (!(cutoffs[i] <= cutoffs[i + 1])) {
      throw new NullPointerException("Cutoffs must be in nondecreasing order.");
    }
  }
  if (variableName == null) {
    throw new NullPointerException();
  }
  int numCategories=cutoffs.length + 1;
  if (categories != null && categories.size() != numCategories) {
    throw new IllegalArgumentException("If specified, the list of " + "categories names must be one longer than the length of " + "the cutoffs array.");
  }
  DiscreteVariable variable;
  if (categories == null) {
    variable=new DiscreteVariable(variableName,numCategories);
  }
 else {
    variable=new DiscreteVariable(variableName,categories);
  }
  int[] discreteData=new int[_data.length];
  loop:   for (int i=0; i < _data.length; i++) {
    if (Double.isNaN(_data[i])) {
      discreteData[i]=DiscreteVariable.MISSING_VALUE;
      continue;
    }
    for (int j=0; j < cutoffs.length; j++) {
      if (_data[i] > Double.NEGATIVE_INFINITY && _data[i] < Double.POSITIVE_INFINITY && _data[i] < cutoffs[j]) {
        discreteData[i]=j;
        continue loop;
      }
    }
    discreteData[i]=cutoffs.length;
  }
  return new Discretization(variable,discreteData);
}

public static Discretization discretize ( double [ ] _data , double [ ] cutoffs , String variableName , List < String > categories ) { if ( cutoffs == null ) { throw new NullPointerException ( ) ; } for ( int i = 0 ; i < cutoffs . length - 1 ; i ++ ) { if ( ! ( cutoffs [ i ] <= cutoffs [ i + 1 ] ) ) { throw new NullPointerException ( "Cutoffs must be in nondecreasing order." ) ; } } if ( variableName == null ) { throw new NullPointerException ( ) ; } int numCategories = cutoffs . length + 1 ; if ( categories != null && categories . size ( ) != numCategories ) { throw new IllegalArgumentException ( "If specified, the list of " + "categories names must be one longer than the length of " + "the cutoffs array." ) ; } DiscreteVariable variable ; if ( categories == null ) { variable = new DiscreteVariable ( variableName , numCategories ) ; } else { variable = new DiscreteVariable ( variableName , categories ) ; } int [ ] discreteData = new int [ _data . length ] ; loop : for ( int i = 0 ; i < _data . length ; i ++ ) { if ( Double . isNaN ( _data [ i ] ) ) { discreteData [ i ] = DiscreteVariable . MISSING_VALUE ; continue ; } for ( int j = 0 ; j < cutoffs . length ; j ++ ) { if ( _data [ i ] > Double . NEGATIVE_INFINITY && _data [ i ] < Double . POSITIVE_INFINITY && _data [ i ] < cutoffs [ j ] ) { discreteData [ i ] = j ; continue loop ; } } discreteData [ i ] = cutoffs . length ; } return new Discretization ( variable , discreteData ) ; }
discretizes the continuous data in the given column using the specified cutoffs and category names . the following scheme is used . if cutoffs [ i - 1 ] < v < = cutoffs [ i ] ( where cutoffs [ - 1 ] = negative infinity ) , then v is mapped to category i . if category names are supplied , the discrete column returned will use these category names .
