/**
   * Parses a given list of options.
   *
   * <p>
   * <!-- options-start -->
   * Valid options are:
   *
   * <p>
   *
   * <pre> -N &lt;num&gt;
   *  number of clusters.
   *  (default 2).</pre>
   *
   * <pre> -P
   *  Initialize using the k-means++ method.
   * </pre>
   *
   * <pre> -V
   *  Display std. deviations for centroids.
   * </pre>
   *
   * <pre> -M
   *  Replace missing values with mean/mode.
   * </pre>
   *
   * <pre> -A &lt;classname and options&gt;
   *  Distance function to use.
   *  (default: weka.core.EuclideanDistance)</pre>
   *
   * <pre> -I &lt;num&gt;
   *  Maximum number of iterations.
   * </pre>
   *
   * <pre> -O
   *  Preserve order of instances.
   * </pre>
   *
   * <pre> -fast
   *  Enables faster distance calculations, using cut-off values.
   *  Disables the calculation/output of squared errors/distances.
   * </pre>
   *
   * <pre> -S &lt;num&gt;
   *  Random number seed.
   *  (default 10)</pre>
   *
   * <!-- options-end -->
   *
   * @param options the list of options as an array of strings
   * @throws Exception if an option is not supported
   */
  public void setOptions(String[] options) throws Exception {

    String optionString = Utils.getOption("I", options);
    if (optionString.length() != 0) {
      setMaxIterations(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption("max", options);
    if (optionString.length() > 0) {
      setMaxNumClusters(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption("min", options);
    if (optionString.length() > 0) {
      setMinNumClusters(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption("restarts", options);
    if (optionString.length() > 0) {
      setRestarts(Integer.parseInt(optionString));
    }

    setManuallySelectNumClusters(Utils.getFlag("manual", options));
    setPrintDebug(Utils.getFlag("debug", options));
    initializeWithKMeansPlusPlus = Utils.getFlag('P', options);

    String distFunctionClass = Utils.getOption('A', options);
    if (distFunctionClass.length() != 0) {
      String distFunctionClassSpec[] = Utils.splitOptions(distFunctionClass);
      if (distFunctionClassSpec.length == 0) {
        throw new Exception("Invalid DistanceFunction specification string.");
      }
      String className = distFunctionClassSpec[0];
      distFunctionClassSpec[0] = "";

      setDistanceFunction(
          (DistanceFunction)
              Utils.forName(DistanceFunction.class, className, distFunctionClassSpec));
    } else {
      setDistanceFunction(new EuclideanDistance());
    }

    super.setOptions(options);
  }
Beispiel #2
0
  /**
   * Parses a given list of options.
   *
   * <p>
   * <!-- options-start -->
   * Valid options are:
   *
   * <p>
   *
   * <pre>
   * -I &lt;num&gt;
   *  maximum number of iterations
   *  (default 100).
   * </pre>
   *
   * <pre>
   * -M &lt;num&gt;
   *  minimum number of changes in a single iteration
   *  (default 0).
   * </pre>
   *
   * <pre>
   * -N &lt;num&gt;
   *  number of clusters.
   *  (default 2).
   * </pre>
   *
   * <pre>
   * -R &lt;num&gt;
   *  number of restarts.
   *  (default 5).
   * </pre>
   *
   * <pre>
   * -U
   *  set not to normalize the data
   *  (default true).
   * </pre>
   *
   * <pre>
   * -V
   *  set to output debug info
   *  (default false).
   * </pre>
   *
   * <pre>
   * -S &lt;num&gt;
   *  Random number seed.
   *  (default 1)
   * </pre>
   *
   * <!-- options-end -->
   *
   * @param options the list of options as an array of strings
   * @throws Exception if an option is not supported
   */
  @Override
  public void setOptions(String[] options) throws Exception {
    String optionString = Utils.getOption('I', options);
    if (optionString.length() != 0) {
      setMaxIterations(Integer.parseInt(optionString));
    }
    optionString = Utils.getOption('M', options);
    if (optionString.length() != 0) {
      setMinChange((new Integer(optionString)).intValue());
    }
    optionString = Utils.getOption('N', options);
    if (optionString.length() != 0) {
      setNumClusters(Integer.parseInt(optionString));
    }
    optionString = Utils.getOption('R', options);
    if (optionString.length() != 0) {
      setNumRestarts((new Integer(optionString)).intValue());
    }
    setNotUnifyNorm(Utils.getFlag('U', options));
    setDebug(Utils.getFlag('V', options));

    super.setOptions(options);
  }