public class NaturalLogUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static double |
LOG_ONE_HALF |
static double |
LOG_ONE_THIRD |
Modifier and Type | Method and Description |
---|---|
static double |
log1mexp(double a)
Calculates
log(1-exp(a)) without losing precision. |
static double |
logSumExp(double... logValues)
Computes $\log(\sum_i e^{a_i})$ trying to avoid underflow issues by using the log-sum-exp trick.
|
static double |
logSumLog(double a,
double b) |
static double[] |
normalizeFromLogToLinearSpace(double[] array)
normalizes the log-probability array in-place.
|
static double[] |
normalizeLog(double[] array)
normalizes the log-probability array in-place.
|
static double[] |
normalizeLog(double[] array,
boolean takeLogOfOutput,
boolean inPlace)
See #normalizeFromLog but with the additional option to use an approximation that keeps the calculation always in log-space
|
static double[] |
posteriors(double[] logPriors,
double[] logLikelihoods) |
static double |
qualToLogErrorProb(byte qual)
Convert a phred-scaled quality score to its log10 probability of being wrong (Q30 => log(0.001))
WARNING -- because this function takes a byte for maxQual, you must be careful in converting
integers to byte.
|
static double |
qualToLogErrorProb(double qual)
Convert a phred-scaled quality score to its log10 probability of being wrong (Q30 => log10(0.001))
This is the Phred-style conversion, *not* the Illumina-style conversion.
|
static double |
qualToLogProb(byte qual) |
public static final double LOG_ONE_HALF
public static final double LOG_ONE_THIRD
public static double[] normalizeFromLogToLinearSpace(double[] array)
array
- the array to be normalizedpublic static double[] normalizeLog(double[] array)
array
- the array to be normalizedpublic static double[] normalizeLog(double[] array, boolean takeLogOfOutput, boolean inPlace)
array
- takeLogOfOutput
- inPlace
- if true, modify the input array in-placepublic static double logSumExp(double... logValues)
This trick consists of shifting all the log values by the maximum so that exponent values are much larger (close to 1) before they are summed. Then the result is shifted back down by the same amount in order to obtain the correct value.
public static double log1mexp(double a)
log(1-exp(a))
without losing precision.
This is based on the approach described in:
Maechler M, Accurately Computing log(1-exp(-|a|)) Assessed by the Rmpfr package, 2012
Online document.
a
- the input exponent.NaN
if a > 0
, otherwise the corresponding value.public static double[] posteriors(double[] logPriors, double[] logLikelihoods)
public static double qualToLogErrorProb(byte qual)
qual
- a phred-scaled quality score encoded as a bytepublic static double qualToLogErrorProb(double qual)
qual
- a phred-scaled quality score encoded as a doublepublic static double qualToLogProb(byte qual)
public static double logSumLog(double a, double b)