public final class MathUtil extends Object
Modifier and Type | Field and Description |
---|---|
static double |
LOG2
Logarithm of 2 to the basis e, for logarithm conversion.
|
static double |
LOGPI
Math.log(Math.PI)
|
static double |
ONE_BY_SQRTPI
Precomputed value of 1 / sqrt(pi)
|
static double |
SQRT2
Square root of 2.
|
static double |
SQRT5
Square root of 5
|
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 |
angle(double[] v1,
double[] v2)
Compute the angle between two vectors.
|
static double |
angle(double[] v1,
double[] v2,
double[] o)
Compute the angle between two vectors.
|
static double |
angle(Vector v1,
Vector v2)
Compute the angle between two vectors.
|
static double |
angle(Vector v1,
Vector v2,
Vector o)
Compute the angle between two vectors.
|
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 |
deg2rad(double deg)
Convert Degree to Radians
|
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 |
fastHypot(double a,
double b)
Computes the square root of the sum of the squared arguments without under
or overflow.
|
static double |
fastHypot3(double a,
double b,
double c)
Computes the square root of the sum of the squared arguments without under
or overflow.
|
static double |
floatToDoubleLower(float f)
Return the largest double that rounds up to this float.
|
static double |
floatToDoubleUpper(float f)
Return the largest double that rounds down to this float.
|
static double |
latlngDistance(double lat1,
double lon1,
double lat2,
double lon2)
Compute the approximate on-earth-surface distance of two points.
|
static double |
mahalanobisDistance(Matrix weightMatrix,
Vector o1_minus_o2)
Compute the Mahalanobis distance using the given weight matrix
|
static int |
nextAllOnesInt(int x)
Find the next larger number with all ones.
|
static long |
nextAllOnesLong(long x)
Find the next larger number with all ones.
|
static int |
nextPow2Int(int x)
Find the next power of 2.
|
static long |
nextPow2Long(long x)
Find the next power of 2.
|
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 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.
|
static double |
weightedPearsonCorrelationCoefficient(NumberVector<?,?> x,
NumberVector<?,?> y,
NumberVector<?,?> 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 SQRT5
public static final double SQRTHALF
public static final double ONE_BY_SQRTPI
public static final double LOG2
public static final double LOGPI
public static double fastHypot(double a, double b)
Math.hypot(double, double)
, since the
latter is significantly slower (but maybe has a higher precision).a
- first cathetusb
- second cathetussqrt(a<sup>2</sup> + b<sup>2</sup>)
public static double fastHypot3(double a, double b, double c)
Math.hypot(double, double)
, since the
latter is significantly slower (but has a higher precision).a
- first cathetusb
- second cathetusc
- second cathetussqrt(a<sup>2</sup> + b<sup>2</sup> + c<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 weightedPearsonCorrelationCoefficient(NumberVector<?,?> x, NumberVector<?,?> y, NumberVector<?,?> 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 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 degreepublic static double angle(Vector v1, Vector v2)
v1
- first vectorv2
- second vectorpublic static double angle(double[] v1, double[] v2)
v1
- first vectorv2
- second vectorpublic static double angle(Vector v1, Vector v2, Vector o)
v1
- first vectorv2
- second vectoro
- Originpublic static double angle(double[] v1, double[] v2, double[] o)
v1
- first vectorv2
- second vectoro
- Originpublic static int nextPow2Int(int x)
x
- original integerpublic static long nextPow2Long(long x)
x
- original long integerpublic static int nextAllOnesInt(int x)
x
- original integerpublic static long nextAllOnesLong(long x)
x
- original long integerpublic static double floatToDoubleUpper(float f)
f
- Float valuepublic static double floatToDoubleLower(float f)
f
- Float value