cc.mallet.util
Class Maths
- java.lang.Object
-
- cc.mallet.util.Maths
-
public final class Maths extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleEPSILONNumbers that are closer than this are considered equal by almostEquals.static doublelog2
-
Constructor Summary
Constructors Constructor and Description Maths()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static booleanalmostEquals(double[] d1, double[] d2, double eps)static booleanalmostEquals(double d1, double d2)static booleanalmostEquals(double d1, double d2, double epsilon)static doublebeta(double a, double b)static booleancheckWithinRange(double value, double min, double max)Checks if min <= value <= max.static doublecosh(double a)static doublefactorial(int n)static doublegamma(double x)static doublegetEntropy(double[] dist)static doublejensenShannonDivergence(double[] p1, double[] p2)Returns the Jensen-Shannon divergence.static doubleklDivergence(double[] p1, double[] p2)Returns the KL divergence, K(p1 || p2).static doublelogBeta(double a, double b)static doublelogBinom(int x, int n, double p)Computes p(x;n,p) where x~B(n,p)static doublelogFactorial(int n)static doublelogGamma(double x)static doublelogit(double p)static doublenumCombinations(int n, int r)static doublenumPermutations(int n, int r)static doubleoldLogGamma(double x)static doublepbinom(int x, int n, double p)Vastly inefficient O(x) method to compute cdf of B(n,p)static doublesigmod_rev(double sig)static doublesigmod(double beta)static doublesubtractLogProb(double a, double b)Returns the difference of two doubles expressed in log space, that is,static doublesumLogProb(double[] vals)Sums an array of numbers log(x1)...log(xn).static doublesumLogProb(double a, double b)Returns the sum of two doubles expressed in log space, that is,static doubletanh(double a)
-
-
-
Field Detail
-
EPSILON
public static double EPSILON
Numbers that are closer than this are considered equal by almostEquals.
-
log2
public static final double log2
-
-
Method Detail
-
logGamma
public static final double logGamma(double x)
-
oldLogGamma
public static double oldLogGamma(double x)
-
logBeta
public static double logBeta(double a, double b)
-
beta
public static double beta(double a, double b)
-
gamma
public static double gamma(double x)
-
factorial
public static double factorial(int n)
-
logFactorial
public static double logFactorial(int n)
-
logBinom
public static double logBinom(int x, int n, double p)Computes p(x;n,p) where x~B(n,p)
-
pbinom
public static double pbinom(int x, int n, double p)Vastly inefficient O(x) method to compute cdf of B(n,p)
-
sigmod
public static double sigmod(double beta)
-
sigmod_rev
public static double sigmod_rev(double sig)
-
logit
public static double logit(double p)
-
numCombinations
public static double numCombinations(int n, int r)
-
numPermutations
public static double numPermutations(int n, int r)
-
cosh
public static double cosh(double a)
-
tanh
public static double tanh(double a)
-
almostEquals
public static boolean almostEquals(double d1, double d2)
-
almostEquals
public static boolean almostEquals(double d1, double d2, double epsilon)
-
almostEquals
public static boolean almostEquals(double[] d1, double[] d2, double eps)
-
checkWithinRange
public static boolean checkWithinRange(double value, double min, double max)Checks if min <= value <= max.
-
klDivergence
public static double klDivergence(double[] p1, double[] p2)Returns the KL divergence, K(p1 || p2). The log is w.r.t. base 2.*Note*: If any value in p2 is 0.0 then the KL-divergence is infinite.
-
jensenShannonDivergence
public static double jensenShannonDivergence(double[] p1, double[] p2)Returns the Jensen-Shannon divergence.
-
sumLogProb
public static double sumLogProb(double a, double b)Returns the sum of two doubles expressed in log space, that is,sumLogProb = log (e^a + e^b) = log e^a(1 + e^(b-a)) = a + log (1 + e^(b-a))By exponentiating b-a, we obtain better numerical precision than we would if we calculated e^a or e^b directly.Note: This function is just like
sumNegLogProbin Transducer, except that the logs aren't negated.
-
sumLogProb
public static double sumLogProb(double[] vals)
Sums an array of numbers log(x1)...log(xn). This saves some of the unnecessary calls to Math.log in the two-argument version.Note that this implementation IGNORES elements of the input array that are more than LOGTOLERANCE (currently 30.0) less than the maximum element.
Cursory testing makes me wonder if this is actually much faster than repeated use of the 2-argument version, however -cas.
- Parameters:
vals- An array log(x1), log(x2), ..., log(xn)- Returns:
- log(x1+x2+...+xn)
-
subtractLogProb
public static double subtractLogProb(double a, double b)Returns the difference of two doubles expressed in log space, that is,sumLogProb = log (e^a - e^b) = log e^a(1 - e^(b-a)) = a + log (1 - e^(b-a))By exponentiating b-a, we obtain better numerical precision than we would if we calculated e^a or e^b directly.Returns NaN if b > a (so that log(e^a - e^b) is undefined).
-
getEntropy
public static double getEntropy(double[] dist)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG