Java Code Examples for weka.core.Utils#splitOptions()

The following examples show how to use weka.core.Utils#splitOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopDownConstructor.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses a given list of options.
 * 
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -S &lt;classname and options&gt;
 *  Ball splitting algorithm to use.</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 {

  super.setOptions(options);
  
  String optionString = Utils.getOption('S', options);
  if(optionString.length() != 0) {
    String nnSearchClassSpec[] = Utils.splitOptions(optionString);
    if(nnSearchClassSpec.length == 0) { 
      throw new Exception("Invalid BallSplitter specification string."); 
    }
    String className = nnSearchClassSpec[0];
    nnSearchClassSpec[0] = "";

    setBallSplitter( (BallSplitter)
                          Utils.forName( BallSplitter.class, 
                                         className, nnSearchClassSpec) );
  }
  else {
    setBallSplitter(new PointsClosestToFurthestChildren());  
  }
}
 
Example 2
Source File: RecentFilesHandlerWithCommandline.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes the setup container using the string.
 *
 * @param s		the string to use
 */
public Setup(String s) {
	String[]	parts;
	String[]	options;
	String		cname;

			parts = s.split("\t");
	if (parts.length != 2)
		return;

	m_File = new File(parts[0]);

	try {
		options    = Utils.splitOptions(parts[1]);
		cname      = options[0];
		options[0] = "";
		m_Handler  = Utils.forName(Object.class, cname, options);
	}
	catch (Exception e) {
		return;
	}
}
 
Example 3
Source File: OptionUtils.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Turns a commandline into an object.
 *
 * @param cls           the class that the commandline is expected to be
 * @param cmdline       the commandline to parse
 * @return              the object, null if failed to instantiate
 * @throws Exception    if parsing fails
 */
public static <T> T fromCommandLine(Class<T> cls, String cmdline) throws Exception {
	String[]    options;
	String      classname;

	options    = Utils.splitOptions(cmdline);
	classname  = options[0];
	options[0] = "";
	return (T) Utils.forName(cls, classname, options);
}
 
Example 4
Source File: ParamSet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Goes through a list of strings and builds the corresponding parameter set
 * @param options
 * @throws Exception
 */
@Override
public void setOptionsList(final List<String> options) throws
    Exception {
    for(int i = 0; i < options.size(); i++) {
        String option = options.get(i);
        String flag = StrUtils.unflagify(option);
        // if the flag is an option (i.e. key value pair, not just a flag, see above comment)
        if(StrUtils.isOption(option, options)) {
            String[] subOptions = Utils.splitOptions(option);
            String optionValue = subOptions[0];
            subOptions[0] = "";
            // get the value
            Object value = StrUtils.fromOptionValue(optionValue);
            if(value instanceof ParamHandler) {
                // handle sub parameters
                ParamSet paramSet = new ParamSet();
                paramSet.setOptions(subOptions);
                add(flag, (ParamHandler) value, paramSet);
            } else {
                add(flag, value);
            }
            options.set(i, "");
            i++;
        } else {
            add(flag, true);
        }
        options.set(i, "");
    }
}
 
Example 5
Source File: ZeroShotUtil.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String[] mapRFInputsToWekaOptions(double i, double kFraction, double m, double depth, double kNumAttributes) throws Exception {
	int iRounded = (int) Math.round(i);
	int k = (int) Math.ceil(kNumAttributes * kFraction);
	int mRounded = (int) Math.round(m);
	int depthRounded = (int) Math.round(depth);

	return Utils.splitOptions(" -I " + iRounded + " -K " + k + " -M " + mRounded + " -depth " + depthRounded);
}
 
