Example usage for weka.core Utils getFlag

List of usage examples for weka.core Utils getFlag

Introduction

In this page you can find the example usage for weka.core Utils getFlag.

Prototype

public static boolean getFlag(String flag, String[] options) throws Exception 

Source Link

Document

Checks if the given array contains the flag "-String".

Usage

From source file:Bilbo.java

License:Open Source License

/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->/*from w w  w. j a va 2  s  . c o m*/
 * Valid options are: <p/>
 * 
 * <pre> -P
 *  Size of each bag, as a percentage of the
 *  training set size. (default 100)</pre>
 * 
 * <pre> -O
 *  Calculate the out of bag error.</pre>
 * 
 * <pre> -represent-copies-using-weights
 *  Represent copies of instances using weights rather than explicitly.</pre>
 * 
 * <pre> -S &lt;num&gt;
 *  Random number seed.
 *  (default 1)</pre>
 * 
 * <pre> -num-slots &lt;num&gt;
 *  Number of execution slots.
 *  (default 1 - i.e. no parallelism)</pre>
 * 
 * <pre> -I &lt;num&gt;
 *  Number of iterations.
 *  (default 10)</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.REPTree)</pre>
 * 
 * <pre> 
 * Options specific to classifier weka.classifiers.trees.REPTree:
 * </pre>
 * 
 * <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>
 * 
 * <pre> -I
 *  Initial class value count (default 0)</pre>
 * 
 * <pre> -R
 *  Spread initial count over all class values (i.e. don't use 1 per value)</pre>
 * 
 <!-- options-end -->
 *
 * Options after -- are passed to the designated classifier.<p>
 *
 * @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 bagSize = Utils.getOption('P', options);
    if (bagSize.length() != 0) {
        setBagSizePercent(Integer.parseInt(bagSize));
    } else {
        setBagSizePercent(100);
    }

    setCalcOutOfBag(Utils.getFlag('O', options));

    setRepresentCopiesUsingWeights(Utils.getFlag("represent-copies-using-weights", options));

    super.setOptions(options);

    Utils.checkForRemainingOptions(options);
}

From source file:PrincipalComponents.java

License:Open Source License

/**
 * Parses a given list of options.//from   w  w  w  . j a v a  2 s. co m
 * <p>
 * <p>
 * <!-- options-start --> Valid options are:
 * <p>
 * <p>
 * <pre>
 * -C
 *  Center (rather than standardize) the
 *  data and compute PCA using the covariance (rather
 *   than the correlation) matrix.
 * </pre>
 * <p>
 * <pre>
 * -R
 *  Retain enough PC attributes to account
 *  for this proportion of variance in the original data.
 *  (default = 0.95)
 * </pre>
 * <p>
 * <pre>
 * -O
 *  Transform through the PC space and
 *  back to the original space.
 * </pre>
 * <p>
 * <pre>
 * -A
 *  Maximum number of attributes to include in
 *  transformed attribute names. (-1 = include all)
 * </pre>
 * <p>
 * <!-- 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 {
    resetOptions();
    String optionString;

    optionString = Utils.getOption('R', options);
    if (optionString.length() != 0) {
        Double temp;
        temp = Double.valueOf(optionString);
        setVarianceCovered(temp.doubleValue());
    }
    optionString = Utils.getOption('A', options);
    if (optionString.length() != 0) {
        setMaximumAttributeNames(Integer.parseInt(optionString));
    }

    setTransformBackToOriginal(Utils.getFlag('O', options));
    setCenterData(Utils.getFlag('C', options));
}

From source file:TextDirectoryLoader.java

License:Open Source License

/** 
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->//from w w  w  .  j a  v a2  s.c om
 * Valid options are: <p/>
 * 
 * <pre> -D
 *  Enables debug output.
 *  (default: off)</pre>
 * 
 * <pre> -F
 *  Stores the filename in an additional attribute.
 *  (default: off)</pre>
 * 
 * <pre> -dir &lt;directory&gt;
 *  The directory to work on.
 *  (default: current directory)</pre>
 * 
 <!-- options-end -->
 *
 * @param options the options
 * @throws Exception if options cannot be set
 */
public void setOptions(String[] options) throws Exception {
    setDebug(Utils.getFlag("D", options));

    setOutputFilename(Utils.getFlag("F", options));

    setDirectory(new File(Utils.getOption("dir", options)));

    String charSet = Utils.getOption("charset", options);
    m_charSet = "";
    if (charSet.length() > 0) {
        m_charSet = charSet;
    }
}

From source file:BaggingImprove.java

