Search in sources :

Example 16 with DecimalFormat

use of java.text.DecimalFormat in project lucida by claritylab.

the class Logger method logFactoidScore.

/**
	 * Logs the score of the factoid component.
	 * 
	 * @param score the score
	 * @param absThresh absolute confidence threshold for results
	 */
public static boolean logFactoidScore(float score, float absThresh) {
    // logging is disabled or log file is not specified
    if (!enabled || logfile == null)
        return false;
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(3);
    df.setMinimumFractionDigits(3);
    try {
        PrintWriter out = new PrintWriter(new FileOutputStream(logfile, true));
        out.println("<factoidscore abs_thresh=\"" + absThresh + "\">");
        out.println("\t" + df.format(score));
        out.println("</factoidscore>");
        out.close();
    } catch (IOException e) {
        return false;
    }
    return true;
}
Also used : DecimalFormat(java.text.DecimalFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 17 with DecimalFormat

use of java.text.DecimalFormat in project AnimeTaste by daimajia.

the class AlfredUtils method getReadableSize.

public static String getReadableSize(long bytes) {
    if (bytes <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024));
    return new DecimalFormat("#,##0.#").format(bytes / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 18 with DecimalFormat

use of java.text.DecimalFormat in project deeplearning4j by deeplearning4j.

the class Evaluation method stats.

/**
     * Method to obtain the classification report as a String
     *
     * @param suppressWarnings whether or not to output warnings related to the evaluation results
     * @return A (multi-line) String with accuracy, precision, recall, f1 score etc
     */
public String stats(boolean suppressWarnings) {
    String actual, expected;
    StringBuilder builder = new StringBuilder().append("\n");
    StringBuilder warnings = new StringBuilder();
    List<Integer> classes = confusion.getClasses();
    for (Integer clazz : classes) {
        actual = resolveLabelForClass(clazz);
        //Output confusion matrix
        for (Integer clazz2 : classes) {
            int count = confusion.getCount(clazz, clazz2);
            if (count != 0) {
                expected = resolveLabelForClass(clazz2);
                builder.append(String.format("Examples labeled as %s classified by model as %s: %d times%n", actual, expected, count));
            }
        }
        //Output possible warnings regarding precision/recall calculation
        if (!suppressWarnings && truePositives.getCount(clazz) == 0) {
            if (falsePositives.getCount(clazz) == 0) {
                warnings.append(String.format("Warning: class %s was never predicted by the model. This class was excluded from the average precision%n", actual));
            }
            if (falseNegatives.getCount(clazz) == 0) {
                warnings.append(String.format("Warning: class %s has never appeared as a true label. This class was excluded from the average recall%n", actual));
            }
        }
    }
    builder.append("\n");
    builder.append(warnings);
    DecimalFormat df = new DecimalFormat("#.####");
    double acc = accuracy();
    double prec = precision();
    double rec = recall();
    double f1 = f1();
    builder.append("\n==========================Scores========================================");
    builder.append("\n Accuracy:        ").append(format(df, acc));
    if (topN > 1) {
        double topNAcc = topNAccuracy();
        builder.append("\n Top ").append(topN).append(" Accuracy:  ").append(format(df, topNAcc));
    }
    builder.append("\n Precision:       ").append(format(df, prec));
    builder.append("\n Recall:          ").append(format(df, rec));
    builder.append("\n F1 Score:        ").append(format(df, f1));
    builder.append("\n========================================================================");
    return builder.toString();
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 19 with DecimalFormat

use of java.text.DecimalFormat in project deeplearning4j by deeplearning4j.

the class StringUtils method formatPercent.

/**
     * Format a percentage for presentation to the user.
     * @param done the percentage to format (0.0 to 1.0)
     * @param digits the number of digits past the decimal point
     * @return a string representation of the percentage
     */
public static String formatPercent(double done, int digits) {
    DecimalFormat percentFormat = new DecimalFormat("0.00%");
    double scale = Math.pow(10.0, digits + 2);
    double rounded = Math.floor(done * scale);
    percentFormat.setDecimalSeparatorAlwaysShown(false);
    percentFormat.setMinimumFractionDigits(digits);
    percentFormat.setMaximumFractionDigits(digits);
    return percentFormat.format(rounded / scale);
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 20 with DecimalFormat

use of java.text.DecimalFormat in project WilliamChart by diogobernardino.

the class StackedCardTwo method show.

@Override
public void show(Runnable action) {
    super.show(action);
    BarSet barSet = new BarSet(mLabels, mValues[0]);
    barSet.setColor(Color.parseColor("#90ee7e"));
    mChart.addData(barSet);
    barSet = new BarSet(mLabels, mValues[1]);
    barSet.setColor(Color.parseColor("#2b908f"));
    mChart.addData(barSet);
    Paint gridPaint = new Paint();
    gridPaint.setColor(Color.parseColor("#e7e7e7"));
    gridPaint.setStyle(Paint.Style.STROKE);
    gridPaint.setAntiAlias(true);
    gridPaint.setStrokeWidth(Tools.fromDpToPx(.7f));
    mChart.setBarSpacing(Tools.fromDpToPx(10));
    mChart.setBorderSpacing(0).setStep(1).setGrid(0, 10, gridPaint).setXAxis(false).setYAxis(false).setLabelsFormat(new DecimalFormat("##'M'")).show(new Animation().setDuration(2500).setEasing(new AccelerateInterpolator()).setEndAction(action));
}
Also used : BarSet(com.db.chart.model.BarSet) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) DecimalFormat(java.text.DecimalFormat) Animation(com.db.chart.animation.Animation) Paint(android.graphics.Paint)

Aggregations

DecimalFormat (java.text.DecimalFormat)719 DecimalFormatSymbols (java.text.DecimalFormatSymbols)89 NumberFormat (java.text.NumberFormat)88 BigDecimal (java.math.BigDecimal)45 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)33 ParseException (java.text.ParseException)30 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 Support_DecimalFormat (tests.support.Support_DecimalFormat)28 File (java.io.File)24 Date (java.util.Date)24 SimpleDateFormat (java.text.SimpleDateFormat)22 HashMap (java.util.HashMap)21 Locale (java.util.Locale)21 PrintWriter (java.io.PrintWriter)20 UsageVO (com.cloud.usage.UsageVO)19 JFreeChart (org.jfree.chart.JFreeChart)18 List (java.util.List)17 TextView (android.widget.TextView)15