Example 6
Source File: MultipleClassifiersCombiner.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses a given list of options. Valid options are:<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>
 *
 * @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 {

  // Iterate through the schemes
  Vector classifiers = new Vector();
  while (true) {
    String classifierString = Utils.getOption('B', options);
    if (classifierString.length() == 0) {
      break;
    }
    String [] classifierSpec = Utils.splitOptions(classifierString);
    if (classifierSpec.length == 0) {
      throw new IllegalArgumentException("Invalid classifier specification string");
    }
    String classifierName = classifierSpec[0];
    classifierSpec[0] = "";
    classifiers.addElement(AbstractClassifier.forName(classifierName,
          classifierSpec));
  }
  if (classifiers.size() == 0) {
    classifiers.addElement(new weka.classifiers.rules.ZeroR());
  }
  Classifier [] classifiersArray = new Classifier [classifiers.size()];
  for (int i = 0; i < classifiersArray.length; i++) {
    classifiersArray[i] = (Classifier) classifiers.elementAt(i);
  }
  setClassifiers(classifiersArray);

  super.setOptions(options);
}
 
Example 7
Source File: SimpleAggregate.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Aggregates the statistics and returns these.
 *
 * @param stats         the statistics to aggregate
 * @return              the aggregated stats
 */
@Override
public List<EvaluationStatistics> aggregate(List<EvaluationStatistics> stats) {
	List<EvaluationStatistics>      result;
	List<EvaluationStatistics>      temp;
	EvaluationStatisticsComparator  comp;
	int                             i;

	try {
		stats  = new ArrayList<>(stats);
		result = new ArrayList<>();
		comp   = new EvaluationStatisticsComparator(Utils.splitOptions(m_AggregationKeys));
		// sort
		Collections.sort(stats, comp);
		// create groups and aggregate them
		i    = 0;
		temp = new ArrayList<>();
		while (i < stats.size()) {
			if ((temp.size() == 0) || (comp.compare(temp.get(temp.size() - 1), stats.get(i)) == 0)) {
				temp.add(stats.get(i));
				i++;
			}
			else {
				result.add(doAggregate(temp));
				temp.clear();
			}
		}
		if (temp.size() > 0)
			result.add(doAggregate(temp));
	}
	catch (Exception e) {
		result = stats;
		handleException("Failed to aggregate!", e);
	}

	return result;
}
 
Example 8
Source File: Wavelet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses the options for this object. <p/>
 *
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -D
 *  Turns on output of debugging information.</pre>
 * 
 * <pre> -A &lt;Haar&gt;
 *  The algorithm to use.
 *  (default: HAAR)</pre>
 * 
 * <pre> -P &lt;Zero&gt;
 *  The padding to use.
 *  (default: ZERO)</pre>
 * 
 * <pre> -F &lt;filter specification&gt;
 *  The filter to use as preprocessing step (classname and options).
 *  (default: MultiFilter with ReplaceMissingValues and Normalize)</pre>
 * 
 * <pre> 
 * Options specific to filter weka.filters.MultiFilter ('-F'):
 * </pre>
 * 
 * <pre> -D
 *  Turns on output of debugging information.</pre>
 * 
 * <pre> -F &lt;classname [options]&gt;
 *  A filter to apply (can be specified multiple times).</pre>
 * 
 <!-- options-end -->
 *
 * @param options	the options to use
 * @throws Exception	if the option setting fails
 */
public void setOptions(String[] options) throws Exception {
  String	tmpStr;
  String[]	tmpOptions;
  Filter	filter;

  super.setOptions(options);

  tmpStr = Utils.getOption("A", options);
  if (tmpStr.length() != 0)
    setAlgorithm(new SelectedTag(tmpStr, TAGS_ALGORITHM));
  else
    setAlgorithm(new SelectedTag(ALGORITHM_HAAR, TAGS_ALGORITHM));

  tmpStr = Utils.getOption("P", options);
  if (tmpStr.length() != 0)
    setPadding(new SelectedTag(tmpStr, TAGS_PADDING));
  else
    setPadding(new SelectedTag(PADDING_ZERO, TAGS_PADDING));

  tmpStr     = Utils.getOption("F", options);
  tmpOptions = Utils.splitOptions(tmpStr);
  if (tmpOptions.length != 0) {
    tmpStr        = tmpOptions[0];
    tmpOptions[0] = "";
    setFilter((Filter) Utils.forName(Filter.class, tmpStr, tmpOptions));
  }
  else {
    filter = new MultiFilter();
    ((MultiFilter) filter).setFilters(
 new Filter[]{
     new weka.filters.unsupervised.attribute.ReplaceMissingValues(),
     new weka.filters.unsupervised.attribute.Normalize()
     });
    setFilter(filter);
  }
}
 
