code: public int[] feature(double[] x) {
          if (x.length != attributes.length) {
              throw new IllegalArgumentException(String.format("Invalid feature vector size %d, expected %d", x.length, attributes.length));
          }
          
          int[] features = new int[attributes.length];
          for (int i = 0; i < features.length; i++) {
              int f = (int) x[i];
              if (Math.floor(x[i]) != x[i] || f < 0 || f >= attributes[i].size()) {
                  throw new IllegalArgumentException(String.format("Invalid value of attribute %s: %d", attributes[i].toString(), f));
              }
              
              features[i] = f + base[i];
          }
          
          return features;
      }
docs: Generates the compact representation of sparse binary features for given object.
  @param x an object of interest.
  @return an integer array of nonzero binary features.