Get Hoeffding probability number - Java java.lang

Java examples for java.lang:Math Number

Description

Get Hoeffding probability number

Demo Code

/*/*from   www  .  j av  a2  s.  c  o m*/
 * Copyright (c) 2014. Real Time Genomics Limited.
 *
 * Use of this source code is bound by the Real Time Genomics Limited Software Licence Agreement
 * for Academic Non-commercial Research Purposes only.
 *
 * If you did not receive a license accompanying this file, a copy must first be obtained by email
 * from support@realtimegenomics.com.  On downloading, using and/or continuing to use this source
 * code you accept the terms of that license agreement and any amendments to those terms that may
 * be made from time to time by Real Time Genomics Limited.
 */
//package com.java2s;

public class Main {
    private static final double LOG10_E = Math.log10(Math.E);

    /**
     * Get Hoeffding probability number
     * @param trials the number of trials measured
     * @param observed the observed number of trials matching the condition
     * @param prob the expected probability of a trial matching the condition
     * @return the Hoeffding probability, or null if there are zero trials
     */
    public static Double hoeffdingPhred(int trials, int observed,
            double prob) {
        if (trials == 0) {
            return null;
        }
        final double hoeffding = -2 * Math.pow(trials * prob - observed, 2)
                / trials;
        return lnToPhred(hoeffding);
    }

    /**
     * turn a log probability into <code>Phred</code> score
     * @param val value to convert
     * @return the result
     */
    public static double lnToPhred(double val) {
        return -10 * LOG10_E * val;
    }
}

Related Tutorials