use of java.text.DecimalFormat in project zeppelin by apache.
the class TransferListener method transferSucceeded.
@Override
public void transferSucceeded(TransferEvent event) {
transferCompleted(event);
TransferResource resource = event.getResource();
long contentLength = event.getTransferredBytes();
if (contentLength >= 0) {
String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";
String throughput = "";
long duration = System.currentTimeMillis() - resource.getTransferStartTime();
if (duration > 0) {
DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
throughput = " at " + format.format(kbPerSec) + " KB/sec";
}
logger.info(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")");
}
}
use of java.text.DecimalFormat in project cucumber-jvm by cucumber.
the class JUnitFormatter method sumTimes.
private String sumTimes(NodeList testCaseNodes) {
double totalDurationSecondsForAllTimes = 0.0d;
for (int i = 0; i < testCaseNodes.getLength(); i++) {
try {
double testCaseTime = Double.parseDouble(testCaseNodes.item(i).getAttributes().getNamedItem("time").getNodeValue());
totalDurationSecondsForAllTimes += testCaseTime;
} catch (NumberFormatException e) {
throw new CucumberException(e);
} catch (NullPointerException e) {
throw new CucumberException(e);
}
}
DecimalFormat nfmt = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
nfmt.applyPattern("0.######");
return nfmt.format(totalDurationSecondsForAllTimes);
}
use of java.text.DecimalFormat in project cucumber-jvm by cucumber.
the class Stats method printDuration.
private void printDuration(PrintStream out) {
out.print(String.format("%dm", (totalDuration / ONE_MINUTE)));
DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale));
out.println(format.format(((double) (totalDuration % ONE_MINUTE)) / ONE_SECOND) + "s");
}
use of java.text.DecimalFormat in project lucida by claritylab.
the class Experimenter method runExperiments.
/**
* Runs the experiments specified in the input properties file. The set of
* experiments run is the cross-product of the sets of algorithm configurations, training/testing
* dataset configurations, and feature type combinations.
*
*/
public void runExperiments() {
DecimalFormat format = new DecimalFormat("#0.00");
HierarchicalClassifierTrainer qc = new HierarchicalClassifierTrainer(languagePair);
StringBuilder sb = new StringBuilder();
for (String alg : learningCombos) {
properties.setProperty("learners", alg);
for (String featureTypes : featureTypeCombos) {
properties.setProperty("featureTypes", featureTypes);
qc.setProperties(properties);
Evaluation eval = qc.runExperiment();
sb.append(alg.replaceAll(",", "-") + "-" + featureTypes.replaceAll(",", "-") + format.format((1.0 - eval.errorRate()) * 100) + "\n");
String report = qc.createReport();
log.debug("Report:\n" + report);
FileUtil.writeFile(report, "reports/report-" + alg.replaceAll(",", "-") + "-" + featureTypes.replaceAll(",", "-") + ".txt", "UTF-8");
}
}
FileUtil.writeFile(sb.toString(), "reports/results-" + System.currentTimeMillis() + ".txt", "UTF-8");
}
use of java.text.DecimalFormat in project lucida by claritylab.
the class QuestionClassifier method evaluate.
/**
* Evaluates classification accuracy on a given test set.
*
* @param testSetFileName the name of the file containing the test set to evaluate against
* @throws Exception
*/
public void evaluate(String testSetFileName) throws Exception {
DecimalFormat format = new DecimalFormat("#0.00");
int correct = 0;
List<GoldStandard> goldStandards;
goldStandards = GoldStandard.loadFile(testSetFileName);
int size = goldStandards.size();
//System.out.println(String.format("%18s / %-18s","Actual","Predicted"));
for (GoldStandard gs : goldStandards) {
String question = gs.getQuestion(languagePair.getFirst().name().split("_")[0].toUpperCase());
String actual = gs.getAnswerType();
Set<AnswerType> actuals = new HashSet<AnswerType>();
Set<AnswerType> predicted = new HashSet<AnswerType>();
for (String atypeStr : actual.split("\\|")) {
actuals.add(AnswerType.constructFromString(atypeStr));
}
List<AnswerType> atypes = getAnswerTypes(question);
if (atypes.size() > 0) {
double topConf = atypes.get(0).getConfidence();
for (int i = 0; i < atypes.size(); i++) {
if (atypes.get(i).getConfidence() == topConf) {
predicted.add(atypes.get(i));
atypes.remove(i);
i--;
}
}
}
boolean corr = false;
for (AnswerType a : predicted) if (actuals.contains(a))
corr = true;
if (corr)
correct++;
else {
log.debug("A: " + actuals + ", P: " + predicted + ", " + question);
if (atypes.size() > 0)
log.debug(" 2nd: " + atypes.get(0));
}
}
if (size > 0)
System.out.println("Test set accuracy: " + correct + "/" + size + " (" + format.format((double) correct / (double) size * 100) + "%)");
else
System.out.println("No examples classified.");
}
Aggregations