use of java.text.DecimalFormat in project CoreNLP by stanfordnlp.
the class TestSentence method printTop.
// This method should be called after a sentence has been tagged.
// For every word token, this method prints the 3 most probable tags
// to the file pfu except for
void printTop(PrintFile pfu) {
NumberFormat nf = new DecimalFormat("0.0000");
int numTags = maxentTagger.numTags();
double[][][] probabilities = new double[size][kBestSize][numTags];
calculateProbs(probabilities);
for (int current = 0; current < correctTags.length; current++) {
pfu.print(sent.get(current));
double[] probs = new double[3];
String[] tag3 = new String[3];
getTop3(probabilities, current, probs, tag3);
for (int i = 0; i < 3; i++) {
if (probs[i] > Double.NEGATIVE_INFINITY) {
pfu.print('\t');
pfu.print(tag3[i]);
pfu.print(' ');
pfu.print(nf.format(Math.exp(probs[i])));
}
}
int rank;
String correctTag = toNice(this.correctTags[current]);
for (rank = 0; rank < 3; rank++) {
if (correctTag.equals(tag3[rank])) {
break;
}
//if
}
pfu.print('\t');
switch(rank) {
case 0:
pfu.print("Correct");
break;
case 1:
pfu.print("2nd");
break;
case 2:
pfu.print("3rd");
break;
default:
pfu.print("Not top 3");
}
pfu.println();
}
// for
}
use of java.text.DecimalFormat in project CoreNLP by stanfordnlp.
the class TwoDimensionalIntCounter method toMatrixString.
@SuppressWarnings({ "unchecked" })
public String toMatrixString(int cellSize) {
List<K1> firstKeys = new ArrayList<>(firstKeySet());
List<K2> secondKeys = new ArrayList<>(secondKeySet());
Collections.sort((List<? extends Comparable>) firstKeys);
Collections.sort((List<? extends Comparable>) secondKeys);
int[][] counts = toMatrix(firstKeys, secondKeys);
return ArrayMath.toString(counts, firstKeys.toArray(), secondKeys.toArray(), cellSize, cellSize, new DecimalFormat(), true);
}
use of java.text.DecimalFormat in project gephi by gephi.
the class Modularity method getReport.
@Override
public String getReport() {
//Distribution series
Map<Integer, Integer> sizeDist = new HashMap<>();
for (Node n : structure.graph.getNodes()) {
Integer v = (Integer) n.getAttribute(MODULARITY_CLASS);
if (!sizeDist.containsKey(v)) {
sizeDist.put(v, 0);
}
sizeDist.put(v, sizeDist.get(v) + 1);
}
XYSeries dSeries = ChartUtils.createXYSeries(sizeDist, "Size Distribution");
XYSeriesCollection dataset1 = new XYSeriesCollection();
dataset1.addSeries(dSeries);
JFreeChart chart = ChartFactory.createXYLineChart("Size Distribution", "Modularity Class", "Size (number of nodes)", dataset1, PlotOrientation.VERTICAL, true, false, false);
chart.removeLegend();
ChartUtils.decorateChart(chart);
ChartUtils.scaleChart(chart, dSeries, false);
String imageFile = ChartUtils.renderChart(chart, "communities-size-distribution.png");
NumberFormat f = new DecimalFormat("#0.000");
String report = "<HTML> <BODY> <h1>Modularity Report </h1> " + "<hr>" + "<h2> Parameters: </h2>" + "Randomize: " + (isRandomized ? "On" : "Off") + "<br>" + "Use edge weights: " + (useWeight ? "On" : "Off") + "<br>" + "Resolution: " + (resolution) + "<br>" + "<br> <h2> Results: </h2>" + "Modularity: " + f.format(modularity) + "<br>" + "Modularity with resolution: " + f.format(modularityResolution) + "<br>" + "Number of Communities: " + structure.communities.size() + "<br /><br />" + imageFile + "<br /><br />" + "<h2> Algorithm: </h2>" + "Vincent D Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Etienne Lefebvre, <i>Fast unfolding of communities in large networks</i>, in Journal of Statistical Mechanics: Theory and Experiment 2008 (10), P1000<br />" + "<br /><br />" + "<h2> Resolution: </h2>" + "R. Lambiotte, J.-C. Delvenne, M. Barahona <i>Laplacian Dynamics and Multiscale Modular Structure in Networks 2009<br />" + "</BODY> </HTML>";
return report;
}
use of java.text.DecimalFormat in project gephi by gephi.
the class WeightedDegree method getDirectedReport.
public String getDirectedReport() {
//Distribution series
XYSeries dSeries = ChartUtils.createXYSeries(degreeDist, "Degree Distribution");
XYSeries idSeries = ChartUtils.createXYSeries(inDegreeDist, "In-Degree Distribution");
XYSeries odSeries = ChartUtils.createXYSeries(outDegreeDist, "Out-Degree Distribution");
XYSeriesCollection dataset1 = new XYSeriesCollection();
dataset1.addSeries(dSeries);
XYSeriesCollection dataset2 = new XYSeriesCollection();
dataset2.addSeries(idSeries);
XYSeriesCollection dataset3 = new XYSeriesCollection();
dataset3.addSeries(odSeries);
JFreeChart chart1 = ChartFactory.createXYLineChart("Degree Distribution", "Value", "Count", dataset1, PlotOrientation.VERTICAL, true, false, false);
ChartUtils.decorateChart(chart1);
ChartUtils.scaleChart(chart1, dSeries, false);
String degreeImageFile = ChartUtils.renderChart(chart1, "w-degree-distribution.png");
JFreeChart chart2 = ChartFactory.createXYLineChart("In-Degree Distribution", "Value", "Count", dataset2, PlotOrientation.VERTICAL, true, false, false);
ChartUtils.decorateChart(chart2);
ChartUtils.scaleChart(chart2, dSeries, false);
String indegreeImageFile = ChartUtils.renderChart(chart2, "indegree-distribution.png");
JFreeChart chart3 = ChartFactory.createXYLineChart("Out-Degree Distribution", "Value", "Count", dataset3, PlotOrientation.VERTICAL, true, false, false);
ChartUtils.decorateChart(chart3);
ChartUtils.scaleChart(chart3, dSeries, false);
String outdegreeImageFile = ChartUtils.renderChart(chart3, "outdegree-distribution.png");
NumberFormat f = new DecimalFormat("#0.000");
String report = "<HTML> <BODY> <h1>Weighted Degree Report </h1> " + "<hr>" + "<br> <h2> Results: </h2>" + "Average Weighted Degree: " + f.format(avgWDegree) + "<br /><br />" + degreeImageFile + "<br /><br />" + indegreeImageFile + "<br /><br />" + outdegreeImageFile + "</BODY></HTML>";
return report;
}
use of java.text.DecimalFormat in project gephi by gephi.
the class DynamicNbEdges method getReport.
@Override
public String getReport() {
//Time series
XYSeries dSeries = ChartUtils.createXYSeries(counts, "Nb Edges Time Series");
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(dSeries);
JFreeChart chart = ChartFactory.createXYLineChart("# Edges Time Series", "Time", "# Edges", dataset, PlotOrientation.VERTICAL, true, false, false);
chart.removeLegend();
ChartUtils.decorateChart(chart);
ChartUtils.scaleChart(chart, dSeries, false);
String imageFile = ChartUtils.renderChart(chart, "nb-edges-ts.png");
NumberFormat f = new DecimalFormat("#0.000");
String report = "<HTML> <BODY> <h1>Dynamic Number of Edges Report </h1> " + "<hr>" + "<br> Bounds: from " + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window + "<br> Tick: " + tick + "<br><br><h2> Number of edges over time: </h2>" + "<br /><br />" + imageFile;
/*for (Interval<Integer> count : counts) {
report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
}*/
report += "<br /><br /></BODY></HTML>";
return report;
}
Aggregations