Example 9
Source File: FilteredSubsetEval.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Parses a given list of options. <p/>
  *
  <!-- options-start -->
  * Valid options are: <p/>
  * 
  * <pre> -W &lt;evaluator specification&gt;
  *  Full name of base evaluator to use, followed by evaluator options.
  *  eg: "weka.attributeSelection.CfsSubsetEval -L"</pre>
  * 
  * <pre> -F &lt;filter specification&gt;
  *  Full class name of filter to use, followed
  *  by filter options.
  *  eg: "weka.filters.supervised.instance.SpreadSubsample -M 1"</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 evaluator = Utils.getOption('W', options);
   
   if (evaluator.length() > 0) { 
     String[] evaluatorSpec = Utils.splitOptions(evaluator);
     if (evaluatorSpec.length == 0) {
       throw new IllegalArgumentException("Invalid evaluator specification string");
     }
     
     String evaluatorName = evaluatorSpec[0];
     evaluatorSpec[0] = "";
     setSubsetEvaluator((ASEvaluation)Utils.forName(SubsetEvaluator.class,
                                                    evaluatorName, evaluatorSpec));

   } else {      
     setSubsetEvaluator(new CfsSubsetEval());
   }

   // Same for filter
   String filterString = Utils.getOption('F', options);
   if (filterString.length() > 0) {
     String [] filterSpec = Utils.splitOptions(filterString);
     if (filterSpec.length == 0) {
throw new IllegalArgumentException("Invalid filter specification string");
     }
     String filterName = filterSpec[0];
     filterSpec[0] = "";
     setFilter((Filter) Utils.forName(Filter.class, filterName, filterSpec));
   } else {
     setFilter(new weka.filters.supervised.instance.SpreadSubsample());
   }
 }
 
Example 10
Source File: KDTree.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 * 
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -S &lt;classname and options&gt;
 *  Node splitting method to use.
 *  (default: weka.core.neighboursearch.kdtrees.SlidingMidPointOfWidestSide)</pre>
 * 
 * <pre> -W &lt;value&gt;
 *  Set minimal width of a box
 *  (default: 1.0E-2).</pre>
 * 
 * <pre> -L
 *  Maximal number of instances in a leaf
 *  (default: 40).</pre>
 * 
 * <pre> -N
 *  Normalizing will be done
 *  (Select dimension for split, with normalising to universe).</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 {
  super.setOptions(options);

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

    setNodeSplitter((KDTreeNodeSplitter) Utils.forName(
        KDTreeNodeSplitter.class, className, splitMethodSpec));
  }
  else {
    setNodeSplitter(new SlidingMidPointOfWidestSide());
  }

  optionString = Utils.getOption('W', options);
  if (optionString.length() != 0)
    setMinBoxRelWidth(Double.parseDouble(optionString));
  else
    setMinBoxRelWidth(1.0E-2);

  optionString = Utils.getOption('L', options);
  if (optionString.length() != 0)
    setMaxInstInLeaf(Integer.parseInt(optionString));
  else
    setMaxInstInLeaf(40);

  setNormalizeNodeWidth(Utils.getFlag('N', options));
}
 
Example 11
Source File: AttributeSelection.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Perform attribute selection with a particular evaluator and
 * a set of options specifying search method and input file etc.
 *
 * @param ASEvaluator an evaluator object
 * @param options an array of options, not only for the evaluator
 * but also the search method (if any) and an input data file
 * @return the results of attribute selection as a String
 * @exception Exception if no training file is set
 */
public static String SelectAttributes (ASEvaluation ASEvaluator, 
			 String[] options)
  throws Exception {
  String trainFileName, searchName;
  Instances train = null;
  ASSearch searchMethod = null;
  String[] optionsTmp = (String[]) options.clone();
  boolean helpRequested = false;

  try {
    // get basic options (options the same for all attribute selectors
    trainFileName = Utils.getOption('i', options);
    helpRequested = Utils.getFlag('h', optionsTmp);

    if (helpRequested || (trainFileName.length() == 0)) {
      searchName = Utils.getOption('s', optionsTmp);
      if (searchName.length() != 0) {
        String[] searchOptions = Utils.splitOptions(searchName);
        searchMethod = (ASSearch)Class.forName(searchOptions[0]).newInstance();
      }

      if (helpRequested)
        throw new Exception("Help requested.");
      else
        throw new Exception("No training file given.");
    }
  }
  catch (Exception e) {
    throw  new Exception('\n' + e.getMessage() 
	   + makeOptionString(ASEvaluator, searchMethod));
  }

  DataSource source = new DataSource(trainFileName);
  train = source.getDataSet();
  return SelectAttributes(ASEvaluator, options, train);
}
 
Example 12
Source File: ZeroShotUtil.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String[] mapSMORBFInputsToWekaOptions(double cExp, double rbfGammaExp) throws Exception {
	double c = Math.pow(10, cExp);
	double g = Math.pow(10, rbfGammaExp);

	String cComplexityConstOption = "-C " + c;
	String rbfGammaOption = " -K \"weka.classifiers.functions.supportVector.RBFKernel -C 250007 -G " + g + "\"";

	String options = cComplexityConstOption + rbfGammaOption;

	return Utils.splitOptions(options);
}
 
Example 13
Source File: AbstractMultiSearch.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses the options for this object.
 *
 * @param options	the options to use
 * @throws Exception	if setting of options fails
 */
@Override
public void setOptions(String[] options) throws Exception {
	String		tmpStr;
	String[]		tmpOptions;
	Vector<String>	search;
	int			i;
	AbstractParameter[]	params;

	tmpStr = Utils.getOption('E', options);
	if (tmpStr.length() != 0)
		setEvaluation(new SelectedTag(tmpStr, m_Metrics.getTags()));
	else
		setEvaluation(new SelectedTag(m_Metrics.getDefaultMetric(), m_Metrics.getTags()));

	search = new Vector<String>();
	do {
		tmpStr = Utils.getOption("search", options);
		if (tmpStr.length() > 0)
			search.add(tmpStr);
	}
	while (tmpStr.length() > 0);
	if (search.size() == 0) {
		for (i = 0; i < m_DefaultParameters.length; i++)
			search.add(getCommandline(m_DefaultParameters[i]));
	}
	params = new AbstractParameter[search.size()];
	for (i = 0; i < search.size(); i++) {
		tmpOptions    = Utils.splitOptions(search.get(i));
		tmpStr        = tmpOptions[0];
		tmpOptions[0] = "";
		params[i]     = (AbstractParameter) Utils.forName(AbstractParameter.class, tmpStr, tmpOptions);
	}
	setSearchParameters(params);

	tmpStr = Utils.getOption("algorithm", options);
	if (!tmpStr.isEmpty()) {
		tmpOptions = Utils.splitOptions(tmpStr);
		tmpStr = tmpOptions[0];
		tmpOptions[0] = "";
		setAlgorithm((AbstractSearch) Utils.forName(AbstractSearch.class, tmpStr, tmpOptions));
	}
	else {
		setAlgorithm(new DefaultSearch());
	}

	tmpStr = Utils.getOption("log-file", options);
	if (tmpStr.length() != 0)
		setLogFile(new File(tmpStr));
	else
		setLogFile(new File(System.getProperty("user.dir")));

	super.setOptions(options);
}
 
