Search in sources :

Example 86 with DecimalFormat

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;
}
Also used : Path(org.apache.hadoop.fs.Path) ArrayListWritable(tl.lin.data.array.ArrayListWritable) SequenceFile(org.apache.hadoop.io.SequenceFile) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) IntWritable(org.apache.hadoop.io.IntWritable)

Example 87 with DecimalFormat

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;
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 88 with DecimalFormat

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;
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 89 with DecimalFormat

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("");
    }
}
Also used : Random(java.util.Random) DecimalFormat(java.text.DecimalFormat) File(java.io.File) Key(water.Key)

Example 90 with DecimalFormat

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);
}
Also used : Frame(water.fvec.Frame) Random(java.util.Random) Vec(water.fvec.Vec) NFSFileVec(water.fvec.NFSFileVec) NFSFileVec(water.fvec.NFSFileVec) DecimalFormat(java.text.DecimalFormat) File(java.io.File)

Aggregations

DecimalFormat (java.text.DecimalFormat)823 DecimalFormatSymbols (java.text.DecimalFormatSymbols)94 NumberFormat (java.text.NumberFormat)93 IOException (java.io.IOException)48 BigDecimal (java.math.BigDecimal)47 ArrayList (java.util.ArrayList)44 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)33 ParseException (java.text.ParseException)31 Test (org.junit.Test)31 File (java.io.File)29 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 Support_DecimalFormat (tests.support.Support_DecimalFormat)28 Date (java.util.Date)25 SimpleDateFormat (java.text.SimpleDateFormat)24 HashMap (java.util.HashMap)24 Locale (java.util.Locale)22 PrintWriter (java.io.PrintWriter)20 UsageVO (com.cloud.usage.UsageVO)19 List (java.util.List)18 JFreeChart (org.jfree.chart.JFreeChart)18