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

The following examples show how to use weka.core.Utils#getFlag() . 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: CheckSource.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Executes the tests, use "-h" to list the commandline options.
 *
 * @param args        the commandline parameters
 * @throws Exception  if something goes wrong
 */
public static void main(String[] args) throws Exception{
  CheckSource         check;
  StringBuffer        text;
  Enumeration         enm;

  check = new CheckSource();
  if (Utils.getFlag('h', args)) {
    text = new StringBuffer();
    text.append("\nHelp requested:\n\n");
    enm = check.listOptions();
    while (enm.hasMoreElements()) {
      Option option = (Option) enm.nextElement();
      text.append(option.synopsis() + "\n");
      text.append(option.description() + "\n");
    }
    System.out.println("\n" + text + "\n");
  }
  else {
    check.setOptions(args);
    if (check.execute())
      System.out.println("Tests OK!");
    else
      System.out.println("Tests failed!");
  }
}
 
Example 2
Source File: Filter.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * runs the filter instance with the given options.
  * 
  * @param filter	the filter to run
  * @param options	the commandline options
  */
 public static void runFilter(Filter filter, String[] options) {
   try {
     if (Utils.getFlag('b', options)) {
Filter.batchFilterFile(filter, options);
     } else {
Filter.filterFile(filter, options);
     }
   } catch (Exception e) {
     if (    (e.toString().indexOf("Help requested") == -1) 
   && (e.toString().indexOf("Filter options") == -1) )
e.printStackTrace();
     else
System.err.println(e.getMessage());
   }
 }
 
Example 3
Source File: Main.java    From SM-MLC with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Read input parameters and store them in private attributes
 *
 * @param args Command line arguments
 */
private void readParameters(String[] args) {
    try {
        // Path verification
        path = Utils.getOption("path", args);
        if(!(new File(path)).isDirectory()) throw new IOException();

        dataset = Utils.getOption("dataset", args);
        xmlfile = path + File.separator + dataset.substring(0, dataset.indexOf("-")) + ".xml";
        if(!(new File(xmlfile)).exists()) throw new IOException(xmlfile + " does not exists");

        folds = Integer.parseInt(Utils.getOption("folds", args));
        if(folds < 1) throw new Exception("-folds must be greater than 0");

        algorithm = Utils.getOption("algorithm", args);
        debug = Utils.getFlag("debug", args);
    } catch(Exception e) {
        System.err.println("Error reading input parameters");
        e.printStackTrace();

        System.out.println("\n\nYou have to specify the following parameters:");
        System.out.println("\t-path path_to_datasets\n\t-dataset name_root\n\t-folds num_folds\n\t-algorithm {CLR|MLkNN|BPMLL|IBLR-ML|BR-J48|LP-J48|RAkEL-BR|RAkEL-LP|BR-RBFN|HOMER|PS-J48|EPS-J48|CC-J48|ECC-J48|BRkNN}");
    }
}
 
Example 4
Source File: StrUtils.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
public static String[] uniteOptions(String[] next, String[] current, boolean flagsFromCurrent) throws
                                                                     Exception {
    ArrayList<String> list = new ArrayList<>();
    for(int i = 0; i < current.length; i++) {
        String flag = current[i];
        flag = unflagify(flag);
        if(isOption(flag, current)) {
            String nextOption = Utils.getOption(flag, next);
            if(nextOption.length() > 0) {
                addOption(flag, list, nextOption);
            } else {
                String currentOption = Utils.getOption(flag, current);
                addOption(flag, list, currentOption);
            }
            i++;
        } else {
            if(Utils.getFlag(flag, next) || flagsFromCurrent) {
                addFlag(flag, list);
            } else {
                // don't add the flag
            }
        }

    }
    return list.toArray(new String[0]);
}
 
Example 5
Source File: DTNB.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> -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>
  * 
  <!-- 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) {
     setCrossVal(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");
     }
   }
 }
 
Example 6
Source File: FPGrowth.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Main method.
 * 
 * @param args the commandline options
 */