Example 14
Source File: KMedoids.java    From apogen with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the options
 * 
 * @param options
 *            a list of options as an array of strings
 * @throws Exception
 *             if an option is not support
 */
public void setOptions(String[] options) throws Exception {

	// Set the number of the cluster
	String optionString = Utils.getOption('N', options);
	if (optionString.length() != 0) {
		setNumClusters(Integer.parseInt(optionString));
	}

	// Set the number of the maximum iterations
	optionString = Utils.getOption("I", options);
	if (optionString.length() != 0) {
		setMaxIterations(Integer.parseInt(optionString));
	}

	// Set the repeat times
	optionString = Utils.getOption("J", options);
	if (optionString.length() != 0) {
		setRepeatTimes(Integer.parseInt(optionString));
	}

	// Set the distance function
	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());
	}

	// Set whether to output the cluster result
	m_SaveClusterResult = Utils.getFlag("s", options);

	// Other options
	super.setOptions(options);
}
 
Example 15
Source File: ZeroShotUtil.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String[] mapJ48InputsToWekaOptions(double c, double m) throws Exception {
	long roundedM = Math.round(m);

	return Utils.splitOptions("-C " + c + " -M " + roundedM);
}
 
Example 16
Source File: RemoveMisclassified.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 * 
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -W &lt;classifier specification&gt;
 *  Full class name of classifier to use, followed
 *  by scheme options. eg:
 *   "weka.classifiers.bayes.NaiveBayes -D"
 *  (default: weka.classifiers.rules.ZeroR)</pre>
 * 
 * <pre> -C &lt;class index&gt;
 *  Attribute on which misclassifications are based.
 *  If &lt; 0 will use any current set class or default to the last attribute.</pre>
 * 
 * <pre> -F &lt;number of folds&gt;
 *  The number of folds to use for cross-validation cleansing.
 *  (&lt;2 = no cross-validation - default).</pre>
 * 
 * <pre> -T &lt;threshold&gt;
 *  Threshold for the max error when predicting numeric class.
 *  (Value should be &gt;= 0, default = 0.1).</pre>
 * 
 * <pre> -I
 *  The maximum number of cleansing iterations to perform.
 *  (&lt;1 = until fully cleansed - default)</pre>
 * 
 * <pre> -V
 *  Invert the match so that correctly classified instances are discarded.
 * </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 classifierString = Utils.getOption('W', options);
  if (classifierString.length() == 0)
    classifierString = weka.classifiers.rules.ZeroR.class.getName();
  String[] classifierSpec = Utils.splitOptions(classifierString);
  if (classifierSpec.length == 0) {
    throw new Exception("Invalid classifier specification string");
  }
  String classifierName = classifierSpec[0];
  classifierSpec[0] = "";
  setClassifier(AbstractClassifier.forName(classifierName, classifierSpec));

  String cString = Utils.getOption('C', options);
  if (cString.length() != 0) {
    setClassIndex((new Double(cString)).intValue());
  } else {
    setClassIndex(-1);
  }

  String fString = Utils.getOption('F', options);
  if (fString.length() != 0) {
    setNumFolds((new Double(fString)).intValue());
  } else {
    setNumFolds(0);
  }

  String tString = Utils.getOption('T', options);
  if (tString.length() != 0) {
    setThreshold((new Double(tString)).doubleValue());
  } else {
    setThreshold(0.1);
  }

  String iString = Utils.getOption('I', options);
  if (iString.length() != 0) {
    setMaxIterations((new Double(iString)).intValue());
  } else {
    setMaxIterations(0);
  }
  
  if (Utils.getFlag('V', options)) {
    setInvert(true);
  } else {
    setInvert(false);
  }
      
  Utils.checkForRemainingOptions(options);

}
 
