use of java.text.DecimalFormat in project Cloud9 by lintool.
the class IndexableAnchorTextForwardIndex method getDocument.
public IndexableAnchorText getDocument(int docno) {
int idx = Arrays.binarySearch(docnos, docno);
if (idx < 0)
idx = -idx - 2;
DecimalFormat df = new DecimalFormat("00000");
String file = collectionPath + "/part-" + df.format(filenos[idx]);
try {
SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(file), conf);
IntWritable key = new IntWritable();
ArrayListWritable<AnchorText> value = new ArrayListWritable<AnchorText>();
reader.seek(offsets[idx]);
while (reader.next(key)) {
if (key.get() == docno)
break;
}
reader.getCurrentValue(value);
reader.close();
indexableAnchorText.createHTML(value);
return indexableAnchorText;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of java.text.DecimalFormat in project android-common by litesuits.
the class LogReader method FormatFileSize.
public static String FormatFileSize(long fileS) {
// 转换文件大小
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
if (fileS < 1024) {
fileSizeString = df.format((double) fileS) + "B";
} else if (fileS < 1048576) {
fileSizeString = df.format((double) fileS / 1024) + "K";
} else if (fileS < 1073741824) {
fileSizeString = df.format((double) fileS / 1048576) + "M";
} else {
fileSizeString = df.format((double) fileS / 1073741824) + "G";
}
return fileSizeString;
}
use of java.text.DecimalFormat in project android-common by litesuits.
the class FileUtil method formatFileSizeToString.
public static String formatFileSizeToString(long fileLen) {
// 转换文件大小
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
if (fileLen < 1024) {
fileSizeString = df.format((double) fileLen) + "B";
} else if (fileLen < 1048576) {
fileSizeString = df.format((double) fileLen / 1024) + "K";
} else if (fileLen < 1073741824) {
fileSizeString = df.format((double) fileLen / 1048576) + "M";
} else {
fileSizeString = df.format((double) fileLen / 1073741824) + "G";
}
return fileSizeString;
}
use of java.text.DecimalFormat in project h2o-2 by h2oai.
the class MapReduceKMeans method execImpl.
@Override
protected void execImpl() {
// Load and parse a file. Data is distributed to other nodes in a round-robin way
Key file = NFSFileVec.make(new File("../lib/resources/datasets/gaussian.csv"));
Frame frame = ParseDataset2.parse(Key.make("test"), new Key[] { file });
// Optionally create a frame with less columns, e.g. skip first
frame = new Frame(Utils.remove(frame._names, 0), Utils.remove(frame.vecs(), 0));
// Create k clusters as arrays of doubles
int k = 7;
double[][] clusters = new double[k][frame.vecs().length];
// Initialize first cluster to random row
Random rand = new Random();
for (int cluster = 0; cluster < clusters.length; cluster++) {
long row = Math.max(0, (long) (rand.nextDouble() * frame.vecs().length) - 1);
for (int i = 0; i < frame.vecs().length; i++) {
Vec v = frame.vecs()[i];
clusters[cluster][i] = v.at(row);
}
}
// Iterate over the dataset and show error for each step
for (int i = 0; i < 10; i++) {
KMeans task = new KMeans();
task.clusters = clusters;
task.doAll(frame);
for (int c = 0; c < clusters.length; c++) {
if (task.counts[c] > 0) {
for (int v = 0; v < frame.vecs().length; v++) {
double value = task.sums[c][v] / task.counts[c];
clusters[c][v] = value;
}
}
}
System.out.println("Error is " + task.error);
}
System.out.println("Clusters:");
DecimalFormat df = new DecimalFormat("#.00");
for (int c = 0; c < clusters.length; c++) {
for (int v = 0; v < frame.vecs().length; v++) System.out.print(df.format(clusters[c][v]) + ", ");
System.out.println("");
}
}
use of java.text.DecimalFormat in project h2o-3 by h2oai.
the class KMeansDroplet method main.
public static void main(String[] args) throws Exception {
initCloud();
// Load and parse a file. Data is distributed to other nodes in a round-robin way
File f = new File("smalldata/glm_test/gaussian.csv");
NFSFileVec nfs = NFSFileVec.make(f);
Frame frame = water.parser.ParseDataset.parse(Key.make(), nfs._key);
// Optionally create a frame with fewer columns, e.g. skip first
frame.remove(0);
// Create k centers as arrays of doubles
int k = 7;
double[][] centers = new double[k][frame.vecs().length];
// Initialize first cluster center to random row
Random rand = new Random();
for (int cluster = 0; cluster < centers.length; cluster++) {
long row = Math.max(0, (long) (rand.nextDouble() * frame.vecs().length) - 1);
for (int i = 0; i < frame.vecs().length; i++) {
Vec v = frame.vecs()[i];
centers[cluster][i] = v.at(row);
}
}
// Iterate over the dataset and show error for each step
int NUM_ITERS = 10;
for (int i = 0; i < NUM_ITERS; i++) {
KMeans task = new KMeans();
task._centers = centers;
task.doAll(frame);
for (int c = 0; c < centers.length; c++) {
if (task._size[c] > 0) {
for (int v = 0; v < frame.vecs().length; v++) {
double value = task._sums[c][v] / task._size[c];
centers[c][v] = value;
}
}
}
System.out.println("Error is " + task._error);
}
System.out.println("Cluster Centers:");
DecimalFormat df = new DecimalFormat("#.00");
for (double[] center : centers) {
for (int v = 0; v < frame.vecs().length; v++) System.out.print(df.format(center[v]) + ", ");
System.out.println("");
}
System.exit(0);
}
Aggregations