Example usage for java.lang Math log10

List of usage examples for java.lang Math log10

Introduction

In this page you can find the example usage for java.lang Math log10.

Prototype

@HotSpotIntrinsicCandidate
public static double log10(double a) 

Source Link

Document

Returns the base 10 logarithm of a double value.

Usage

From source file:org.dkpro.similarity.experiments.sts2013.util.CharacterNGramIdfValuesGenerator.java

@SuppressWarnings("unchecked")
public static void computeIdfScores(Mode mode, Dataset dataset, int n) throws Exception {
    URL inputUrl = ResourceUtils.resolveLocation(
            DATASET_DIR + "/" + mode.toString().toLowerCase() + "/STS.input." + dataset.toString() + ".txt");
    List<String> lines = IOUtils.readLines(inputUrl.openStream(), "utf-8");

    System.out.println("Computing character " + n + "-grams");

    File outputFile = new File(UTILS_DIR + "/character-ngrams-idf/" + mode.toString().toLowerCase() + "/" + n
            + "/" + dataset.toString() + ".txt");

    if (outputFile.exists()) {
        System.out.println(" - skipping, already exists");
    } else {/*from w ww . jav  a  2 s . c om*/
        Map<String, Double> idfValues = new HashMap<String, Double>();

        CharacterNGramMeasure measure = new CharacterNGramMeasure(n, new HashMap<String, Double>());

        // Get n-gram representations of texts
        List<Set<String>> docs = new ArrayList<Set<String>>();

        for (String line : lines) {
            Set<String> ngrams = measure.getNGrams(line);

            docs.add(ngrams);
        }

        // Get all ngrams
        Set<String> allNGrams = new HashSet<String>();
        for (Set<String> doc : docs)
            allNGrams.addAll(doc);

        // Compute idf values         
        for (String ngram : allNGrams) {
            double count = 0;
            for (Set<String> doc : docs) {
                if (doc.contains(ngram))
                    count++;
            }
            idfValues.put(ngram, count);
        }

        // Compute the idf
        for (String lemma : idfValues.keySet()) {
            double idf = Math.log10(lines.size() / idfValues.get(lemma));
            idfValues.put(lemma, idf);
        }

        // Store persistently
        StringBuilder sb = new StringBuilder();
        for (String key : idfValues.keySet()) {
            sb.append(key + "\t" + idfValues.get(key) + LF);
        }
        FileUtils.writeStringToFile(outputFile, sb.toString());

        System.out.println(" - done");
    }
}

From source file:org.dkpro.similarity.experiments.sts2013baseline.util.CharacterNGramIdfValuesGenerator.java

public static void computeIdfScores(Mode mode, Dataset dataset, int n) throws Exception {
    URL inputUrl = ResourceUtils.resolveLocation(
            DATASET_DIR + "/" + mode.toString().toLowerCase() + "/STS.input." + dataset.toString() + ".txt");
    List<String> lines = IOUtils.readLines(inputUrl.openStream(), "utf-8");

    System.out.println("Computing character " + n + "-grams");

    File outputFile = new File(UTILS_DIR + "/character-ngrams-idf/" + mode.toString().toLowerCase() + "/" + n
            + "/" + dataset.toString() + ".txt");

    if (outputFile.exists()) {
        System.out.println(" - skipping, already exists");
    } else {/*w  ww.j a  va  2 s .  c om*/
        Map<String, Double> idfValues = new HashMap<String, Double>();

        CharacterNGramMeasure measure = new CharacterNGramMeasure(n, new HashMap<String, Double>());

        // Get n-gram representations of texts
        List<Set<String>> docs = new ArrayList<Set<String>>();

        for (String line : lines) {
            Set<String> ngrams = measure.getNGrams(line);

            docs.add(ngrams);
        }

        // Get all ngrams
        Set<String> allNGrams = new HashSet<String>();
        for (Set<String> doc : docs) {
            allNGrams.addAll(doc);
        }

        // Compute idf values         
        for (String ngram : allNGrams) {
            double count = 0;
            for (Set<String> doc : docs) {
                if (doc.contains(ngram)) {
                    count++;
                }
            }
            idfValues.put(ngram, count);
        }

        // Compute the idf
        for (String lemma : idfValues.keySet()) {
            double idf = Math.log10(lines.size() / idfValues.get(lemma));
            idfValues.put(lemma, idf);
        }

        // Store persistently
        StringBuilder sb = new StringBuilder();
        for (String key : idfValues.keySet()) {
            sb.append(key + "\t" + idfValues.get(key) + LF);
        }
        FileUtils.writeStringToFile(outputFile, sb.toString());

        System.out.println(" - done");
    }
}

From source file:com.edduarte.argus.util.Constants.java

public static String fileSizeToString(long size) {
    if (size <= 0) {
        return "0 kb";
    }//from w  ww  . j  av a 2  s  .c  om

    final String[] units = new String[] { "bytes", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
    return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}

From source file:libra.preprocess.stage2.KmerIndexBuilderReducer.java

@Override
protected void reduce(CompressedSequenceWritable key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
    int frequency = 0;

    for (IntWritable value : values) {
        frequency += value.get();//from  ww w .ja  va 2 s  .co  m
    }

    // compute base
    if (frequency > 0) {
        this.logTFSquareCounter.increment((long) (Math.pow(1 + Math.log10(frequency), 2) * 1000));
    }
    context.write(key, new IntWritable(frequency));
}

From source file:com.bmwcarit.barefoot.markov.StateTest.java

@Test
public void TestState() {
    Map<Integer, MockElem> elements = new HashMap<>();
    elements.put(0, new MockElem(0, Math.log10(0.3), 0.3, null));
    elements.put(1, new MockElem(1, Math.log10(0.2), 0.2, null));
    elements.put(2, new MockElem(2, Math.log10(0.5), 0.5, null));

    StateMemory<MockElem, StateTransition, Sample> state = new StateMemory<>();
    {/*w  w w.  ja va2 s. c  o m*/
        Set<MockElem> vector = new HashSet<>(Arrays.asList(elements.get(0), elements.get(1), elements.get(2)));

        state.update(vector, new Sample(0));

        assertEquals(3, state.size());
        assertEquals(2, state.estimate().numid());
    }

    elements.put(3, new MockElem(3, Math.log10(0.3), 0.3, elements.get(1)));
    elements.put(4, new MockElem(4, Math.log10(0.2), 0.2, elements.get(1)));
    elements.put(5, new MockElem(5, Math.log10(0.4), 0.4, elements.get(2)));
    elements.put(6, new MockElem(6, Math.log10(0.1), 0.1, elements.get(2)));

    {
        Set<MockElem> vector = new HashSet<>(
                Arrays.asList(elements.get(3), elements.get(4), elements.get(5), elements.get(6)));

        state.update(vector, new Sample(1));

        assertEquals(4, state.size());
        assertEquals(5, state.estimate().numid());
    }

    elements.put(7, new MockElem(7, Math.log10(0.3), 0.3, elements.get(5)));
    elements.put(8, new MockElem(8, Math.log10(0.2), 0.2, elements.get(5)));
    elements.put(9, new MockElem(9, Math.log10(0.4), 0.4, elements.get(6)));
    elements.put(10, new MockElem(10, Math.log10(0.1), 0.1, elements.get(6)));

    {
        Set<MockElem> vector = new HashSet<>(
                Arrays.asList(elements.get(7), elements.get(8), elements.get(9), elements.get(10)));

        state.update(vector, new Sample(2));

        assertEquals(4, state.size());
        assertEquals(9, state.estimate().numid());
    }

    elements.put(11, new MockElem(11, Math.log10(0.3), 0.3, null));
    elements.put(12, new MockElem(12, Math.log10(0.2), 0.2, null));
    elements.put(13, new MockElem(13, Math.log10(0.4), 0.4, null));
    elements.put(14, new MockElem(14, Math.log10(0.1), 0.1, null));

    {
        Set<MockElem> vector = new HashSet<>(
                Arrays.asList(elements.get(11), elements.get(12), elements.get(13), elements.get(14)));

        state.update(vector, new Sample(3));

        assertEquals(4, state.size());
        assertEquals(13, state.estimate().numid());
    }
    {
        Set<MockElem> vector = new HashSet<>();

        state.update(vector, new Sample(4));

        assertEquals(4, state.size());
        assertEquals(13, state.estimate().numid());
    }
}

From source file:org.geowebcache.storage.blobstore.file.FilePathGenerator.java

/**
 * Builds the storage path for a tile and returns it as a File reference
 * <p>//  ww w  .j  av  a 2 s.co  m
 * </p>
 * 
 * @param layerName
 *            name of the layer the tile belongs to
 * @param tileIndex
 *            the [x,y,z] index for the tile
 * @param gridSetId
 *            the name of the gridset for the tile inside layer
 * @param mimeType
 *            the storage mime type
 * @param parameters_id
 *            the parameters identifier
 * @return File pointer to the tile image
 */
public File tilePath(TileObject tile, MimeType mimeType) {
    final long[] tileIndex = tile.getXYZ();
    long x = tileIndex[0];
    long y = tileIndex[1];
    long z = tileIndex[2];

    StringBuilder path = new StringBuilder(256);

    long shift = z / 2;
    long half = 2 << shift;
    int digits = 1;
    if (half > 10) {
        digits = (int) (Math.log10(half)) + 1;
    }
    long halfx = x / half;
    long halfy = y / half;

    String fileExtension = mimeType.getFileExtension();

    path.append(cacheRoot);
    path.append(File.separatorChar);
    appendFiltered(tile.getLayerName(), path);
    path.append(File.separatorChar);
    appendGridsetZoomLevelDir(tile.getGridSetId(), z, path);
    String parametersId = tile.getParametersId();
    Map<String, String> parameters = tile.getParameters();
    if (parametersId == null && parameters != null && !parameters.isEmpty()) {
        parametersId = getParametersId(parameters);
        tile.setParametersId(parametersId);
    }
    if (parametersId != null) {
        path.append('_');
        path.append(parametersId);
    }
    path.append(File.separatorChar);
    zeroPadder(halfx, digits, path);
    path.append('_');
    zeroPadder(halfy, digits, path);
    path.append(File.separatorChar);

    zeroPadder(x, 2 * digits, path);
    path.append('_');
    zeroPadder(y, 2 * digits, path);
    path.append('.');
    path.append(fileExtension);

    File tileFile = new File(path.toString());
    return tileFile;
}

From source file:graph_line.java

public void drawfft(double[] data) {
    if (!fftseries.isEmpty())
        fftseries.clear();/* www  .  j  a va2 s . c o  m*/

    for (int i = 0; i < data.length; i++) {
        fftseries.add(i, 10 * Math.log10(data[i]));
    }

    if (_active == 0)
        showGraph();

}

From source file:at.tuwien.ifs.commons.util.MathUtils.java

public static int numberOfDigits(int i) {
    return 1 + (int) Math.log10(Math.abs(i));
}

From source file:edu.upf.bioevo.manhattanPlotter.QQPlot.java

void setExperiment(Experiment experiment) {
    this.experiment = experiment;

    // Creates ordered array with log10 observed values
    orderedLog10ObservedValues = new double[experiment.tests.length];
    for (int i = 0; i < experiment.tests.length; i++) {
        orderedLog10ObservedValues[i] = experiment.tests[i].logPValue;
    }/*from  w ww.  j  av  a  2 s  .  c  om*/
    Arrays.sort(orderedLog10ObservedValues);
    maxObservedLogValue = orderedLog10ObservedValues[orderedLog10ObservedValues.length - 1];

    // Creates ordered array with log10 exepected values
    orderedLog10ExpectedValues = new double[experiment.tests.length];
    for (int i = experiment.tests.length; i > 0; i--) {
        orderedLog10ExpectedValues[experiment.tests.length - i] = -Math
                .log10((double) i / (experiment.tests.length + 1));
    }
    maxExpectedLogValue = orderedLog10ExpectedValues[orderedLog10ExpectedValues.length - 1];

    // Creates CI95 upper and lower values
    if (ic95Option) {
        lowerCI = new double[experiment.tests.length];
        upperCI = new double[experiment.tests.length];

        for (int i = experiment.tests.length - 1; i >= 0; i--) {
            BetaDistribution beta = new BetaDistribution(i + 1, experiment.tests.length - i);
            lowerCI[i] = -Math.log10(beta.inverseCumulativeProbability(0.025));
            upperCI[i] = -Math.log10(beta.inverseCumulativeProbability(0.975));
        }
        Arrays.sort(lowerCI);
        Arrays.sort(upperCI);
    }

}

From source file:org.zkoss.ganttz.DatesMapperOnInterval.java

private int toPixels(Fraction proportion) {
    try {/*  w w  w  .ja v a  2 s. c o  m*/
        return proportion.multiplyBy(Fraction.getFraction(horizontalSize, 1)).intValue();
    } catch (ArithmeticException e) {
        double d = Math.log10(horizontalSize);
        int scale = (int) d + 1;

        BigDecimal quotient = new BigDecimal(proportion.getNumerator())
                .divide(new BigDecimal(proportion.getDenominator()), scale, RoundingMode.HALF_UP);

        return quotient.multiply(new BigDecimal(horizontalSize)).intValue();
    }
}