public final class Maths extends Object
| Modifier and Type | Field and Description |
|---|---|
static double |
EPSILON
Numbers that are closer than this are considered equal
by almostEquals.
|
| Constructor and Description |
|---|
Maths() |
| Modifier and Type | Method and Description |
|---|---|
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 double |
cosh(double a) |
static double |
factorial(int n) |
static double |
gamma(double x) |
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 |
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) |
public static double EPSILON
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 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 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)
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).
Copyright © 2019 JULIE Lab, Germany. All rights reserved.