Example usage for weka.core Utils joinOptions

List of usage examples for weka.core Utils joinOptions

Introduction

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

Prototype

public static String joinOptions(String[] optionArray) 

Source Link

Document

Joins all the options in an option array into a single string, as might be used on the command line.

Usage

From source file:SMO.java

License:Open Source License

/**
 * Gets the current settings of the classifier.
 *
 * @return an array of strings suitable for passing to setOptions
 *///from   ww w . j  a v a  2s.  co m
public String[] getOptions() {
    int i;
    Vector result;
    String[] options;

    result = new Vector();
    options = super.getOptions();
    for (i = 0; i < options.length; i++)
        result.add(options[i]);

    if (getChecksTurnedOff())
        result.add("-no-checks");

    result.add("-C");
    result.add("" + getC());

    result.add("-L");
    result.add("" + getToleranceParameter());

    result.add("-P");
    result.add("" + getEpsilon());

    result.add("-N");
    result.add("" + m_filterType);

    if (getBuildLogisticModels())
        result.add("-M");

    result.add("-V");
    result.add("" + getNumFolds());

    result.add("-W");
    result.add("" + getRandomSeed());

    result.add("-K");
    result.add("" + getKernel().getClass().getName() + " " + Utils.joinOptions(getKernel().getOptions()));

    return (String[]) result.toArray(new String[result.size()]);
}

From source file:WekaClassify.java

License:Open Source License

/**
 * outputs some data about the classifier
 *//*from w ww. j ava  2  s .co m*/
public String toString() {
    StringBuffer result;

    result = new StringBuffer();
    result.append("Weka - Classify\n===========\n\n");

    result.append("Classifier...: " + m_Classifier.getClass().getName() + " "
            + Utils.joinOptions(m_Classifier.getOptions()) + "\n");
    if (m_Filter != null) {
        if (m_Filter instanceof OptionHandler)
            result.append("Filter.......: " + m_Filter.getClass().getName() + " "
                    + Utils.joinOptions(((OptionHandler) m_Filter).getOptions()) + "\n");
        else
            result.append("Filter.......: " + m_Filter.getClass().getName() + "\n");
    }
    result.append("Training file: " + m_TrainingFile + "\n");
    result.append("\n");

    result.append(m_Classifier.toString() + "\n");
    result.append(m_Evaluation.toSummaryString() + "\n");
    try {
        result.append(m_Evaluation.toMatrixString() + "\n");
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        result.append(m_Evaluation.toClassDetailsString() + "\n");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result.toString();
}

From source file:WekaClassify.java

License:Open Source License

public String toStringAbbrev() {
    StringBuffer result;//www .  j  ava 2  s  .  c  o m
    result = new StringBuffer();
    result.append("Classifier...: " + m_Classifier.getClass().getName() + " "
            + Utils.joinOptions(m_Classifier.getOptions()) + "\n");
    result.append("Training file: " + m_TrainingFile + "\n");
    result.append("\n");
    result.append(m_Evaluation.toSummaryString() + "\n");
    try {
        result.append(m_Evaluation.toMatrixString() + "\n");
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        result.append(m_Evaluation.toClassDetailsString() + "\n");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result.toString();

}

From source file:OptionTree.java

License:Open Source License

/**
 * Returns the options for this node and its subtree.
 * //  w w  w.ja  v a2  s . c  o m
 * @param node
 *            the node to get the options for
 * @return the generated options
 */
protected String getOptions(DefaultMutableTreeNode node) {
    Vector<String> options;
    int i;

    options = new Vector<String>();

    // the node itself
    if (!node.toString().equals(LABEL_ROOT) && !node.toString().equals(LABEL_NESTED))
        options.add(node.toString());

    // the node's children
    for (i = 0; i < node.getChildCount(); i++)
        options.add(getOptions((DefaultMutableTreeNode) node.getChildAt(i)));

    return Utils.joinOptions(options.toArray(new String[options.size()]));
}

From source file:OptionTree.java

License:Open Source License

/**
 * Displays a frame with the option tree panel.
 * //ww w .j  av  a2s.c  om
 * @param args
 *            displayed in the full options text
 */
public static void main(String[] args) {
    OptionTree tree = new OptionTree();
    final JFrame jf = new JFrame("Option Tree");
    jf.getContentPane().setLayout(new BorderLayout());
    jf.getContentPane().add(tree, BorderLayout.CENTER);
    jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    jf.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            jf.dispose();
        }
    });
    jf.pack();
    jf.setSize(800, 600);
    jf.setLocationRelativeTo(null);
    jf.setVisible(true);

    if (args.length > 0)
        tree.setOptions(Utils.joinOptions(args));
}