Example 17
Source File: HierarchicalClusterer.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 *
  <!-- options-start -->
 * Valid options are: <p/>
 * 
  <!-- 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 {
  m_bPrintNewick = Utils.getFlag('P', options);

  String optionString = Utils.getOption('N', options); 
  if (optionString.length() != 0) {
    Integer temp = new Integer(optionString);
    setNumClusters(temp);
  }
  else {
    setNumClusters(2);
  }

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

  String sLinkType = Utils.getOption('L', options);


  if (sLinkType.compareTo("SINGLE") == 0) {setLinkType(new SelectedTag(SINGLE, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("COMPLETE") == 0) {setLinkType(new SelectedTag(COMPLETE, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("AVERAGE") == 0) {setLinkType(new SelectedTag(AVERAGE, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("MEAN") == 0) {setLinkType(new SelectedTag(MEAN, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("CENTROID") == 0) {setLinkType(new SelectedTag(CENTROID, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("WARD") == 0) {setLinkType(new SelectedTag(WARD, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("ADJCOMLPETE") == 0) {setLinkType(new SelectedTag(ADJCOMLPETE, TAGS_LINK_TYPE));}
  if (sLinkType.compareTo("NEIGHBOR_JOINING") == 0) {setLinkType(new SelectedTag(NEIGHBOR_JOINING, TAGS_LINK_TYPE));}

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

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

  Utils.checkForRemainingOptions(options);
}
 
Example 18
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -E &lt;attribute evaluator specification&gt;
 *  Full class name of attribute evaluator, followed
 *  by its options.
 *  eg: "weka.attributeSelection.CfsSubsetEval -L"
 *  (default weka.attributeSelection.CfsSubsetEval)</pre>
 * 
 * <pre> -S &lt;search method specification&gt;
 *  Full class name of search method, followed
 *  by its options.
 *  eg: "weka.attributeSelection.BestFirst -D 1"
 *  (default weka.attributeSelection.BestFirst)</pre>
 * 
 * <pre> -D
 *  If set, classifier is run in debug mode and
 *  may output additional info to the console</pre>
 * 
 * <pre> -W
 *  Full name of base classifier.
 *  (default: weka.classifiers.trees.J48)</pre>
 * 
 * <pre> 
 * Options specific to classifier weka.classifiers.trees.J48:
 * </pre>
 * 
 * <pre> -U
 *  Use unpruned tree.</pre>
 * 
 * <pre> -C &lt;pruning confidence&gt;
 *  Set confidence threshold for pruning.
 *  (default 0.25)</pre>
 * 
 * <pre> -M &lt;minimum number of instances&gt;
 *  Set minimum number of instances per leaf.
 *  (default 2)</pre>
 * 
 * <pre> -R
 *  Use reduced error pruning.</pre>
 * 
 * <pre> -N &lt;number of folds&gt;
 *  Set number of folds for reduced error
 *  pruning. One fold is used as pruning set.
 *  (default 3)</pre>
 * 
 * <pre> -B
 *  Use binary splits only.</pre>
 * 
 * <pre> -S
 *  Don't perform subtree raising.</pre>
 * 
 * <pre> -L
 *  Do not clean up after the tree has been built.</pre>
 * 
 * <pre> -A
 *  Laplace smoothing for predicted probabilities.</pre>
 * 
 * <pre> -Q &lt;seed&gt;
 *  Seed for random data shuffling (default 1).</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 {

  // same for attribute evaluator
  String evaluatorString = Utils.getOption('E', options);
  if (evaluatorString.length() == 0)
    evaluatorString = weka.attributeSelection.CfsSubsetEval.class.getName();
  String [] evaluatorSpec = Utils.splitOptions(evaluatorString);
  if (evaluatorSpec.length == 0) {
    throw new Exception("Invalid attribute evaluator specification string");
  }
  String evaluatorName = evaluatorSpec[0];
  evaluatorSpec[0] = "";
  setEvaluator(ASEvaluation.forName(evaluatorName, evaluatorSpec));

  // same for search method
  String searchString = Utils.getOption('S', options);
  if (searchString.length() == 0)
    searchString = weka.attributeSelection.BestFirst.class.getName();
  String [] searchSpec = Utils.splitOptions(searchString);
  if (searchSpec.length == 0) {
    throw new Exception("Invalid search specification string");
  }
  String searchName = searchSpec[0];
  searchSpec[0] = "";
  setSearch(ASSearch.forName(searchName, searchSpec));

  super.setOptions(options);
}
 
Example 19
Source File: XMLOptions.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * returns the current DOM document as string array.
 * 
 * @return 		the document as string array
 * @throws Exception 	if anything goes wrong initializing the parsing
 */
public String[] toArray() throws Exception {
  return Utils.splitOptions(toCommandLine());
}
 
Example 20
Source File: DecisionTable.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
  * Parses the options for this object. <p/>
  *
  <!-- options-start -->
  * Valid options are: <p/>
  * 
  * <pre> -S &lt;search method specification&gt;
  *  Full class name of search method, followed
  *  by its options.
  *  eg: "weka.attributeSelection.BestFirst -D 1"
  *  (default weka.attributeSelection.BestFirst)</pre>
  * 
  * <pre> -X &lt;number of folds&gt;
  *  Use cross validation to evaluate features.
  *  Use number of folds = 1 for leave one out CV.
  *  (Default = leave one out CV)</pre>
  * 
  * <pre> -E &lt;acc | rmse | mae | auc&gt;
  *  Performance evaluation measure to use for selecting attributes.
  *  (Default = accuracy for discrete class and rmse for numeric class)</pre>
  * 
  * <pre> -I
  *  Use nearest neighbour instead of global table majority.</pre>
  * 
  * <pre> -R
  *  Display decision table rules.
  * </pre>
  * 
  * <pre> 
  * Options specific to search method weka.attributeSelection.BestFirst:
  * </pre>
  * 
  * <pre> -P &lt;start set&gt;
  *  Specify a starting set of attributes.
  *  Eg. 1,3,5-7.</pre>
  * 
  * <pre> -D &lt;0 = backward | 1 = forward | 2 = bi-directional&gt;
  *  Direction of search. (default = 1).</pre>
  * 
  * <pre> -N &lt;num&gt;
  *  Number of non-improving nodes to
  *  consider before terminating search.</pre>
  * 
  * <pre> -S &lt;num&gt;
  *  Size of lookup cache for evaluated subsets.
  *  Expressed as a multiple of the number of
  *  attributes in the data set. (default = 1)</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;

   resetOptions();

   optionString = Utils.getOption('X',options);
   if (optionString.length() != 0) {
     m_CVFolds = Integer.parseInt(optionString);
   }

   m_useIBk = Utils.getFlag('I',options);

   m_displayRules = Utils.getFlag('R',options);

   optionString = Utils.getOption('E', options);
   if (optionString.length() != 0) {
     if (optionString.equals("acc")) {
setEvaluationMeasure(new SelectedTag(EVAL_ACCURACY, TAGS_EVALUATION));
     } else if (optionString.equals("rmse")) {
setEvaluationMeasure(new SelectedTag(EVAL_RMSE, TAGS_EVALUATION));
     } else if (optionString.equals("mae")) {
setEvaluationMeasure(new SelectedTag(EVAL_MAE, TAGS_EVALUATION));
     } else if (optionString.equals("auc")) {
setEvaluationMeasure(new SelectedTag(EVAL_AUC, TAGS_EVALUATION));
     } else {
throw new IllegalArgumentException("Invalid evaluation measure");
     }
   }

   String searchString = Utils.getOption('S', options);
   if (searchString.length() == 0)
     searchString = weka.attributeSelection.BestFirst.class.getName();
   String [] searchSpec = Utils.splitOptions(searchString);
   if (searchSpec.length == 0) {
     throw new IllegalArgumentException("Invalid search specification string");
   }
   String searchName = searchSpec[0];
   searchSpec[0] = "";
   setSearch(ASSearch.forName(searchName, searchSpec));
 }