public static void main(String[] args) {
  try {
    String[] argsCopy = args.clone();
    if (Utils.getFlag('h', argsCopy) || Utils.getFlag("help", argsCopy)) {
      runAssociator(new FPGrowth(), args);
      System.out.println("-disk\n\tProcess data off of disk instead of loading\n\t" +
      		"into main memory. This is a command line only option.");
      return;
    }
      
    if (!Utils.getFlag("disk", args)) {
      runAssociator(new FPGrowth(), args);
    } else {
      String filename;
      filename = Utils.getOption('t', args);
      weka.core.converters.ArffLoader loader = null;
      if (filename.length() != 0) {
        loader = new weka.core.converters.ArffLoader();
        loader.setFile(new java.io.File(filename));
      } else {
        throw new Exception("No training file specified!");
      }
      FPGrowth fpGrowth = new FPGrowth();
      fpGrowth.setOptions(args);
      Utils.checkForRemainingOptions(args);
      fpGrowth.buildAssociations(loader);
      System.out.print(fpGrowth.toString());
    }
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 
Example 7
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 8
Source File: NonSparseToSparse.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
public void setOptions(String[] options) throws Exception {
  m_encodeMissingAsZero = Utils.getFlag('M', options);
  m_insertDummyNominalFirstValue = Utils.getFlag('F', options);
}
 
Example 9
Source File: K2.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> -N
 *  Initial structure is empty (instead of Naive Bayes)</pre>
 * 
 * <pre> -P &lt;nr of parents&gt;
 *  Maximum number of parents</pre>
 * 
 * <pre> -R
 *  Random order.
 *  (default false)</pre>
 * 
 * <pre> -mbc
 *  Applies a Markov Blanket correction to the network structure, 
 *  after a network structure is learned. This ensures that all 
 *  nodes in the network are part of the Markov blanket of the 
 *  classifier node.</pre>
 * 
 * <pre> -S [LOO-CV|k-Fold-CV|Cumulative-CV]
 *  Score type (LOO-CV,k-Fold-CV,Cumulative-CV)</pre>
 * 
 * <pre> -Q
 *  Use probabilistic or 0/1 scoring.
 *  (default probabilistic scoring)</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 {
   
  setRandomOrder(Utils.getFlag('R', options));

  m_bInitAsNaiveBayes = !(Utils.getFlag('N', options));

  String sMaxNrOfParents = Utils.getOption('P', options);

  if (sMaxNrOfParents.length() != 0) {
	setMaxNrOfParents(Integer.parseInt(sMaxNrOfParents));
  } else {
	setMaxNrOfParents(100000);
  } 
  super.setOptions(options);	  
}
 
Example 10
Source File: RandomProjection.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> -N &lt;number&gt;
  *  The number of dimensions (attributes) the data should be reduced to
  *  (default 10; exclusive of the class attribute, if it is set).</pre>
  * 
  * <pre> -D [SPARSE1|SPARSE2|GAUSSIAN]
  *  The distribution to use for calculating the random matrix.
  *  Sparse1 is:
  *    sqrt(3)*{-1 with prob(1/6), 0 with prob(2/3), +1 with prob(1/6)}
  *  Sparse2 is:
  *    {-1 with prob(1/2), +1 with prob(1/2)}
  * </pre>
  * 
  * <pre> -P &lt;percent&gt;
  *  The percentage of dimensions (attributes) the data should
  *  be reduced to (exclusive of the class attribute, if it is set). This -N
  *  option is ignored if this option is present or is greater
  *  than zero.</pre>
  * 
  * <pre> -M
  *  Replace missing values using the ReplaceMissingValues filter</pre>
  * 
  * <pre> -R &lt;num&gt;
  *  The random seed for the random number generator used for
  *  calculating the random matrix (default 42).</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 mString = Utils.getOption('P', options);
   if (mString.length() != 0) {
setPercent((double) Double.parseDouble(mString)); //setNumberOfAttributes((int) Integer.parseInt(mString));
   } else {
       setPercent(0);
mString = Utils.getOption('N', options);
if (mString.length() != 0) 
    setNumberOfAttributes(Integer.parseInt(mString));	    
else	    
    setNumberOfAttributes(10);
   }    
   
   mString = Utils.getOption('R', options);
   if(mString.length()!=0) {
setRandomSeed( Long.parseLong(mString) );
   }

   mString = Utils.getOption('D', options);
   if(mString.length()!=0) {
if(mString.equalsIgnoreCase("sparse1"))
   setDistribution( new SelectedTag(SPARSE1, TAGS_DSTRS_TYPE) );
else if(mString.equalsIgnoreCase("sparse2"))
   setDistribution( new SelectedTag(SPARSE2, TAGS_DSTRS_TYPE) );
else if(mString.equalsIgnoreCase("gaussian"))
   setDistribution( new SelectedTag(GAUSSIAN, TAGS_DSTRS_TYPE) );	   
   }

   if(Utils.getFlag('M', options))
setReplaceMissingValues(true);
   else
setReplaceMissingValues(false);


  //if(Utils.getFlag('G', options))
  //    setUseGaussian(true);
  //else
  //    setUseGaussian(false);
   
 }
 
Example 11
Source File: AODE.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> -D
 *  Output debugging information
 * </pre>
 * 
 * <pre> -F &lt;int&gt;
 *  Impose a frequency limit for superParents
 *  (default is 1)</pre>
 * 
 * <pre> -M
 *  Use m-estimate instead of laplace correction
 * </pre>
 * 
 * <pre> -W &lt;int&gt;
 *  Specify a weight to use with m-estimate
 *  (default is 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 {

  m_Debug = Utils.getFlag('D', options);

  String Freq = Utils.getOption('F', options);
  if (Freq.length() != 0) 
     m_Limit = Integer.parseInt(Freq);
  else
     m_Limit = 1;
 
  m_MEstimates = Utils.getFlag('M', options);
  String weight = Utils.getOption('W', options);
  if (weight.length() != 0) {
     if (!m_MEstimates)
        throw new Exception("Can't use Laplace AND m-estimate weight. Choose one.");
     m_Weight = Integer.parseInt(weight);
  } 
  else {
     if (m_MEstimates)
        m_Weight = 1;
  }

  Utils.checkForRemainingOptions(options);
}
 
Example 12
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 13
Source File: REPTree.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> -M &lt;minimum number of instances&gt;
 *  Set minimum number of instances per leaf (default 2).</pre>
 * 
 * <pre> -V &lt;minimum variance for split&gt;
 *  Set minimum numeric class variance proportion
 *  of train variance for split (default 1e-3).</pre>
 * 
 * <pre> -N &lt;number of folds&gt;
 *  Number of folds for reduced error pruning (default 3).</pre>
 * 
 * <pre> -S &lt;seed&gt;
 *  Seed for random data shuffling (default 1).</pre>
 * 
 * <pre> -P
 *  No pruning.</pre>
 * 
 * <pre> -L
 *  Maximum tree depth (default -1, no maximum)</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 minNumString = Utils.getOption('M', options);
  if (minNumString.length() != 0) {
    m_MinNum = (double)Integer.parseInt(minNumString);
  } else {
    m_MinNum = 2;
  }
  String minVarString = Utils.getOption('V', options);
  if (minVarString.length() != 0) {
    m_MinVarianceProp = Double.parseDouble(minVarString);
  } else {
    m_MinVarianceProp = 1e-3;
  }
  String numFoldsString = Utils.getOption('N', options);
  if (numFoldsString.length() != 0) {
    m_NumFolds = Integer.parseInt(numFoldsString);
  } else {
    m_NumFolds = 3;
  }
  String seedString = Utils.getOption('S', options);
  if (seedString.length() != 0) {
    m_Seed = Integer.parseInt(seedString);
  } else {
    m_Seed = 1;
  }
  m_NoPruning = Utils.getFlag('P', options);
  String depthString = Utils.getOption('L', options);
  if (depthString.length() != 0) {
    m_MaxDepth = Integer.parseInt(depthString);
  } else {
    m_MaxDepth = -1;
  }
  String initialCountString = Utils.getOption('I', options);
  if (initialCountString.length() != 0) {
    m_InitialCount = Double.parseDouble(initialCountString);
  } else {
    m_InitialCount = 0;
  }
  m_SpreadInitialCount = Utils.getFlag('R', options);
  
  Utils.checkForRemainingOptions(options);
}
 
Example 14
Source File: LinearForwardSelection.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses a given list of options.
 *
 * Valid options are:
 * <p>
 *
 * -P <start set> <br>
 * Specify a starting set of attributes. Eg 1,4,7-9.
 * <p>
 *
 * -D <0 = forward selection | 1 = floating forward selection> <br>
 * Forward selection method of the search. (default = 0).
 * <p>
 *
 * -N <num> <br>
 * Number of non improving nodes to consider before terminating search.
 * (default = 5).
 * <p>
 *
 * -I <br>
 * Perform initial ranking to select top-ranked attributes.
 * <p>
 *
 * -K <num> <br>
 * Number of top-ranked attributes that are taken into account.
 * <p>
 *
 * -T <0 = fixed-set | 1 = fixed-width> <br>
 * Typ of Linear Forward Selection (default = 0).
 * <p>
 *
 * -S <num> <br>
 * Size of lookup cache for evaluated subsets. Expressed as a multiple of
 * the number of attributes in the data set. (default = 1).
 * <p>
 *
 * -Z <br>
 * verbose on/off.
 * <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 {
  String optionString;
  resetOptions();

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

  if (optionString.length() != 0) {
    setStartSet(optionString);
  }

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

  if (optionString.length() != 0) {
    setForwardSelectionMethod(new SelectedTag(Integer.parseInt(optionString),
                                              TAGS_SEARCH_METHOD));
  } else {
    setForwardSelectionMethod(new SelectedTag(SEARCH_METHOD_FORWARD,
                                              TAGS_SEARCH_METHOD));
  }

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

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

  setPerformRanking(Utils.getFlag('I', options));

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

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

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

  if (optionString.length() != 0) {
    setType(new SelectedTag(Integer.parseInt(optionString), TAGS_TYPE));
  } else {
    setType(new SelectedTag(TYPE_FIXED_SET, TAGS_TYPE));
  }

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

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

  m_verbose = Utils.getFlag('Z', options);
}
 
Example 15
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 16
Source File: RenameAttribute.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> -find &lt;regexp&gt;
  *  The regular expression that the attribute names must match.
  *  (default: ([\s\S]+))</pre>
  * 
  * <pre> -replace &lt;string&gt;
  *  The string to replace the regular expression of matching attributes with.
  *  Cannot be used in conjunction with '-remove'.
  *  (default: $0)</pre>
  * 
  * <pre> -remove
  *  In case the matching string needs to be removed instead of replaced.
  *  Cannot be used in conjunction with '-replace &lt;string&gt;'.
  *  (default: off)</pre>
  * 
  * <pre> -all
  *  Replaces all occurrences instead of just the first.
  *  (default: only first occurrence)</pre>
  * 
  * <pre> -R &lt;range&gt;
  *  The attribute range to work on.
  * This is a comma separated list of attribute indices, with "first" and "last" valid values.
  *  Specify an inclusive range with "-".
  *  E.g: "first-3,5,6-10,last".
  *  (default: first-last)</pre>
  * 
  * <pre> -V
  *  Inverts the attribute selection range.
  *  (default: off)</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	tmpStr;
   
   tmpStr = Utils.getOption("find", options);
   if (tmpStr.length() != 0)
     setFind(tmpStr);
   else
     setFind("([\\s\\S]+)");
   
   if (Utils.getFlag("remove", options)) {
     setReplace("");
   }
   else {
     tmpStr = Utils.getOption("replace", options);
     if (tmpStr.length() > 0)
setReplace(tmpStr);
     else
setReplace("$0");
   }

   setReplaceAll(Utils.getFlag("all", options));
   
   tmpStr = Utils.getOption("R", options);
   if (tmpStr.length() != 0)
     setAttributeIndices(tmpStr);
   else
     setAttributeIndices("first-last");

   setInvertSelection(Utils.getFlag("V", options));
   
   if (getInputFormat() != null)
     setInputFormat(getInputFormat());
 }
 
