Package picard.util
Class MathUtil
- java.lang.Object
-
- picard.util.MathUtil
-
public final class MathUtil extends Object
General math utilities
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMathUtil.LogMathA collection of common math operations that work with log values.
-
Field Summary
Fields Modifier and Type Field Description static MathUtil.LogMathLOG_10_MATHstatic MathUtil.LogMathLOG_2_MATHstatic doubleLOG_4_BASE_EConstant to convert between the natural base e and 4.0.static doubleMAX_PROB_BELOW_ONEThe double value closest to 1 while still being less than 1.static MathUtil.LogMathNATURAL_LOG_MATH
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intcompare(int v1, int v2)static double[]divide(double[] numerators, double[] denominators)Calculates the ratio of two arrays of the same length.static doubledivide(double numerator, double denominator)Divide two Doubles but return 0.0 if the denominator is 0static intindexOfMax(double[] nums)Returns the index of the largest element in the array.static intindexOfMax(long[] nums)Returns the index of the largest element in the array.static intindexOfMin(double[] nums)Returns the index of the smallest element in the array.static intindexOfMin(int[] nums)Returns the index of the smallest element in the array.static doublelog10_1p(double x)this function mimics the behavior of log_1p but resulting in log _base 10_ of (1+x) instead of natural log of 1+xstatic double[]logLikelihoodsToProbs(double[] likelihoods)Deprecated.static doublemax(double[] nums)Returns the largest value stored in the array.static longmax(long[] nums)Returns the largest value stored in the array.static doublemean(double[] in, int start, int stop)Calculated the mean of an array of doubles.static doublemedian(double... in)Calculate the median of an array of doubles.static bytemin(byte[] nums)Returns the smallest value stored in the array.static doublemin(double[] nums)Returns the smallest value stored in the array.static intmin(int[] nums)Returns the smallest value stored in the array.static shortmin(short[] nums)Returns the smallest value stored in the array.static double[]multiply(double[] lhs, double[] rhs)Calculates the product of two arrays of the same length.static DoublepercentageOrNull(Long numerator, Long denominator)Obtains percentage of two Longsstatic double[]pNormalizeLogProbability(double[] lPosterior)Takes a complete set of mutually exclusive logPosteriors and converts them to probabilities that sum to 1 with as much fidelity as possible.static double[]pNormalizeVector(double[] pPosterior)Takes a vector of numbers and converts it to a vector of probabilities that sum to 1 with as much fidelity as possible.static double[]promote(int[] is)"Promotes" an int[] into a double array with the same values (or as close as precision allows).static doubleround(double num, int precision)Round off the value to the specified precision.static double[]seq(double from, double to, double by)Mimic's R's seq() function to produce a sequence of equally spaced numbers.static doublestddev(double[] in, int start, int length)Calculated the standard deviation of an array of doubles.static doublestddev(double[] in, int start, int stop, double mean)Calculated the standard deviation of an array of doubles.static doublesum(double[] arr)Returns the sum of the elements in the array.static double[]sum(double[] lhs, double[] rhs)calculates the sum of the arrays as a third array.static longsum(long[] arr, int start, int stop)Returns the sum of the elements in the array starting with start and ending before stop.
-
-
-
Field Detail
-
MAX_PROB_BELOW_ONE
public static final double MAX_PROB_BELOW_ONE
The double value closest to 1 while still being less than 1.- See Also:
- Constant Field Values
-
LOG_4_BASE_E
public static final double LOG_4_BASE_E
Constant to convert between the natural base e and 4.0. Useful for entropy calculations on DNA.
-
LOG_2_MATH
public static final MathUtil.LogMath LOG_2_MATH
-
NATURAL_LOG_MATH
public static final MathUtil.LogMath NATURAL_LOG_MATH
-
LOG_10_MATH
public static final MathUtil.LogMath LOG_10_MATH
-
-
Method Detail
-
log10_1p
public static double log10_1p(double x)
this function mimics the behavior of log_1p but resulting in log _base 10_ of (1+x) instead of natural log of 1+x
-
mean
public static double mean(double[] in, int start, int stop)Calculated the mean of an array of doubles.
-
stddev
public static double stddev(double[] in, int start, int length)Calculated the standard deviation of an array of doubles.
-
stddev
public static double stddev(double[] in, int start, int stop, double mean)Calculated the standard deviation of an array of doubles.
-
compare
public static int compare(int v1, int v2)
-
median
public static double median(double... in)
Calculate the median of an array of doubles. Assumes that the input is sorted
-
percentageOrNull
public static Double percentageOrNull(Long numerator, Long denominator)
Obtains percentage of two Longs- Parameters:
numerator- dividenddenominator- divisor- Returns:
- numerator/(double)denominator if both are non-null and denominator != 0, else returns null.
-
round
public static double round(double num, int precision)Round off the value to the specified precision.
-
divide
public static double divide(double numerator, double denominator)Divide two Doubles but return 0.0 if the denominator is 0- Parameters:
numerator- dividenddenominator- divisor- Returns:
- numerator/denominator unless denominator is 0, in which case returns 0
-
max
public static double max(double[] nums)
Returns the largest value stored in the array.
-
indexOfMax
public static int indexOfMax(double[] nums)
Returns the index of the largest element in the array. If there are multiple equal maxima then the earliest one in the array is returned.
-
max
public static long max(long[] nums)
Returns the largest value stored in the array.
-
indexOfMax
public static int indexOfMax(long[] nums)
Returns the index of the largest element in the array. If there are multiple equal maxima then the earliest one in the array is returned.
-
min
public static double min(double[] nums)
Returns the smallest value stored in the array.
-
min
public static int min(int[] nums)
Returns the smallest value stored in the array.
-
min
public static short min(short[] nums)
Returns the smallest value stored in the array.
-
min
public static byte min(byte[] nums)
Returns the smallest value stored in the array.
-
indexOfMin
public static int indexOfMin(int[] nums)
Returns the index of the smallest element in the array. If there are multiple equal minima then the earliest one in the array is returned.
-
indexOfMin
public static int indexOfMin(double[] nums)
Returns the index of the smallest element in the array. If there are multiple equal minima then the earliest one in the array is returned.
-
seq
public static double[] seq(double from, double to, double by)Mimic's R's seq() function to produce a sequence of equally spaced numbers.
-
promote
public static double[] promote(int[] is)
"Promotes" an int[] into a double array with the same values (or as close as precision allows).
-
logLikelihoodsToProbs
@Deprecated public static double[] logLikelihoodsToProbs(double[] likelihoods)
Deprecated.
-
pNormalizeLogProbability
public static double[] pNormalizeLogProbability(double[] lPosterior)
Takes a complete set of mutually exclusive logPosteriors and converts them to probabilities that sum to 1 with as much fidelity as possible. Limits probabilities to be in the space: 0.9999999999999999 >= p >= (1-0.9999999999999999)/(lPosteriors.length-1)
-
divide
public static double[] divide(double[] numerators, double[] denominators)Calculates the ratio of two arrays of the same length.
-
pNormalizeVector
public static double[] pNormalizeVector(double[] pPosterior)
Takes a vector of numbers and converts it to a vector of probabilities that sum to 1 with as much fidelity as possible. Limits probabilities to be in the space: 0.9999999999999999 >= p >= (1-0.9999999999999999)/(likelihoods.length-1)
-
multiply
public static double[] multiply(double[] lhs, double[] rhs)Calculates the product of two arrays of the same length.
-
sum
public static double[] sum(double[] lhs, double[] rhs)calculates the sum of the arrays as a third array.
-
sum
public static double sum(double[] arr)
Returns the sum of the elements in the array.
-
sum
public static long sum(long[] arr, int start, int stop)Returns the sum of the elements in the array starting with start and ending before stop.
-
-