From source file:HierarchicalClusterer.java

License:Open Source License

/**
 * Gets the current settings of the clusterer.
 *
 * @return an array of strings suitable for passing to setOptions()
 *//*from w w  w . jav  a  2  s . com*/
public String[] getOptions() {

    String[] options = new String[14];
    int current = 0;

    options[current++] = "-N";
    options[current++] = "" + getNumClusters();

    options[current++] = "-L";
    switch (m_nLinkType) {
    case (SINGLE):
        options[current++] = "SINGLE";
        break;
    case (COMPLETE):
        options[current++] = "COMPLETE";
        break;
    case (AVERAGE):
        options[current++] = "AVERAGE";
        break;
    case (MEAN):
        options[current++] = "MEAN";
        break;
    case (CENTROID):
        options[current++] = "CENTROID";
        break;
    case (WARD):
        options[current++] = "WARD";
        break;
    case (ADJCOMLPETE):
        options[current++] = "ADJCOMLPETE";
        break;
    case (NEIGHBOR_JOINING):
        options[current++] = "NEIGHBOR_JOINING";
        break;
    }
    if (m_bPrintNewick) {
        options[current++] = "-P";
    }
    if (getDebug()) {
        options[current++] = "-D";
    }
    if (getDistanceIsBranchLength()) {
        options[current++] = "-B";
    }

    options[current++] = "-A";
    options[current++] = (m_DistanceFunction.getClass().getName() + " "
            + Utils.joinOptions(m_DistanceFunction.getOptions())).trim();

    while (current < options.length) {
        options[current++] = "";
    }

    return options;
}

From source file:adams.gui.tools.WekaOptionsConversionPanel.java

License:Open Source License

/**
 * Performs the conversion.//  w  ww .  ja v a 2  s . c  om
 */
protected void convert() {
    WekaCommandLineHandler cmd;
    Object obj;
    StringBuilder buf;
    OptionHandler handler;

    try {
        cmd = new WekaCommandLineHandler();
        obj = cmd.fromCommandLine(m_TextAreaInput.getText());

        buf = new StringBuilder();
        buf.append("--> String:\n");
        buf.append("\n");
        buf.append("\"" + Utils.backQuoteChars(cmd.toCommandLine(obj)) + "\"\n");
        buf.append("\n");
        buf.append("\n");
        buf.append("--> Test class:\n");
        buf.append("\n");
        buf.append("public class OptionsTest {\n");
        buf.append("\n");
        buf.append("  public static void main(String[] args) throws Exception {\n");
        buf.append("    // create new instance of scheme\n");
        buf.append("    " + obj.getClass().getName() + " scheme = new " + obj.getClass().getName() + "();\n");
        if (obj instanceof OptionHandler) {
            handler = (OptionHandler) obj;
            buf.append("    \n");
            buf.append("    // set options\n");
            buf.append("    scheme.setOptions(weka.core.Utils.splitOptions(\""
                    + Utils.backQuoteChars(Utils.joinOptions(handler.getOptions())) + "\"));\n");
            buf.append("  }\n");
        }
        buf.append("}\n");

        m_TextAreaCodeOutput.setText(buf.toString());
        m_TextAreaCodeOutput.getComponent().setCaretPosition(0);
    } catch (Exception ex) {
        ex.printStackTrace();
        GUIHelper.showErrorMessage(this, "Failed to convert options:\n" + ex);
    }
}

From source file:adaptedClusteringAlgorithms.MyFarthestFirst.java

License:Open Source License

/**
 * Gets the current settings of FarthestFirst
 *
 * @return an array of strings suitable for passing to setOptions()
 *//*  w  w  w.  j a v a 2s  .  c  o m*/
public String[] getOptions() {
    int i;
    Vector result;
    String[] options;

    result = new Vector();

    result.add("-N");
    result.add("" + getNumClusters());

    result.add("-A");
    result.add(
            (m_DistanceFunction.getClass().getName() + " " + Utils.joinOptions(m_DistanceFunction.getOptions()))
                    .trim());

    options = super.getOptions();
    for (i = 0; i < options.length; i++)
        result.add(options[i]);

    return (String[]) result.toArray(new String[result.size()]);
}

From source file:adaptedClusteringAlgorithms.MySimpleKMeans.java

License:Open Source License

/**
 * Gets the current settings of SimpleKMeans
 * //from   www  .j  ava2s  . c  o  m
 * @return an array of strings suitable for passing to setOptions()
 */
@Override
public String[] getOptions() {
    int i;
    Vector result;
    String[] options;

    result = new Vector();

    if (m_displayStdDevs) {
        result.add("-V");
    }

    if (m_dontReplaceMissing) {
        result.add("-M");
    }

    result.add("-N");
    result.add("" + getNumClusters());

    result.add("-A");
    result.add(
            (m_DistanceFunction.getClass().getName() + " " + Utils.joinOptions(m_DistanceFunction.getOptions()))
                    .trim());

    result.add("-I");
    result.add("" + getMaxIterations());

    if (m_PreserveOrder) {
        result.add("-O");
    }

    options = super.getOptions();
    for (i = 0; i < options.length; i++) {
        result.add(options[i]);
    }

    return (String[]) result.toArray(new String[result.size()]);
}

From source file:asap.CrossValidation.java

/**
 *
 * @param dataInput/*  w  ww. j a v  a2s. co m*/
 * @param classIndex
 * @param removeIndices
 * @param cls
 * @param seed
 * @param folds
 * @param modelOutputFile
 * @return
 * @throws Exception
 */
public static String performCrossValidation(String dataInput, String classIndex, String removeIndices,
        AbstractClassifier cls, int seed, int folds, String modelOutputFile) throws Exception {

    PerformanceCounters.startTimer("cross-validation ST");

    PerformanceCounters.startTimer("cross-validation init ST");

    // loads data and set class index
    Instances data = DataSource.read(dataInput);
    String clsIndex = classIndex;

    switch (clsIndex) {
    case "first":
        data.setClassIndex(0);
        break;
    case "last":
        data.setClassIndex(data.numAttributes() - 1);
        break;
    default:
        try {
            data.setClassIndex(Integer.parseInt(clsIndex) - 1);
        } catch (NumberFormatException e) {
            data.setClassIndex(data.attribute(clsIndex).index());
        }
        break;
    }

    Remove removeFilter = new Remove();
    removeFilter.setAttributeIndices(removeIndices);
    removeFilter.setInputFormat(data);
    data = Filter.useFilter(data, removeFilter);

    // randomize data
    Random rand = new Random(seed);
    Instances randData = new Instances(data);
    randData.randomize(rand);
    if (randData.classAttribute().isNominal()) {
        randData.stratify(folds);
    }

    // perform cross-validation and add predictions
    Evaluation eval = new Evaluation(randData);
    Instances trainSets[] = new Instances[folds];
    Instances testSets[] = new Instances[folds];
    Classifier foldCls[] = new Classifier[folds];

    for (int n = 0; n < folds; n++) {
        trainSets[n] = randData.trainCV(folds, n);
        testSets[n] = randData.testCV(folds, n);
        foldCls[n] = AbstractClassifier.makeCopy(cls);
    }

    PerformanceCounters.stopTimer("cross-validation init ST");
    PerformanceCounters.startTimer("cross-validation folds+train ST");
    //paralelize!!:--------------------------------------------------------------
    for (int n = 0; n < folds; n++) {
        Instances train = trainSets[n];
        Instances test = testSets[n];

        // the above code is used by the StratifiedRemoveFolds filter, the
        // code below by the Explorer/Experimenter:
        // Instances train = randData.trainCV(folds, n, rand);
        // build and evaluate classifier
        Classifier clsCopy = foldCls[n];
        clsCopy.buildClassifier(train);
        eval.evaluateModel(clsCopy, test);
    }

    cls.buildClassifier(data);
    //until here!-----------------------------------------------------------------

    PerformanceCounters.stopTimer("cross-validation folds+train ST");
    PerformanceCounters.startTimer("cross-validation post ST");
    // output evaluation
    String out = "\n" + "=== Setup ===\n" + "Classifier: " + cls.getClass().getName() + " "
            + Utils.joinOptions(cls.getOptions()) + "\n" + "Dataset: " + data.relationName() + "\n" + "Folds: "
            + folds + "\n" + "Seed: " + seed + "\n" + "\n"
            + eval.toSummaryString("=== " + folds + "-fold Cross-validation ===", false) + "\n";

    if (!modelOutputFile.isEmpty()) {
        SerializationHelper.write(modelOutputFile, cls);
    }

    PerformanceCounters.stopTimer("cross-validation post ST");
    PerformanceCounters.stopTimer("cross-validation ST");

    return out;
}