Example 17
Source File: ConjunctiveRule.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> -N &lt;number of folds&gt;
 *  Set number of folds for REP
 *  One fold is used as pruning set.
 *  (default 3)</pre>
 * 
 * <pre> -R
 *  Set if NOT uses randomization
 *  (default:use randomization)</pre>
 * 
 * <pre> -E
 *  Set whether consider the exclusive
 *  expressions for nominal attributes
 *  (default false)</pre>
 * 
 * <pre> -M &lt;min. weights&gt;
 *  Set the minimal weights of instances
 *  within a split.
 *  (default 2.0)</pre>
 * 
 * <pre> -P &lt;number of antecedents&gt;
 *  Set number of antecedents for pre-pruning
 *  if -1, then REP is used
 *  (default -1)</pre>
 * 
 * <pre> -S &lt;seed&gt;
 *  Set the seed of randomization
 *  (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 numFoldsString = Utils.getOption('N', options);
  if (numFoldsString.length() != 0) 
    m_Folds = Integer.parseInt(numFoldsString);
  else 
    m_Folds = 3;

  String minNoString = Utils.getOption('M', options);
  if (minNoString.length() != 0) 
    m_MinNo = Double.parseDouble(minNoString);
  else 
    m_MinNo = 2.0;
	
  String seedString = Utils.getOption('S', options);
  if (seedString.length() != 0) 
    m_Seed = Integer.parseInt(seedString);
  else 
    m_Seed = 1;
	
  String numAntdsString = Utils.getOption('P', options);
  if (numAntdsString.length() != 0) 
    m_NumAntds = Integer.parseInt(numAntdsString);
  else 
    m_NumAntds = -1;
	
  m_IsExclude = Utils.getFlag('E', options);	
}
 
Example 18
Source File: Ridor.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> -F &lt;number of folds&gt;
 *  Set number of folds for IREP
 *  One fold is used as pruning set.
 *  (default 3)</pre>
 * 
 * <pre> -S &lt;number of shuffles&gt;
 *  Set number of shuffles to randomize
 *  the data in order to get better rule.
 *  (default 10)</pre>
 * 
 * <pre> -A
 *  Set flag of whether use the error rate 
 *  of all the data to select the default class
 *  in each step. If not set, the learner will only use the error rate in the pruning data</pre>
 * 
 * <pre> -M
 *   Set flag of whether use the majority class as
 *  the default class in each step instead of 
 *  choosing default class based on the error rate
 *  (if the flag is not set)</pre>
 * 
 * <pre> -N &lt;min. weights&gt;
 *  Set the minimal weights of instances
 *  within a split.
 *  (default 2.0)</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 numFoldsString = Utils.getOption('F', options);
  if (numFoldsString.length() != 0) 
    m_Folds = Integer.parseInt(numFoldsString);
  else 
    m_Folds = 3;
	
  String numShuffleString = Utils.getOption('S', options);
  if (numShuffleString.length() != 0) 
    m_Shuffle = Integer.parseInt(numShuffleString);
  else 
    m_Shuffle = 1;

  String seedString = Utils.getOption('s', options);
  if (seedString.length() != 0) 
    m_Seed = Integer.parseInt(seedString);
  else 
    m_Seed = 1;
	
  String minNoString = Utils.getOption('N', options);
  if (minNoString.length() != 0) 
    m_MinNo = Double.parseDouble(minNoString);
  else 
    m_MinNo = 2.0;
	
  m_IsAllErr = Utils.getFlag('A', options);
  m_IsMajority = Utils.getFlag('M', options);
}
 