/**
 * Parses a given list of options./*w w w .ja  v  a 2s  .c  om*/
 * <p/>
 *
 * <!-- options-start -->
 * Valid options are:
 * <p/>
 *
 * <pre>
 * -P
 *  Size of each bag, as a percentage of the
 *  training set size. (default 100)
 * </pre>
 *
 * <pre>
 * -O
 *  Calculate the out of bag error.
 * </pre>
 *
 * <pre>
 * -S &lt;num&gt;
 *  Random number seed.
 *  (default 1)
 * </pre>
 *
 * <pre>
 * -I &lt;num&gt;
 *  Number of iterations.
 *  (default 10)
 * </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.REPTree)
 * </pre>
 *
 * <pre>
 * Options specific to classifier weka.classifiers.trees.REPTree:
 * </pre>
 *
 * <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 -->
 *
 * Options after -- are passed to the designated classifier.
 * <p>
 *
 * @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 bagSize = Utils.getOption('P', options);
    if (bagSize.length() != 0) {
        setBagSizePercent(Integer.parseInt(bagSize));
    } else {
        setBagSizePercent(100);
    }

    setCalcOutOfBag(Utils.getFlag('O', options));

    super.setOptions(options);
}

From source file:REPTree.java

License:Open Source License

/**
 * Parses a given list of options. <p/>
 * // w  w w.j ava  2s.com
 <!-- 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);
}

From source file:Pair.java

License:Open Source License

public void setOptions(String[] options) throws Exception {

    String sourceFileName = Utils.getOption('S', options);
    if (sourceFileName.length() == 0) {
        throw new Exception("A filename must be specified with" + " the -S option.");
    } else {/*from   w w w  . jav  a2s.  c  om*/
        setSourceFile(new File(sourceFileName));
    }

    doFraction = (Utils.getFlag('F', options));
    doBagging = (Utils.getFlag('B', options));
    doUpsource = (Utils.getFlag('U', options));
    useMedian = (Utils.getFlag('M', options));
    resample = (Utils.getFlag('R', options));
    doSampleSize = Utils.getFlag("SS", options);
    fixedBeta = Utils.getFlag("FB", options);

    String optionString = Utils.getOption("TT", options);
    testData = new Instances(new BufferedReader(new FileReader(optionString)));
    testData.setClassIndex(testData.numAttributes() - 1);

    String r = Utils.getOption("Ratio", options);
    if (!r.equals(""))
        sourceRatio = Double.parseDouble(r);

    super.setOptions(options);

    r = Utils.getOption("II", options);
    if (!r.equals(""))
        sourceIterations = Integer.parseInt(r);
    else
        sourceIterations = m_NumIterations;

}

From source file:REPRandomTree.java

License:Open Source License

