Beispiel #1
0
  /**
   * Parses a given list of options.
   *
   * @param options the list of options as an array of strings
   * @exception Exception if an option is not supported
   */
  public void setOptions(String[] options) throws Exception {

    String optionString = Utils.getOption('N', options);

    if (optionString.length() != 0) {
      setNumClusters(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption('S', options);

    if (optionString.length() != 0) {
      setSeed(Integer.parseInt(optionString));
    }
  }
Beispiel #2
0
  /**
   * Parses a given list of options. Valid options are:
   *
   * <p>-D <br>
   * Turn on debugging output.
   *
   * <p>-S seed <br>
   * Random number seed (default 1).
   *
   * <p>-B classifierstring <br>
   * Classifierstring should contain the full class name of a scheme included for selection followed
   * by options to the classifier (required, option should be used once for each classifier).
   *
   * <p>-X num_folds <br>
   * Use cross validation error as the basis for classifier selection. (default 0, is to use error
   * on the training data instead)
   *
   * <p>
   *
   * @param options the list of options as an array of strings
   * @exception Exception if an option is not supported
   */
  public void setOptions(String[] options) throws Exception {

    setDebug(Utils.getFlag('D', options));

    String numFoldsString = Utils.getOption('X', options);
    if (numFoldsString.length() != 0) {
      setNumFolds(Integer.parseInt(numFoldsString));
    } else {
      setNumFolds(0);
    }

    String randomString = Utils.getOption('S', options);
    if (randomString.length() != 0) {
      setSeed(Integer.parseInt(randomString));
    } else {
      setSeed(1);
    }

    // Iterate through the schemes
    FastVector classifiers = new FastVector();
    while (true) {
      String classifierString = Utils.getOption('B', options);
      if (classifierString.length() == 0) {
        break;
      }
      String[] classifierSpec = Utils.splitOptions(classifierString);
      if (classifierSpec.length == 0) {
        throw new Exception("Invalid classifier specification string");
      }
      String classifierName = classifierSpec[0];
      classifierSpec[0] = "";
      classifiers.addElement(Classifier.forName(classifierName, classifierSpec));
    }
    if (classifiers.size() <= 1) {
      throw new Exception("At least two classifiers must be specified" + " with the -B option.");
    } else {
      Classifier[] classifiersArray = new Classifier[classifiers.size()];
      for (int i = 0; i < classifiersArray.length; i++) {
        classifiersArray[i] = (Classifier) classifiers.elementAt(i);
      }
      setClassifiers(classifiersArray);
    }
  }
Beispiel #3
0
  public static void main(String args[]) {
    Timers timer = new Timers();
    try {
      // Get the data set path.
      String referenceFile = Utils.getOption('r', args);
      String queryFile = Utils.getOption('q', args);
      if (referenceFile.length() == 0)
        throw new IllegalArgumentException(
            "Required option: File containing" + "the reference dataset.");

      // Load input dataset.
      DataSource source = new DataSource(referenceFile);
      Instances referenceData = source.getDataSet();

      Instances queryData = null;
      if (queryFile.length() != 0) {
        source = new DataSource(queryFile);
        queryData = source.getDataSet();
      }

      timer.StartTimer("total_time");

      // Get all the parameters.
      String leafSize = Utils.getOption('l', args);
      String neighbors = Utils.getOption('k', args);

      // Validate options.
      int k = 0;
      if (neighbors.length() == 0) {
        throw new IllegalArgumentException(
            "Required option: Number of " + "furthest neighbors to find.");
      } else {
        k = Integer.parseInt(neighbors);
        if (k < 1 || k > referenceData.numInstances())
          throw new IllegalArgumentException("[Fatal] Invalid k");
      }

      int l = 20;
      if (leafSize.length() != 0) l = Integer.parseInt(leafSize);

      // Create KDTree.
      KDTree tree = new KDTree();
      tree.setMaxInstInLeaf(l);
      tree.setInstances(referenceData);

      // Perform All K-Nearest-Neighbors.
      if (queryFile.length() != 0) {
        for (int i = 0; i < queryData.numInstances(); i++) {
          Instances out = tree.kNearestNeighbours(queryData.instance(i), k);
        }
      } else {
        for (int i = 0; i < referenceData.numInstances(); i++) {
          Instances out = tree.kNearestNeighbours(referenceData.instance(i), k);
        }
      }

      timer.StopTimer("total_time");
      timer.PrintTimer("total_time");
    } catch (IOException e) {
      System.err.println(USAGE);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }