Example usage for weka.core Utils padRight

List of usage examples for weka.core Utils padRight

Introduction

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

Prototype

public static String padRight(String inString, int length) 

Source Link

Document

Pads a string to a specified length, inserting spaces on the right as required.

Usage

From source file:clusterer.HaritsDBScan.java

License:Open Source License

/**
 * Returns a description of the clusterer
 * //from  ww w. j  a  va2 s  .c om
 * @return a string representation of the clusterer
 */
public String toString() {
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("DBSCAN clustering results\n"
            + "========================================================================================\n\n");
    stringBuffer.append("Clustered DataObjects: " + database.size() + "\n");
    stringBuffer.append("Number of attributes: " + database.getInstances().numAttributes() + "\n");
    stringBuffer.append("Epsilon: " + getEpsilon() + "; minPoints: " + getMinPoints() + "\n");
    stringBuffer.append("Index: " + getDatabase_Type() + "\n");
    stringBuffer.append("Distance-type: " + getDatabase_distanceType() + "\n");
    stringBuffer.append("Number of generated clusters: " + numberOfGeneratedClusters + "\n");
    DecimalFormat decimalFormat = new DecimalFormat(".##");
    stringBuffer.append("Elapsed time: " + decimalFormat.format(elapsedTime) + "\n\n");

    for (int i = 0; i < database.size(); i++) {
        DataObject dataObject = database.getDataObject(Integer.toString(i));
        stringBuffer.append("("
                + Utils.doubleToString(Double.parseDouble(dataObject.getKey()),
                        (Integer.toString(database.size()).length()), 0)
                + ".) " + Utils.padRight(dataObject.toString(), 69) + "  -->  "
                + ((dataObject.getClusterLabel() == DataObject.NOISE) ? "NOISE\n"
                        : dataObject.getClusterLabel() + "\n"));
    }
    return stringBuffer.toString() + "\n";
}

From source file:core.DBScan.java

License:Open Source License

/**
 * Returns a description of the clusterer
 * //  ww  w  . ja va 2s  .  c o m
 * @return a string representation of the clusterer
 */
public String toString() {
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("DBScan clustering results\n"
            + "========================================================================================\n\n");
    stringBuffer.append("Clustered DataObjects: " + database.size() + "\n");
    stringBuffer.append("Number of attributes: " + database.getInstances().numAttributes() + "\n");
    stringBuffer.append("Epsilon: " + getEpsilon() + "; minPoints: " + getMinPoints() + "\n");
    stringBuffer.append("Index: " + getDatabase_Type() + "\n");
    stringBuffer.append("Distance-type: " + getDatabase_distanceType() + "\n");
    stringBuffer.append("Number of generated clusters: " + numberOfGeneratedClusters + "\n");
    DecimalFormat decimalFormat = new DecimalFormat(".##");
    stringBuffer.append("Elapsed time: " + decimalFormat.format(elapsedTime) + "\n\n");

    double[][] clusterID = new double[1][ID.numInstances()];
    for (int i = 0; i < database.size(); i++) {
        DataObject dataObject = database.getDataObject(Integer.toString(i));
        stringBuffer.append("("
                + Utils.doubleToString(Double.parseDouble(dataObject.getKey()),
                        (Integer.toString(database.size()).length()), 0)
                + ".) " + Utils.padRight(dataObject.toString(), 69) + "  -->  "
                + ((dataObject.getClusterLabel() == DataObject.NOISE) ? "NOISE\n"
                        : dataObject.getClusterLabel() + "\n"));
    }
    return stringBuffer.toString() + "\n";
}

From source file:LogReg.Logistic.java

License:Open Source License

/**
 * Gets a string describing the classifier.
 *
 * @return a string describing the classifer built.
 *///w w  w .j  av a 2s .  c om
public String toString() {
    StringBuffer temp = new StringBuffer();

    String result = "";
    temp.append("Logistic Regression with ridge parameter of " + m_Ridge);
    if (m_Par == null) {
        return result + ": No model built yet.";
    }

    // find longest attribute name
    int attLength = 0;
    for (int i = 0; i < m_structure.numAttributes(); i++) {
        if (i != m_structure.classIndex() && m_structure.attribute(i).name().length() > attLength) {
            attLength = m_structure.attribute(i).name().length();
        }
    }

    if ("Intercept".length() > attLength) {
        attLength = "Intercept".length();
    }

    if ("Variable".length() > attLength) {
        attLength = "Variable".length();
    }
    attLength += 2;

    int colWidth = 0;
    // check length of class names
    for (int i = 0; i < m_structure.classAttribute().numValues() - 1; i++) {
        if (m_structure.classAttribute().value(i).length() > colWidth) {
            colWidth = m_structure.classAttribute().value(i).length();
        }
    }

    // check against coefficients and odds ratios
    for (int j = 1; j <= m_NumPredictors; j++) {
        for (int k = 0; k < m_NumClasses - 1; k++) {
            if (Utils.doubleToString(m_Par[j][k], 12, 4).trim().length() > colWidth) {
                colWidth = Utils.doubleToString(m_Par[j][k], 12, 4).trim().length();
            }
            double ORc = Math.exp(m_Par[j][k]);
            String t = " " + ((ORc > 1e10) ? "" + ORc : Utils.doubleToString(ORc, 12, 4));
            if (t.trim().length() > colWidth) {
                colWidth = t.trim().length();
            }
        }
    }

    if ("Class".length() > colWidth) {
        colWidth = "Class".length();
    }
    colWidth += 2;

    temp.append("\nCoefficients...\n");
    temp.append(Utils.padLeft(" ", attLength) + Utils.padLeft("Class", colWidth) + "\n");
    temp.append(Utils.padRight("Variable", attLength));

    for (int i = 0; i < m_NumClasses - 1; i++) {
        String className = m_structure.classAttribute().value(i);
        temp.append(Utils.padLeft(className, colWidth));
    }
    temp.append("\n");
    int separatorL = attLength + ((m_NumClasses - 1) * colWidth);
    for (int i = 0; i < separatorL; i++) {
        temp.append("=");
    }
    temp.append("\n");

    int j = 1;
    for (int i = 0; i < m_structure.numAttributes(); i++) {
        if (i != m_structure.classIndex()) {
            temp.append(Utils.padRight(m_structure.attribute(i).name(), attLength));
            for (int k = 0; k < m_NumClasses - 1; k++) {
                temp.append(Utils.padLeft(Utils.doubleToString(m_Par[j][k], 12, 4).trim(), colWidth));
            }
            temp.append("\n");
            j++;
        }
    }

    temp.append(Utils.padRight("Intercept", attLength));
    for (int k = 0; k < m_NumClasses - 1; k++) {
        temp.append(Utils.padLeft(Utils.doubleToString(m_Par[0][k], 10, 4).trim(), colWidth));
    }
    temp.append("\n");

    temp.append("\n\nOdds Ratios...\n");
    temp.append(Utils.padLeft(" ", attLength) + Utils.padLeft("Class", colWidth) + "\n");
    temp.append(Utils.padRight("Variable", attLength));

    for (int i = 0; i < m_NumClasses - 1; i++) {
        String className = m_structure.classAttribute().value(i);
        temp.append(Utils.padLeft(className, colWidth));
    }
    temp.append("\n");
    for (int i = 0; i < separatorL; i++) {
        temp.append("=");
    }
    temp.append("\n");

    j = 1;
    for (int i = 0; i < m_structure.numAttributes(); i++) {
        if (i != m_structure.classIndex()) {
            temp.append(Utils.padRight(m_structure.attribute(i).name(), attLength));
            for (int k = 0; k < m_NumClasses - 1; k++) {
                double ORc = Math.exp(m_Par[j][k]);
                String ORs = " " + ((ORc > 1e10) ? "" + ORc : Utils.doubleToString(ORc, 12, 4));
                temp.append(Utils.padLeft(ORs.trim(), colWidth));
            }
            temp.append("\n");
            j++;
        }
    }

    return temp.toString();
}

From source file:meka.core.MLUtils.java

License:Open Source License

/**
 * Print out a HashMap nicely.// w w w.  j ava2s .  c  o m
 * @param   map   HashMap
 * @param   dp   decimal point precision (-1 for no limitation)
 * @return   String representation of map
 */
public static String hashMapToString(HashMap<?, ?> map, int dp) {
    StringBuilder sb = new StringBuilder();
    for (Object k : map.keySet()) {
        sb.append(Utils.padRight(k.toString(), 31));
        Object obj = map.get(k);
        //sb.append(" : ");
        if (obj instanceof Double) {
            sb.append(Utils.doubleToString((Double) obj, 5, dp));
        } else if (obj instanceof double[]) {
            sb.append(A.toString((double[]) obj, dp));
        } else if (obj instanceof int[]) {
            sb.append(A.toString((int[]) obj, dp + 2));
        } else if (obj instanceof String) {
            String s = (String) obj;
            if (s.contains("\n"))
                sb.append("\n");
            sb.append(obj);
            if (s.contains("\n"))
                sb.append("\n");
        } else {
            // don't append if we don't know what it is!
            //sb.append(obj);
        }
        sb.append('\n');
    }
    return sb.toString();
}

From source file:motaz.CODB.java

License:Open Source License

public StringBuffer report() {
    StringBuffer stringBuffer = new StringBuffer();
    DecimalFormat decimalFormat = new DecimalFormat(".#####");
    //decimalFormat.format(
    for (int i = 0; i < database.size(); i++) {
        DataObject dataObject = (DataObject) database.getDataObject(Integer.toString(i));

        stringBuffer.append("("
                + Utils.doubleToString(Double.parseDouble(dataObject.getKey()),
                        (Integer.toString(database.size()).length()), 0)
                + ".) " + Utils.padRight(dataObject.toString(), 69) + "\n");

        List knn = myknn(getK(), dataObject);

        stringBuffer.append(//from w  w  w. ja va  2  s.  c  o  m
                "=== The " + getK() + " Nearst Neighbors of the Instance #" + dataObject.getKey() + " ====\n");
        for (int j = 0; j < knn.size(); j++) {
            PriorityQueueElement pqe = (PriorityQueueElement) knn.get(j);
            DataObject knndataObject = (DataObject) pqe.getObject();
            stringBuffer.append(knndataObject.getKey() + "\t\t" + knndataObject.toString() + "\t\tDistance: "
                    + decimalFormat.format(pqe.getPriority()) + "\n");

        }

        stringBuffer.append(
                "======================================================================================\n");
    }
    return stringBuffer;
}

From source file:technion.prime.history.converters.MyDBScan.java

License:Open Source License

/**
 * Returns a description of the clusterer
 * /*from  ww  w  . j a  va 2s  .  c  om*/
 * @return a string representation of the clusterer
 */
@Override
public String toString() {
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("DBScan clustering results\n"
            + "========================================================================================\n\n");
    stringBuffer.append("Clustered DataObjects: " + database.size() + "\n");
    stringBuffer.append("Number of attributes: " + database.getInstances().numAttributes() + "\n");
    stringBuffer.append("Epsilon: " + getEpsilon() + "; minPoints: " + getMinPoints() + "\n");
    stringBuffer.append("Index: " + getDatabase_Type() + "\n");
    stringBuffer.append("Distance-type: " + getDatabase_distanceType() + "\n");
    stringBuffer.append("Number of generated clusters: " + numberOfGeneratedClusters + "\n");
    DecimalFormat decimalFormat = new DecimalFormat(".##");
    stringBuffer.append("Elapsed time: " + decimalFormat.format(elapsedTime) + "\n\n");

    for (int i = 0; i < database.size(); i++) {
        DataObject dataObject = database.getDataObject(Integer.toString(i));
        stringBuffer.append("("
                + Utils.doubleToString(Double.parseDouble(dataObject.getKey()),
                        (Integer.toString(database.size()).length()), 0)
                + ".) " + Utils.padRight(dataObject.toString(), 69) + "  -->  "
                + ((dataObject.getClusterLabel() == DataObject.NOISE) ? "NOISE\n"
                        : dataObject.getClusterLabel() + "\n"));
    }
    return stringBuffer.toString() + "\n";
}