|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cc.mallet.util.Maths
public final class Maths
Field Summary | |
---|---|
static double |
EPSILON
Numbers that are closer than this are considered equal by almostEquals. |
static double |
log2
|
Constructor Summary | |
---|---|
Maths()
|
Method Summary | |
---|---|
static boolean |
almostEquals(double[] d1,
double[] d2,
double eps)
|
static boolean |
almostEquals(double d1,
double d2)
|
static boolean |
almostEquals(double d1,
double d2,
double epsilon)
|
static double |
beta(double a,
double b)
|
static boolean |
checkWithinRange(double value,
double min,
double max)
Checks if min <= value <= max. |
static double |
cosh(double a)
|
static double |
factorial(int n)
|
static double |
gamma(double x)
|
static double |
getEntropy(double[] dist)
|
static double |
jensenShannonDivergence(double[] p1,
double[] p2)
Returns the Jensen-Shannon divergence. |
static double |
klDivergence(double[] p1,
double[] p2)
Returns the KL divergence, K(p1 || p2). |
static double |
logBeta(double a,
double b)
|
static double |
logBinom(int x,
int n,
double p)
Computes p(x;n,p) where x~B(n,p) |
static double |
logFactorial(int n)
|
static double |
logGamma(double x)
|
static double |
logit(double p)
|
static double |
numCombinations(int n,
int r)
|
static double |
numPermutations(int n,
int r)
|
static double |
oldLogGamma(double x)
|
static double |
pbinom(int x,
int n,
double p)
Vastly inefficient O(x) method to compute cdf of B(n,p) |
static double |
sigmod_rev(double sig)
|
static double |
sigmod(double beta)
|
static double |
subtractLogProb(double a,
double b)
Returns the difference of two doubles expressed in log space, that is, |
static double |
sumLogProb(double[] vals)
Sums an array of numbers log(x1)...log(xn). |
static double |
sumLogProb(double a,
double b)
Returns the sum of two doubles expressed in log space, that is, |
static double |
tanh(double a)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static double EPSILON
public static final double log2
Constructor Detail |
---|
public Maths()
Method Detail |
---|
public static final double logGamma(double x)
public static double oldLogGamma(double x)
public static double logBeta(double a, double b)
public static double beta(double a, double b)
public static double gamma(double x)
public static double factorial(int n)
public static double logFactorial(int n)
public static double logBinom(int x, int n, double p)
public static double pbinom(int x, int n, double p)
public static double sigmod(double beta)
public static double sigmod_rev(double sig)
public static double logit(double p)
public static double numCombinations(int n, int r)
public static double numPermutations(int n, int r)
public static double cosh(double a)
public static double tanh(double a)
public static boolean almostEquals(double d1, double d2)
public static boolean almostEquals(double d1, double d2, double epsilon)
public static boolean almostEquals(double[] d1, double[] d2, double eps)
public static boolean checkWithinRange(double value, double min, double max)
public static double klDivergence(double[] p1, double[] p2)
*Note*: If any value in p2 is 0.0 then the KL-divergence is infinite.
public static double jensenShannonDivergence(double[] p1, double[] p2)
public static double sumLogProb(double a, double b)
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
sumNegLogProb
in Transducer,
except that the logs aren't negated.
public static double sumLogProb(double[] vals)
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.
vals
- An array log(x1), log(x2), ..., log(xn)
public static double subtractLogProb(double a, double b)
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).
public static double getEntropy(double[] dist)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |