Example usage for com.google.common.math DoubleMath log2

List of usage examples for com.google.common.math DoubleMath log2

Introduction

In this page you can find the example usage for com.google.common.math DoubleMath log2.

Prototype

public static double log2(double x) 

Source Link

Document

Returns the base 2 logarithm of a double value.

Usage

From source file:com.github.steveash.jg2p.align.AlignerInferencer.java

public List<Alignment> bestGraphemes(Word x, int bestPathCount) {
    PathXTable t = new PathXTable(x.unigramCount() + 1, bestPathCount);
    t.offer(0, t.make(0, -1, -1));/*from   w w  w .ja v a 2s . c  o  m*/

    for (int xx = 1; xx < x.unigramCount() + 1; xx++) {
        for (int i = 1; (i <= opts.getMaxXGram()) && (xx - i >= 0); i++) {
            String xGram = x.gram(xx - i, i);
            double margX = margs.probX(xGram);

            double score = DoubleMath.log2(margX) * i;
            t.extendPath(xx, xx - i, PathXTable.Entry.sample(score, i));
        }
    }

    return createAlignments(x, t, bestPathCount);
}

From source file:com.github.steveash.jg2p.align.AlignerViterbi.java

public List<Alignment> align(Word x, Word y, int bestPathCount) {
    PathXYTable t = new PathXYTable(x.unigramCount() + 1, y.unigramCount() + 1, bestPathCount);
    t.offer(0, 0, t.make(0, -1, -1, -1));

    for (int xx = 0; xx < x.unigramCount() + 1; xx++) {
        for (int yy = 0; yy < y.unigramCount() + 1; yy++) {

            if (xx > 0 && opts.isIncludeXEpsilons()) {
                for (int i = 1; (i <= opts.getMaxXGram()) && (xx - i >= 0); i++) {
                    String xGram = x.gram(xx - i, i);
                    double score = DoubleMath.log2(probs.prob(xGram, Grams.EPSILON)) * i;
                    t.extendPath(xx, yy, xx - i, yy, PathXYTable.Entry.sample(score, i, 0));
                }/*from w w w.ja v  a2  s.  c  om*/
            }

            if (yy > 0 && opts.isIncludeEpsilonYs()) {
                for (int j = 1; (j <= opts.getMaxYGram()) && (yy - j >= 0); j++) {
                    String yGram = y.gram(yy - j, j);
                    double score = DoubleMath.log2(probs.prob(Grams.EPSILON, yGram)) * j;
                    t.extendPath(xx, yy, xx, yy - j, PathXYTable.Entry.sample(score, 0, j));
                }
            }

            if (xx > 0 && yy > 0) {
                for (int i = 1; (i <= opts.getMaxXGram()) && (xx - i >= 0); i++) {
                    for (int j = 1; (j <= opts.getMaxYGram()) && (yy - j >= 0); j++) {
                        String xGram = x.gram(xx - i, i);
                        String yGram = y.gram(yy - j, j);

                        double score = DoubleMath.log2(probs.prob(xGram, yGram)) * Math.max(i, j);
                        t.extendPath(xx, yy, xx - i, yy - j, PathXYTable.Entry.sample(score, i, j));
                    }
                }
            }
        }
    }

    return createAlignments(x, y, t, bestPathCount);
}

From source file:com.github.mgunlogson.cuckoofilter4j.Utils.java

/**
 * Calculates how many bits are needed to reach a given false positive rate.
 * //from  w ww .jav a2  s.  c om
 * @param fpProb
 *            the false positive probability.
 * @return the length of the tag needed (in bits) to reach the false
 *         positive rate.
 */
static int getBitsPerItemForFpRate(double fpProb, double loadFactor) {
    /*
     * equation from Cuckoo Filter: Practically Better Than Bloom Bin Fan,
     * David G. Andersen, Michael Kaminsky , Michael D. Mitzenmacher
     */
    return DoubleMath.roundToInt(DoubleMath.log2((1 / fpProb) + 3) / loadFactor, RoundingMode.UP);
}

From source file:com.github.gdfm.shobaidogu.StatsUtils.java

/**
 * Compute Discount Cumulative Gain for a relevance vector.
 * // w w w. ja  v  a 2s .c  om
 * @param relevance
 *          the vector or relevance values.
 * @return DCG.
 */
public static double[] computeDCG(double[] relevance) {
    checkNotNull(relevance);
    checkArgument(relevance.length > 0);
    double[] dcg = Arrays.copyOf(relevance, relevance.length);
    for (int i = 1; i < dcg.length; i++)
        dcg[i] = dcg[i - 1] + dcg[i] / DoubleMath.log2(i + 1);
    return dcg;
}