/**
 * Parses a given list of options. <p/>
 * //from w ww .j a  v a  2s.com
 <!-- 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);

    String featureFracString = Utils.getOption('F', options);
    if (featureFracString.length() != 0) {
        m_FeatureFrac = Double.parseDouble(featureFracString);
    } else {
        m_FeatureFrac = 1.0;
    }

    Utils.checkForRemainingOptions(options);
}

From source file:MultiClassClassifier.java

License:Open Source License

/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->//from   www. ja  va2s .co m
 * Valid options are: <p/>
 * 
 * <pre> -M &lt;num&gt;
 *  Sets the method to use. Valid values are 0 (1-against-all),
 *  1 (random codes), 2 (exhaustive code), and 3 (1-against-1). (default 0)
 * </pre>
 * 
 * <pre> -R &lt;num&gt;
 *  Sets the multiplier when using random codes. (default 2.0)</pre>
 * 
 * <pre> -P
 *  Use pairwise coupling (only has an effect for 1-against1)</pre>
 * 
 * <pre> -S &lt;num&gt;
 *  Random number seed.
 *  (default 1)</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.functions.Logistic)</pre>
 * 
 * <pre> 
 * Options specific to classifier weka.classifiers.functions.Logistic:
 * </pre>
 * 
 * <pre> -D
 *  Turn on debugging output.</pre>
 * 
 * <pre> -R &lt;ridge&gt;
 *  Set the ridge in the log-likelihood.</pre>
 * 
 * <pre> -M &lt;number&gt;
 *  Set the maximum number of iterations (default -1, until convergence).</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 errorString = Utils.getOption('M', options);
    if (errorString.length() != 0) {
        setMethod(new SelectedTag(Integer.parseInt(errorString), TAGS_METHOD));
    } else {
        setMethod(new SelectedTag(METHOD_1_AGAINST_ALL, TAGS_METHOD));
    }

    String rfactorString = Utils.getOption('R', options);
    if (rfactorString.length() != 0) {
        setRandomWidthFactor((new Double(rfactorString)).doubleValue());
    } else {
        setRandomWidthFactor(2.0);
    }

    setUsePairwiseCoupling(Utils.getFlag('P', options));

    super.setOptions(options);
}

From source file:GainRatioAttributeEval1.java

License:Open Source License

/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->// w  w  w . j  a va2  s .  co  m
 * Valid options are: <p/>
 * 
 * <pre> -M
 *  treat missing values as a seperate value.</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 {
    resetOptions();
    setMissingMerge(!(Utils.getFlag('M', options)));
}

From source file:SMO.java

License:Open Source License

/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->// ww  w. j a v  a  2  s  .  c  om
 * Valid options are: <p/>
 * 
 * <pre> -D
 *  If set, classifier is run in debug mode and
 *  may output additional info to the console</pre>
 * 
 * <pre> -no-checks
 *  Turns off all checks - use with caution!
 *  Turning them off assumes that data is purely numeric, doesn't
 *  contain any missing values, and has a nominal class. Turning them
 *  off also means that no header information will be stored if the
 *  machine is linear. Finally, it also assumes that no instance has
 *  a weight equal to 0.
 *  (default: checks on)</pre>
 * 
 * <pre> -C &lt;double&gt;
 *  The complexity constant C. (default 1)</pre>
 * 
 * <pre> -N
 *  Whether to 0=normalize/1=standardize/2=neither. (default 0=normalize)</pre>
 * 
 * <pre> -L &lt;double&gt;
 *  The tolerance parameter. (default 1.0e-3)</pre>
 * 
 * <pre> -P &lt;double&gt;
 *  The epsilon for round-off error. (default 1.0e-12)</pre>
 * 
 * <pre> -M
 *  Fit logistic models to SVM outputs. </pre>
 * 
 * <pre> -V &lt;double&gt;
 *  The number of folds for the internal
 *  cross-validation. (default -1, use training data)</pre>
 * 
 * <pre> -W &lt;double&gt;
 *  The random number seed. (default 1)</pre>
 * 
 * <pre> -K &lt;classname and parameters&gt;
 *  The Kernel to use.
 *  (default: weka.classifiers.functions.supportVector.PolyKernel)</pre>
 * 
 * <pre> 
 * Options specific to kernel weka.classifiers.functions.supportVector.PolyKernel:
 * </pre>
 * 
 * <pre> -D
 *  Enables debugging output (if available) to be printed.
 *  (default: off)</pre>
 * 
 * <pre> -no-checks
 *  Turns off all checks - use with caution!
 *  (default: checks on)</pre>
 * 
 * <pre> -C &lt;num&gt;
 *  The size of the cache (a prime number), 0 for full cache and 
 *  -1 to turn it off.
 *  (default: 250007)</pre>
 * 
 * <pre> -E &lt;num&gt;
 *  The Exponent to use.
 *  (default: 1.0)</pre>
 * 
 * <pre> -L
 *  Use lower-order terms.
 *  (default: no)</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;
    String[] tmpOptions;

    setChecksTurnedOff(Utils.getFlag("no-checks", options));

    tmpStr = Utils.getOption('C', options);
    if (tmpStr.length() != 0)
        setC(Double.parseDouble(tmpStr));
    else
        setC(1.0);

    tmpStr = Utils.getOption('L', options);
    if (tmpStr.length() != 0)
        setToleranceParameter(Double.parseDouble(tmpStr));
    else
        setToleranceParameter(1.0e-3);

    tmpStr = Utils.getOption('P', options);
    if (tmpStr.length() != 0)
        setEpsilon(Double.parseDouble(tmpStr));
    else
        setEpsilon(1.0e-12);

    tmpStr = Utils.getOption('N', options);
    if (tmpStr.length() != 0)
        setFilterType(new SelectedTag(Integer.parseInt(tmpStr), TAGS_FILTER));
    else
        setFilterType(new SelectedTag(FILTER_NORMALIZE, TAGS_FILTER));

    setBuildLogisticModels(Utils.getFlag('M', options));

    tmpStr = Utils.getOption('V', options);
    if (tmpStr.length() != 0)
        setNumFolds(Integer.parseInt(tmpStr));
    else
        setNumFolds(-1);

    tmpStr = Utils.getOption('W', options);
    if (tmpStr.length() != 0)
        setRandomSeed(Integer.parseInt(tmpStr));
    else
        setRandomSeed(1);

    tmpStr = Utils.getOption('K', options);
    tmpOptions = Utils.splitOptions(tmpStr);
    if (tmpOptions.length != 0) {
        tmpStr = tmpOptions[0];
        tmpOptions[0] = "";
        setKernel(Kernel.forName(tmpStr, tmpOptions));
    }

    super.setOptions(options);
}