Example 19
Source File: JRip.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> -F &lt;number of folds&gt;
 *  Set number of folds for REP
 *  One fold is used as pruning set.
 *  (default 3)</pre>
 * 
 * <pre> -N &lt;min. weights&gt;
 *  Set the minimal weights of instances
 *  within a split.
 *  (default 2.0)</pre>
 * 
 * <pre> -O &lt;number of runs&gt;
 *  Set the number of runs of
 *  optimizations. (Default: 2)</pre>
 * 
 * <pre> -D
 *  Set whether turn on the
 *  debug mode (Default: false)</pre>
 * 
 * <pre> -S &lt;seed&gt;
 *  The seed of randomization
 *  (Default: 1)</pre>
 * 
 * <pre> -E
 *  Whether NOT check the error rate&gt;=0.5
 *  in stopping criteria  (default: check)</pre>
 * 
 * <pre> -P
 *  Whether NOT use pruning
 *  (default: use pruning)</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 numFoldsString = Utils.getOption('F', options);
  if (numFoldsString.length() != 0) 
    m_Folds = Integer.parseInt(numFoldsString);
  else 
    m_Folds = 3;   
	
  String minNoString = Utils.getOption('N', options);
  if (minNoString.length() != 0) 
    m_MinNo = Double.parseDouble(minNoString);
  else 
    m_MinNo = 2.0;
	
  String seedString = Utils.getOption('S', options);
  if (seedString.length() != 0)
    m_Seed = Long.parseLong(seedString);
  else 
    m_Seed = 1;

  String runString = Utils.getOption('O', options);
  if (runString.length() != 0)
    m_Optimizations = Integer.parseInt(runString);
  else 
    m_Optimizations = 2;

  m_Debug = Utils.getFlag('D', options);
  m_CheckErr = !Utils.getFlag('E', options);
  m_UsePruning = !Utils.getFlag('P', options);
}
 
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));
 }