public final class MathUtil extends Object
Modifier and Type | Field and Description |
---|---|
(package private) static double[] |
ERFAPP_A
Coefficients for erf approximation.
|
(package private) static double[] |
ERFAPP_B
Coefficients for erf approximation.
|
(package private) static double[] |
ERFAPP_C
Coefficients for erf approximation.
|
(package private) static double[] |
ERFAPP_D
Coefficients for erf approximation.
|
(package private) static double[] |
ERFAPP_P
Coefficients for erf approximation.
|
(package private) static double[] |
ERFAPP_Q
Coefficients for erf approximation.
|
(package private) static double[] |
ERFINV_A
Coefficients for erfinv approximation, rational version
|
(package private) static double[] |
ERFINV_B
Coefficients for erfinv approximation, rational version
|
(package private) static double[] |
ERFINV_C
Coefficients for erfinv approximation, rational version
|
(package private) static double[] |
ERFINV_D
Coefficients for erfinv approximation, rational version
|
(package private) static double[] |
LANCZOS
LANCZOS-Coefficients for Gamma approximation.
|
(package private) static double |
NUM_PRECISION
Numerical precision to use
|
static double |
ONE_BY_SQRTPI
Precomputed value of 1 / sqrt(pi)
|
(package private) static double |
P_HIGH
Treshold for switching nethods for erfinv approximation
|
(package private) static double |
P_LOW
Treshold for switching nethods for erfinv approximation
|
static double |
SQRT2
Square root of 2.
|
static double |
SQRTHALF
Square root of 0.5 == 1 / Sqrt(2)
|
static double |
SQRTTWOPI
Squre root of two times Pi.
|
static double |
TWOPI
Two times Pi.
|
Modifier | Constructor and Description |
---|---|
private |
MathUtil()
Fake constructor for static class.
|
Modifier and Type | Method and Description |
---|---|
static double |
approximateBinomialCoefficient(int n,
int k)
Binomial coefficent, also known as "n choose k")
|
static double |
approximateFactorial(int n)
Compute the Factorial of n, often written as
c! |
static long |
binomialCoefficient(long n,
long k)
Binomial coefficient, also known as "n choose k".
|
static double |
cosineSimilarity(Vector v1,
Vector v2)
Compute the cosine similarity for two vectors.
|
static double |
deg2rad(double deg)
Convert Degree to Radians
|
static double |
erf(double x)
Error function for Gaussian distributions = Normal distributions.
|
static double |
erfc(double x)
Complementary error function for Gaussian distributions = Normal
distributions.
|
static double |
erfinv(double x)
Inverse error function.
|
static BigInteger |
factorial(BigInteger n)
Compute the Factorial of n, often written as
c! |
static long |
factorial(int n)
Compute the Factorial of n, often written as
c! |
static double |
hypotenuse(double a,
double b)
Computes the square root of the sum of the squared arguments without under
or overflow.
|
static double |
latlngDistance(double lat1,
double lon1,
double lat2,
double lon2)
Compute the approximate on-earth-surface distance of two points.
|
static double |
logGamma(double x)
Compute logGamma.
|
static double |
mahalanobisDistance(Matrix weightMatrix,
Vector o1_minus_o2)
Compute the Mahalanobis distance using the given weight matrix
|
static double |
normalCDF(double x,
double mu,
double sigma)
Cumulative probability density function (CDF) of a normal distribution.
|
static double |
normalPDF(double x,
double mu,
double sigma)
Probability density function of the normal distribution.
|
static double |
normalProbit(double x,
double mu,
double sigma)
Inverse cumulative probability density function (probit) of a normal
distribution.
|
static double |
pearsonCorrelationCoefficient(double[] x,
double[] y)
Provides the Pearson product-moment correlation coefficient for two
FeatureVectors.
|
static double |
pearsonCorrelationCoefficient(NumberVector<?,?> x,
NumberVector<?,?> y)
Provides the Pearson product-moment correlation coefficient for two
FeatureVectors.
|
static double |
rad2deg(double rad)
Radians to Degree
|
static double[] |
randomDoubleArray(int len)
Produce an array of random numbers in [0:1]
|
static double[] |
randomDoubleArray(int len,
Random r)
Produce an array of random numbers in [0:1]
|
static double |
regularizedGammaP(double a,
double x)
Returns the regularized gamma function P(a, x).
|
static double |
regularizedGammaQ(double a,
double x)
Returns the regularized gamma function Q(a, x) = 1 - P(a, x).
|
static double |
standardNormalProbit(double d)
Approximate the inverse error function for normal distributions.
|
static long |
sumFirstIntegers(long i)
Compute the sum of the i first integers.
|
static double |
weightedPearsonCorrelationCoefficient(double[] x,
double[] y,
double[] weights)
Provides the Pearson product-moment correlation coefficient for two
FeatureVectors.
|
static double |
weightedPearsonCorrelationCoefficient(NumberVector<?,?> x,
NumberVector<?,?> y,
double[] weights)
Provides the Pearson product-moment correlation coefficient for two
FeatureVectors.
|
public static final double TWOPI
public static final double SQRTTWOPI
public static final double SQRT2
public static final double SQRTHALF
public static final double ONE_BY_SQRTPI
static final double[] ERFAPP_A
static final double[] ERFAPP_B
static final double[] ERFAPP_C
static final double[] ERFAPP_D
static final double[] ERFAPP_P
static final double[] ERFAPP_Q
static final double P_LOW
static final double P_HIGH
static final double[] ERFINV_A
static final double[] ERFINV_B
static final double[] ERFINV_C
static final double[] ERFINV_D
static final double[] LANCZOS
static final double NUM_PRECISION
public static double hypotenuse(double a, double b)
a
- first cathetusb
- second cathetussqrt(a<sup>2</sup> + b<sup>2</sup>)
public static double mahalanobisDistance(Matrix weightMatrix, Vector o1_minus_o2)
weightMatrix
- Weight Matrixo1_minus_o2
- Delta vectorpublic static double pearsonCorrelationCoefficient(NumberVector<?,?> x, NumberVector<?,?> y)
Provides the Pearson product-moment correlation coefficient for two FeatureVectors.
x
- first FeatureVectory
- second FeatureVectorpublic static double weightedPearsonCorrelationCoefficient(NumberVector<?,?> x, NumberVector<?,?> y, double[] weights)
Provides the Pearson product-moment correlation coefficient for two FeatureVectors.
x
- first FeatureVectory
- second FeatureVectorpublic static double pearsonCorrelationCoefficient(double[] x, double[] y)
Provides the Pearson product-moment correlation coefficient for two FeatureVectors.
x
- first FeatureVectory
- second FeatureVectorpublic static double weightedPearsonCorrelationCoefficient(double[] x, double[] y, double[] weights)
Provides the Pearson product-moment correlation coefficient for two FeatureVectors.
x
- first FeatureVectory
- second FeatureVectorpublic static BigInteger factorial(BigInteger n)
c!
in
mathematics.
Use this method if for large values of n
.
n
- Note: n >= 0. This BigInteger
n
will be 0
after this method finishes.public static long factorial(int n)
c!
in
mathematics.n
- Note: n >= 0public static long binomialCoefficient(long n, long k)
Binomial coefficient, also known as "n choose k".
n
- Total number of samples. n > 0k
- Number of elements to choose. n >= k
,
k >= 0
public static double approximateFactorial(int n)
c!
in
mathematics.n
- Note: n >= 0public static double approximateBinomialCoefficient(int n, int k)
Binomial coefficent, also known as "n choose k")
n
- Total number of samples. n > 0k
- Number of elements to choose. n >= k
,
k >= 0
public static double erfc(double x)
x
- parameter valuepublic static double erf(double x)
x
- parameter valuepublic static double erfinv(double x)
x
- parameter valuepublic static double standardNormalProbit(double d)
http://www.math.uio.no/~jacklam/notes/invnorm/index.html
by Peter John Acklam
d
- Quantile. Must be in [0:1], obviously.public static double normalPDF(double x, double mu, double sigma)
1/(SQRT(2*pi*sigma^2)) * e^(-(x-mu)^2/2sigma^2)
x
- The value.mu
- The mean.sigma
- The standard deviation.public static double normalCDF(double x, double mu, double sigma)
x
- value to evaluate CDF atmu
- Mean valuesigma
- Standard deviation.public static double normalProbit(double x, double mu, double sigma)
x
- value to evaluate probit function atmu
- Mean valuesigma
- Standard deviation.public static double logGamma(double x)
x
- Parameter xpublic static double regularizedGammaP(double a, double x)
a
- Parameter ax
- Parameter xpublic static double regularizedGammaQ(double a, double x)
a
- parameter ax
- parameter xpublic static long sumFirstIntegers(long i)
i
- maximum summandpublic static double[] randomDoubleArray(int len)
len
- Lengthpublic static double[] randomDoubleArray(int len, Random r)
len
- Lengthr
- Random generatorpublic static double deg2rad(double deg)
deg
- Degree valuepublic static double rad2deg(double rad)
rad
- Radians valuepublic static double latlngDistance(double lat1, double lon1, double lat2, double lon2)
lat1
- Latitude of first point in degreelon1
- Longitude of first point in degreelat2
- Latitude of second point in degreelon2
- Longitude of second point in degree