Esempio n. 1
0
  /**
   * Returns the number of distinct values of a given attribute. Returns the number of instances if
   * the attribute is a string attribute. The value 'missing' is not counted.
   *
   * @param attIndex the attribute (index starts with 0)
   * @return the number of distinct values of a given attribute
   */
  public int numDistinctValues(int attIndex) {

    MyAttribute att = getAttribute(attIndex);
    if (att.isContinuous()) {
      double[] attVals = attributeToDoubleArray(attIndex);
      Utilities.mergeSort(attVals, attVals.length);
      double prev = 0;
      int counter = 0;
      for (int i = 0; i < size(); i++) {

        if (attVals[i] == Double.NaN) {
          break;
        }
        if ((i == 0) || (attVals[i] > prev)) {
          prev = attVals[i];
          counter++;
        }
      }
      return counter;
    } else {
      return att.numValues();
    }
  }