public class MathEx
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DIGITS
The number of digits (in radix base) in the mantissa.
|
static double |
EPSILON
The machine precision for the double type, which is the difference between 1
and the smallest value greater than 1 that is representable for the double type.
|
static int |
FLOAT_DIGITS
The number of digits (in radix base) in the mantissa.
|
static float |
FLOAT_EPSILON
The machine precision for the float type, which is the difference between 1
and the smallest value greater than 1 that is representable for the float type.
|
static int |
FLOAT_MACHEP
The largest negative integer such that 1.0 + RADIXMACHEP ≠ 1.0,
except that machep is bounded below by -(DIGITS+3)
|
static int |
FLOAT_NEGEP
The largest negative integer such that 1.0 - RADIXNEGEP ≠ 1.0,
except that negeps is bounded below by -(DIGITS+3)
|
static int |
MACHEP
The largest negative integer such that 1.0 + RADIXMACHEP ≠ 1.0,
except that machep is bounded below by -(DIGITS+3)
|
static int |
NEGEP
The largest negative integer such that 1.0 - RADIXNEGEP ≠ 1.0,
except that negeps is bounded below by -(DIGITS+3)
|
static int |
RADIX
The base of the exponent of the double type.
|
static int |
ROUND_STYLE
Rounding style.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
add(double[] y,
double[] x)
Element-wise sum of two arrays y = x + y.
|
static boolean |
all(boolean[] x)
Given a set of boolean values, are all of the values true?
|
static boolean |
any(boolean[] x)
Given a set of boolean values, is at least one of the values true?
|
static double[] |
axpy(double a,
double[] x,
double[] y)
Update an array by adding a multiple of another array y = a * x + y.
|
static double[] |
c(double... x)
Combines the arguments to form a vector.
|
static double[] |
c(double[]... list)
Merges multiple vectors into one.
|
static float[] |
c(float... x)
Combines the arguments to form a vector.
|
static float[] |
c(float[]... list)
Merges multiple vectors into one.
|
static int[] |
c(int... x)
Combines the arguments to form a vector.
|
static int[] |
c(int[]... list)
Merges multiple vectors into one.
|
static java.lang.String[] |
c(java.lang.String... x)
Combines the arguments to form a vector.
|
static java.lang.String[] |
c(java.lang.String[]... list)
Concatenates multiple vectors into one array of strings.
|
static double[] |
cbind(double[]... x)
Take a sequence of vector arguments and combine by columns.
|
static float[] |
cbind(float[]... x)
Take a sequence of vector arguments and combine by columns.
|
static int[] |
cbind(int[]... x)
Take a sequence of vector arguments and combine by columns.
|
static java.lang.String[] |
cbind(java.lang.String[]... x)
Take a sequence of vector arguments and combine by columns.
|
static double |
choose(int n,
int k)
The n choose k.
|
static double[][] |
clone(double[][] x)
Deep clone a two-dimensional array.
|
static float[][] |
clone(float[][] x)
Deep clone a two-dimensional array.
|
static int[][] |
clone(int[][] x)
Deep clone a two-dimensional array.
|
static double[] |
colMax(double[][] data)
Returns the column maximum for a matrix.
|
static int[] |
colMax(int[][] data)
Returns the column maximum for a matrix.
|
static double[] |
colMeans(double[][] data)
Returns the column means for a matrix.
|
static double[] |
colMin(double[][] data)
Returns the column minimum for a matrix.
|
static int[] |
colMin(int[][] data)
Returns the column minimum for a matrix.
|
static double[] |
colSds(double[][] data)
Returns the column deviations for a matrix.
|
static double[] |
colSums(double[][] data)
Returns the column sums for a matrix.
|
static long[] |
colSums(int[][] data)
Returns the column sums for a matrix.
|
static boolean |
contains(double[][] polygon,
double[] point)
Determines if the polygon contains the specified coordinates.
|
static boolean |
contains(double[][] polygon,
double x,
double y)
Determines if the polygon contains the specified coordinates.
|
static void |
copy(double[][] x,
double[][] y)
Copy x into y.
|
static void |
copy(double[] x,
double[] y)
Copy x into y.
|
static void |
copy(float[][] x,
float[][] y)
Copy x into y.
|
static void |
copy(float[] x,
float[] y)
Copy x into y.
|
static void |
copy(int[][] x,
int[][] y)
Copy x into y.
|
static void |
copy(int[] x,
int[] y)
Copy x into y.
|
static double[][] |
cor(double[][] data)
Returns the sample correlation matrix.
|
static double[][] |
cor(double[][] data,
double[] mu)
Returns the sample correlation matrix.
|
static double |
cor(double[] x,
double[] y)
Returns the correlation coefficient between two vectors.
|
static double |
cor(float[] x,
float[] y)
Returns the correlation coefficient between two vectors.
|
static double |
cor(int[] x,
int[] y)
Returns the correlation coefficient between two vectors.
|
static double |
cos(double[] x,
double[] y)
Returns the cosine similarity.
|
static float |
cos(float[] x,
float[] y)
Returns the cosine similarity.
|
static double[][] |
cov(double[][] data)
Returns the sample covariance matrix.
|
static double[][] |
cov(double[][] data,
double[] mu)
Returns the sample covariance matrix.
|
static double |
cov(double[] x,
double[] y)
Returns the covariance between two vectors.
|
static double |
cov(float[] x,
float[] y)
Returns the covariance between two vectors.
|
static double |
cov(int[] x,
int[] y)
Returns the covariance between two vectors.
|
static double |
distance(double[] x,
double[] y)
The Euclidean distance.
|
static double |
distance(float[] x,
float[] y)
The Euclidean distance.
|
static double |
distance(int[] x,
int[] y)
The Euclidean distance on binary sparse arrays,
which are the indices of nonzero elements in ascending order.
|
static double |
distance(SparseArray x,
SparseArray y)
The Euclidean distance.
|
static double |
dot(double[] x,
double[] y)
Returns the dot product between two vectors.
|
static float |
dot(float[] x,
float[] y)
Returns the dot product between two vectors.
|
static int |
dot(int[] x,
int[] y)
Returns the dot product between two binary sparse arrays,
which are the indices of nonzero elements in ascending order.
|
static double |
dot(SparseArray x,
SparseArray y)
Returns the dot product between two sparse arrays.
|
static double |
entropy(double[] p)
Shannon's entropy.
|
static boolean |
equals(double[][] x,
double[][] y)
Check if x element-wisely equals y with default epsilon 1E-10.
|
static boolean |
equals(double[][] x,
double[][] y,
double eps)
Check if x element-wisely equals y.
|
static boolean |
equals(double[] x,
double[] y)
Check if x element-wisely equals y with default epsilon 1E-10.
|
static boolean |
equals(double[] x,
double[] y,
double eps)
Check if x element-wisely equals y.
|
static boolean |
equals(double a,
double b)
Returns true if two double values equals to each other in the system precision.
|
static boolean |
equals(float[][] x,
float[][] y)
Check if x element-wisely equals y with default epsilon 1E-7.
|
static boolean |
equals(float[][] x,
float[][] y,
float epsilon)
Check if x element-wisely equals y.
|
static boolean |
equals(float[] x,
float[] y)
Check if x element-wisely equals y with default epsilon 1E-7.
|
static boolean |
equals(float[] x,
float[] y,
float epsilon)
Check if x element-wisely equals y.
|
static double |
factorial(int n)
The factorial of n.
|
static boolean |
isInt(double x)
Returns true if x is an integer.
|
static boolean |
isInt(float x)
Returns true if x is an integer.
|
static boolean |
isPower2(int x)
Returns true if x is a power of 2.
|
static boolean |
isProbablePrime(long n,
int k)
Returns true if n is probably prime, false if it's definitely composite.
|
static boolean |
isZero(double x)
Tests if a floating number is zero.
|
static boolean |
isZero(double x,
double epsilon)
Tests if a floating number is zero with given epsilon.
|
static boolean |
isZero(float x)
Tests if a floating number is zero.
|
static boolean |
isZero(float x,
float epsilon)
Tests if a floating number is zero with given epsilon.
|
static double |
JensenShannonDivergence(double[] x,
double[] y)
Jensen-Shannon divergence JS(P||Q) = (KL(P||M) + KL(Q||M)) / 2, where
M = (P+Q)/2.
|
static double |
JensenShannonDivergence(double[] x,
SparseArray y)
Jensen-Shannon divergence JS(P||Q) = (KL(P||M) + KL(Q||M)) / 2, where
M = (P+Q)/2.
|
static double |
JensenShannonDivergence(SparseArray x,
double[] y)
Jensen-Shannon divergence JS(P||Q) = (KL(P||M) + KL(Q||M)) / 2, where
M = (P+Q)/2.
|
static double |
JensenShannonDivergence(SparseArray x,
SparseArray y)
Jensen-Shannon divergence JS(P||Q) = (KL(P||M) + KL(Q||M)) / 2, where
M = (P+Q)/2.
|
static double |
kendall(double[] x,
double[] y)
The Kendall Tau Rank Correlation Coefficient is used to measure the
degree of correspondence between sets of rankings where the measures
are not equidistant.
|
static double |
kendall(float[] x,
float[] y)
The Kendall Tau Rank Correlation Coefficient is used to measure the
degree of correspondence between sets of rankings where the measures
are not equidistant.
|
static double |
kendall(int[] x,
int[] y)
The Kendall Tau Rank Correlation Coefficient is used to measure the
degree of correspondence between sets of rankings where the measures
are not equidistant.
|
static double |
KullbackLeiblerDivergence(double[] x,
double[] y)
Kullback-Leibler divergence.
|
static double |
KullbackLeiblerDivergence(double[] x,
SparseArray y)
Kullback-Leibler divergence.
|
static double |
KullbackLeiblerDivergence(SparseArray x,
double[] y)
Kullback-Leibler divergence.
|
static double |
KullbackLeiblerDivergence(SparseArray x,
SparseArray y)
Kullback-Leibler divergence.
|
static double |
lchoose(int n,
int k)
The log of n choose k.
|
static double |
lfactorial(int n)
The log of factorial of n.
|
static double |
log(double x)
Returns natural log without underflow.
|
static double |
log1pe(double x)
Returns natural log(1+exp(x)) without overflow.
|
static double |
log2(double x)
Log of base 2.
|
static double |
logistic(double x)
Logistic sigmoid function.
|
static double |
mad(double[] x)
Returns the median absolute deviation (MAD).
|
static double |
mad(float[] x)
Returns the median absolute deviation (MAD).
|
static double |
mad(int[] x)
Returns the median absolute deviation (MAD).
|
static double |
max(double[] x)
Returns the maximum value of an array.
|
static double |
max(double[][] matrix)
Returns the maximum of a matrix.
|
static double |
max(double a,
double b,
double c)
maximum of 3 doubles
|
static double |
max(double a,
double b,
double c,
double d)
maximum of 4 doubles
|
static float |
max(float[] x)
Returns the maximum value of an array.
|
static float |
max(float a,
float b,
float c)
maximum of 3 floats
|
static float |
max(float a,
float b,
float c,
float d)
maximum of 4 floats
|
static int |
max(int[] x)
Returns the maximum value of an array.
|
static int |
max(int[][] matrix)
Returns the maximum of a matrix.
|
static int |
max(int a,
int b,
int c)
maximum of 3 integers
|
static int |
max(int a,
int b,
int c,
int d)
maximum of 4 integers
|
static double |
mean(double[] x)
Returns the mean of an array.
|
static double |
mean(float[] x)
Returns the mean of an array.
|
static double |
mean(int[] x)
Returns the mean of an array.
|
static double |
median(double[] a)
Find the median of an array of type double.
|
static float |
median(float[] a)
Find the median of an array of type float.
|
static int |
median(int[] a)
Find the median of an array of type int.
|
static <T extends java.lang.Comparable<? super T>> |
median(T[] a)
Find the median of an array of type double.
|
static double |
min(double[] x)
Returns the minimum value of an array.
|
static double |
min(double[][] matrix)
Returns the minimum of a matrix.
|
static double |
min(double a,
double b,
double c)
minimum of 3 doubles
|
static double |
min(double a,
double b,
double c,
double d)
minimum of 4 doubles
|
static float |
min(float[] x)
Returns the minimum value of an array.
|
static double |
min(float a,
float b,
float c)
minimum of 3 floats
|
static double |
min(float a,
float b,
float c,
float d)
minimum of 4 floats
|
static int |
min(int[] x)
Returns the minimum value of an array.
|
static int |
min(int[][] matrix)
Returns the minimum of a matrix.
|
static int |
min(int a,
int b,
int c)
minimum of 3 integers
|
static int |
min(int a,
int b,
int c,
int d)
minimum of 4 integers
|
static double |
norm(double[] x)
L2 vector norm.
|
static float |
norm(float[] x)
L2 vector norm.
|
static double |
norm1(double[] x)
L1 vector norm.
|
static float |
norm1(float[] x)
L1 vector norm.
|
static double |
norm2(double[] x)
L2 vector norm.
|
static float |
norm2(float[] x)
L2 vector norm.
|
static void |
normalize(double[][] x)
Unitizes each column of a matrix to unit length (L_2 norm).
|
static void |
normalize(double[][] x,
boolean centerizing)
Unitizes each column of a matrix to unit length (L_2 norm).
|
static double |
normInf(double[] x)
L-infinity vector norm.
|
static float |
normInf(float[] x)
L-infinity vector norm.
|
static Matrix |
pdist(double[][] x)
Returns the pairwise distance matrix of multiple vectors.
|
static Matrix |
pdist(double[][] x,
boolean squared)
Returns the pairwise distance matrix of multiple vectors.
|
static Matrix |
pdist(float[][] x)
Returns the pairwise distance matrix of multiple vectors.
|
static Matrix |
pdist(float[][] x,
boolean squared)
Returns the pairwise distance matrix of multiple vectors.
|
static Matrix |
pdist(int[][] x)
Returns the pairwise distance matrix of multiple binary sparse vectors.
|
static Matrix |
pdist(int[][] x,
boolean squared)
Returns the pairwise distance matrix of multiple binary sparse vectors.
|
static Matrix |
pdist(SparseArray[] x)
Returns the pairwise distance matrix of multiple vectors.
|
static Matrix |
pdist(SparseArray[] x,
boolean squared)
Returns the pairwise distance matrix of multiple vectors.
|
static <T> void |
pdist(T[] x,
double[][] d,
Distance<T> distance)
Computes the pairwise distance matrix of multiple vectors.
|
static Matrix |
pdot(double[][] x)
Returns the pairwise dot product matrix of double vectors.
|
static Matrix |
pdot(float[][] x)
Returns the pairwise dot product matrix of float vectors.
|
static Matrix |
pdot(int[][] x)
Returns the pairwise dot product matrix of binary sparse vectors.
|
static Matrix |
pdot(SparseArray[] x)
Returns the pairwise dot product matrix of multiple vectors.
|
static void |
permutate(double[] x)
Generates a permutation of given array.
|
static void |
permutate(float[] x)
Generates a permutation of given array.
|
static int[] |
permutate(int n)
Generates a permutation of 0, 1, 2, ..., n-1, which is useful for
sampling without replacement.
|
static void |
permutate(int[] x)
Generates a permutation of given array.
|
static void |
permutate(java.lang.Object[] x)
Generates a permutation of given array.
|
static double[] |
pow(double[] x,
double n)
Raise each element of an array to a scalar power.
|
static long |
probablePrime(long n,
int k)
Returns a probably prime number greater than n.
|
static double |
q1(double[] a)
Find the first quantile (p = 1/4) of an array of type double.
|
static float |
q1(float[] a)
Find the first quantile (p = 1/4) of an array of type float.
|
static int |
q1(int[] a)
Find the first quantile (p = 1/4) of an array of type int.
|
static <T extends java.lang.Comparable<? super T>> |
q1(T[] a)
Find the first quantile (p = 1/4) of an array of type double.
|
static double |
q3(double[] a)
Find the third quantile (p = 3/4) of an array of type double.
|
static float |
q3(float[] a)
Find the third quantile (p = 3/4) of an array of type float.
|
static int |
q3(int[] a)
Find the third quantile (p = 3/4) of an array of type int.
|
static <T extends java.lang.Comparable<? super T>> |
q3(T[] a)
Find the third quantile (p = 3/4) of an array of type double.
|
static double |
random()
Generate a random number in [0, 1).
|
static int |
random(double[] prob)
Given a set of n probabilities, generate a random number in [0, n).
|
static int[] |
random(double[] prob,
int n)
Given a set of m probabilities, draw with replacement a set of n random
number in [0, m).
|
static double |
random(double lo,
double hi)
Generate a uniform random number in the range [lo, hi).
|
static double[] |
random(double lo,
double hi,
int n)
Generate n uniform random numbers in the range [lo, hi).
|
static double[] |
random(int n)
Generate n random numbers in [0, 1).
|
static int |
randomInt(int n)
Returns a random integer in [0, n).
|
static int |
randomInt(int lo,
int hi)
Returns a random integer in [lo, hi).
|
static long |
randomLong()
Returns a random long integer.
|
static double[][] |
rbind(double[]... x)
Take a sequence of vector arguments and combine by rows.
|
static float[][] |
rbind(float[]... x)
Take a sequence of vector arguments and combine by rows.
|
static int[][] |
rbind(int[]... x)
Take a sequence of vector arguments and combine by rows.
|
static java.lang.String[][] |
rbind(java.lang.String[]... x)
Take a sequence of vector arguments and combine by rows.
|
static void |
reverse(double[] a)
Reverses the order of the elements in the specified array.
|
static void |
reverse(float[] a)
Reverses the order of the elements in the specified array.
|
static void |
reverse(int[] a)
Reverses the order of the elements in the specified array.
|
static <T> void |
reverse(T[] a)
Reverses the order of the elements in the specified array.
|
static double |
round(double x,
int decimal)
Round a double vale to given digits such as 10^n, where n is a positive
or negative integer.
|
static double[] |
rowMax(double[][] data)
Returns the row maximum for a matrix.
|
static int[] |
rowMax(int[][] data)
Returns the row maximum for a matrix.
|
static double[] |
rowMeans(double[][] data)
Returns the row means for a matrix.
|
static double[] |
rowMin(double[][] data)
Returns the row minimum for a matrix.
|
static int[] |
rowMin(int[][] data)
Returns the row minimum for a matrix.
|
static double[] |
rowSds(double[][] data)
Returns the row standard deviations for a matrix.
|
static double[] |
rowSums(double[][] data)
Returns the row sums for a matrix.
|
static long[] |
rowSums(int[][] data)
Returns the row sums for a matrix.
|
static void |
scale(double[][] x)
Scales each column of a matrix to range [0, 1].
|
static void |
scale(double a,
double[] x)
Scale each element of an array by a constant x = a * x.
|
static void |
scale(double a,
double[] x,
double[] y)
Scale each element of an array by a constant y = a * x.
|
static double |
sd(double[] x)
Returns the standard deviation of an array.
|
static double |
sd(float[] x)
Returns the standard deviation of an array.
|
static double |
sd(int[] x)
Returns the standard deviation of an array.
|
static java.util.stream.LongStream |
seeds(long n,
int k)
Returns a stream of prime numbers to be used as RNG seeds.
|
static void |
setSeed()
Initialize the random generator with a random seed from a
cryptographically strong random number generator.
|
static void |
setSeed(long seed)
Initialize the random generator with a seed.
|
static double[] |
slice(double[] data,
int[] index)
Returns a slice of data for given indices.
|
static <E> E[] |
slice(E[] data,
int[] index)
Returns a slice of data for given indices.
|
static float[] |
slice(float[] data,
int[] index)
Returns a slice of data for given indices.
|
static int[] |
slice(int[] data,
int[] index)
Returns a slice of data for given indices.
|
static int |
softmax(double[] posteriori)
The softmax function without overflow.
|
static int |
softmax(double[] x,
int k)
The softmax function without overflow.
|
static double[] |
solve(double[] a,
double[] b,
double[] c,
double[] r)
Solve the tridiagonal linear set which is of diagonal dominance
|
static int[][] |
sort(double[][] x)
Sorts each variable and returns the index of values in ascending order.
|
static double |
spearman(double[] x,
double[] y)
The Spearman Rank Correlation Coefficient is a form of the Pearson
coefficient with the data converted to rankings (ie.
|
static double |
spearman(float[] x,
float[] y)
The Spearman Rank Correlation Coefficient is a form of the Pearson
coefficient with the data converted to rankings (ie.
|
static double |
spearman(int[] x,
int[] y)
The Spearman Rank Correlation Coefficient is a form of the Pearson
coefficient with the data converted to rankings (ie.
|
static double |
sqr(double x)
Returns x * x.
|
static double |
squaredDistance(double[] x,
double[] y)
The squared Euclidean distance.
|
static double |
squaredDistance(float[] x,
float[] y)
The squared Euclidean distance.
|
static double |
squaredDistance(int[] x,
int[] y)
The squared Euclidean distance on binary sparse arrays,
which are the indices of nonzero elements in ascending order.
|
static double |
squaredDistance(SparseArray x,
SparseArray y)
The Euclidean distance on sparse arrays.
|
static double |
squaredDistanceWithMissingValues(double[] x,
double[] y)
The squared Euclidean distance with handling missing values (represented as NaN).
|
static void |
standardize(double[] x)
Standardizes an array to mean 0 and variance 1.
|
static void |
standardize(double[][] x)
Standardizes each column of a matrix to 0 mean and unit variance.
|
static void |
sub(double[] y,
double[] x)
Element-wise subtraction of two arrays y = y - x.
|
static int |
sum(byte[] x)
Returns the sum of an array.
|
static double |
sum(double[] x)
Returns the sum of an array.
|
static double |
sum(float[] x)
Returns the sum of an array.
|
static long |
sum(int[] x)
Returns the sum of an array.
|
static void |
swap(double[] x,
double[] y)
Swap two arrays.
|
static void |
swap(double[] x,
int i,
int j)
Swap two elements of an array.
|
static <E> void |
swap(E[] x,
E[] y)
Swap two arrays.
|
static void |
swap(float[] x,
float[] y)
Swap two arrays.
|
static void |
swap(float[] x,
int i,
int j)
Swap two elements of an array.
|
static void |
swap(int[] x,
int[] y)
Swap two arrays.
|
static void |
swap(int[] x,
int i,
int j)
Swap two elements of an array.
|
static void |
swap(java.lang.Object[] x,
int i,
int j)
Swap two elements of an array.
|
static double |
tanh(double x)
Hyperbolic tangent function.
|
static double[][] |
transpose(double[][] A)
Returns the matrix transpose.
|
static int[] |
unique(int[] x)
Find unique elements of vector.
|
static java.lang.String[] |
unique(java.lang.String[] x)
Find unique elements of vector.
|
static void |
unitize(double[] x)
Unitize an array so that L2 norm of x = 1.
|
static void |
unitize1(double[] x)
Unitize an array so that L1 norm of x is 1.
|
static void |
unitize2(double[] x)
Unitize an array so that L2 norm of x = 1.
|
static double |
var(double[] x)
Returns the variance of an array.
|
static double |
var(float[] x)
Returns the variance of an array.
|
static double |
var(int[] x)
Returns the variance of an array.
|
static int |
whichMax(double[] x)
Returns the index of maximum value of an array.
|
static IntPair |
whichMax(double[][] x)
Returns the index of maximum value of an array.
|
static int |
whichMax(float[] x)
Returns the index of maximum value of an array.
|
static int |
whichMax(int[] x)
Returns the index of maximum value of an array.
|
static int |
whichMin(double[] x)
Returns the index of minimum value of an array.
|
static IntPair |
whichMin(double[][] x)
Returns the index of minimum value of an array.
|
static int |
whichMin(float[] x)
Returns the index of minimum value of an array.
|
static int |
whichMin(int[] x)
Returns the index of minimum value of an array.
|
public static final double EPSILON
public static final float FLOAT_EPSILON
public static final int RADIX
public static final int DIGITS
public static final int FLOAT_DIGITS
public static final int ROUND_STYLE
public static final int MACHEP
public static final int FLOAT_MACHEP
public static final int NEGEP
public static final int FLOAT_NEGEP
public static double log2(double x)
public static double log(double x)
public static double log1pe(double x)
public static boolean isInt(float x)
public static boolean isInt(double x)
public static boolean equals(double a,
double b)
a - a double value.b - a double value.public static double logistic(double x)
public static double tanh(double x)
public static double sqr(double x)
public static boolean isPower2(int x)
public static boolean isProbablePrime(long n,
int k)
n - an odd integer to be tested for primalityk - a parameter that determines the accuracy of the testpublic static double round(double x,
int decimal)
public static double factorial(int n)
public static double lfactorial(int n)
public static double choose(int n,
int k)
public static double lchoose(int n,
int k)
public static void setSeed(long seed)
public static void setSeed()
public static long probablePrime(long n,
int k)
n - the returned value should be greater than n.k - a parameter that determines the accuracy of the primality testpublic static java.util.stream.LongStream seeds(long n,
int k)
n - the returned value should be greater than n.k - a parameter that determines the accuracy of the primality testpublic static int random(double[] prob)
prob - probabilities of size n. The prob argument can be used to
give a vector of weights for obtaining the elements of the vector being
sampled. They need not sum to one, but they should be non-negative and
not all zero.public static int[] random(double[] prob,
int n)
prob - probabilities of size n. The prob argument can be used to
give a vector of weights for obtaining the elements of the vector being
sampled. They need not sum to one, but they should be non-negative and
not all zero.public static double random()
public static double[] random(int n)
public static double random(double lo,
double hi)
lo - lower limit of rangehi - upper limit of rangepublic static double[] random(double lo,
double hi,
int n)
n - size of the arraylo - lower limit of rangehi - upper limit of rangepublic static long randomLong()
public static int randomInt(int n)
public static int randomInt(int lo,
int hi)
public static int[] permutate(int n)
public static void permutate(int[] x)
public static void permutate(float[] x)
public static void permutate(double[] x)
public static void permutate(java.lang.Object[] x)
public static int softmax(double[] posteriori)
posteriori - the input/output vector.public static int softmax(double[] x,
int k)
x - the input/output vector.k - uses only first k components of input vector.public static int[] c(int... x)
public static float[] c(float... x)
public static double[] c(double... x)
public static java.lang.String[] c(java.lang.String... x)
public static int[] c(int[]... list)
public static float[] c(float[]... list)
public static double[] c(double[]... list)
public static java.lang.String[] c(java.lang.String[]... list)
public static int[] cbind(int[]... x)
public static float[] cbind(float[]... x)
public static double[] cbind(double[]... x)
public static java.lang.String[] cbind(java.lang.String[]... x)
public static int[][] rbind(int[]... x)
public static float[][] rbind(float[]... x)
public static double[][] rbind(double[]... x)
public static java.lang.String[][] rbind(java.lang.String[]... x)
public static <E> E[] slice(E[] data,
int[] index)
public static int[] slice(int[] data,
int[] index)
public static float[] slice(float[] data,
int[] index)
public static double[] slice(double[] data,
int[] index)
public static boolean contains(double[][] polygon,
double[] point)
point - the coordinates of specified point to be tested.public static boolean contains(double[][] polygon,
double x,
double y)
x - the specified x coordinate.y - the specified y coordinate.public static void reverse(int[] a)
a - an array to reverse.public static void reverse(float[] a)
a - an array to reverse.public static void reverse(double[] a)
a - an array to reverse.public static <T> void reverse(T[] a)
a - an array to reverse.public static int min(int a,
int b,
int c)
public static double min(float a,
float b,
float c)
public static double min(double a,
double b,
double c)
public static int min(int a,
int b,
int c,
int d)
public static double min(float a,
float b,
float c,
float d)
public static double min(double a,
double b,
double c,
double d)
public static int max(int a,
int b,
int c)
public static float max(float a,
float b,
float c)
public static double max(double a,
double b,
double c)
public static int max(int a,
int b,
int c,
int d)
public static float max(float a,
float b,
float c,
float d)
public static double max(double a,
double b,
double c,
double d)
public static int min(int[] x)
public static float min(float[] x)
public static double min(double[] x)
public static int whichMin(int[] x)
public static int whichMin(float[] x)
public static int whichMin(double[] x)
public static IntPair whichMin(double[][] x)
public static int max(int[] x)
public static float max(float[] x)
public static double max(double[] x)
public static int whichMax(int[] x)
public static int whichMax(float[] x)
public static int whichMax(double[] x)
public static IntPair whichMax(double[][] x)
public static int min(int[][] matrix)
public static double min(double[][] matrix)
public static int max(int[][] matrix)
public static double max(double[][] matrix)
public static double[][] transpose(double[][] A)
public static int[] rowMin(int[][] data)
public static int[] rowMax(int[][] data)
public static long[] rowSums(int[][] data)
public static double[] rowMin(double[][] data)
public static double[] rowMax(double[][] data)
public static double[] rowSums(double[][] data)
public static double[] rowMeans(double[][] data)
public static double[] rowSds(double[][] data)
public static int[] colMin(int[][] data)
public static int[] colMax(int[][] data)
public static long[] colSums(int[][] data)
public static double[] colMin(double[][] data)
public static double[] colMax(double[][] data)
public static double[] colSums(double[][] data)
public static double[] colMeans(double[][] data)
public static double[] colSds(double[][] data)
public static int sum(byte[] x)
public static long sum(int[] x)
public static double sum(float[] x)
public static double sum(double[] x)
public static int median(int[] a)
public static float median(float[] a)
public static double median(double[] a)
public static <T extends java.lang.Comparable<? super T>> T median(T[] a)
public static int q1(int[] a)
public static float q1(float[] a)
public static double q1(double[] a)
public static <T extends java.lang.Comparable<? super T>> T q1(T[] a)
public static int q3(int[] a)
public static float q3(float[] a)
public static double q3(double[] a)
public static <T extends java.lang.Comparable<? super T>> T q3(T[] a)
public static double mean(int[] x)
public static double mean(float[] x)
public static double mean(double[] x)
public static double var(int[] x)
public static double var(float[] x)
public static double var(double[] x)
public static double sd(int[] x)
public static double sd(float[] x)
public static double sd(double[] x)
public static double mad(int[] x)
MAD(X) = median(|Xi - median(Xi)|)
that is, starting with the residuals (deviations) from the data's median, the MAD is the median of their absolute values.
MAD is a more robust estimator of scale than the sample variance or standard deviation. For instance, MAD is more resilient to outliers in a data set than the standard deviation. It thus behaves better with distributions without a mean or variance, such as the Cauchy distribution.
In order to use the MAD as a consistent estimator for the estimation of the standard deviation σ, one takes σ = K * MAD, where K is a constant scale factor, which depends on the distribution. For normally distributed data K is taken to be 1.4826. Other distributions behave differently: for example for large samples from a uniform continuous distribution, this factor is about 1.1547.
public static double mad(float[] x)
MAD(X) = median(|Xi - median(Xi)|)
that is, starting with the residuals (deviations) from the data's median, the MAD is the median of their absolute values.
MAD is a more robust estimator of scale than the sample variance or standard deviation. For instance, MAD is more resilient to outliers in a data set than the standard deviation. It thus behaves better with distributions without a mean or variance, such as the Cauchy distribution.
In order to use the MAD as a consistent estimator for the estimation of the standard deviation σ, one takes σ = K * MAD, where K is a constant scale factor, which depends on the distribution. For normally distributed data K is taken to be 1.4826. Other distributions behave differently: for example for large samples from a uniform continuous distribution, this factor is about 1.1547.
public static double mad(double[] x)
MAD(X) = median(|Xi - median(Xi)|)
that is, starting with the residuals (deviations) from the data's median, the MAD is the median of their absolute values.
MAD is a more robust estimator of scale than the sample variance or standard deviation. For instance, MAD is more resilient to outliers in a data set than the standard deviation. It thus behaves better with distributions without a mean or variance, such as the Cauchy distribution.
In order to use the MAD as a consistent estimator for the estimation of the standard deviation σ, one takes σ = K * MAD, where K is a constant scale factor, which depends on the distribution. For normally distributed data K is taken to be 1.4826. Other distributions behave differently: for example for large samples from a uniform continuous distribution, this factor is about 1.1547.
public static boolean all(boolean[] x)
public static boolean any(boolean[] x)
public static double distance(int[] x,
int[] y)
public static double distance(float[] x,
float[] y)
public static double distance(double[] x,
double[] y)
public static double distance(SparseArray x, SparseArray y)
public static double squaredDistance(int[] x,
int[] y)
public static double squaredDistance(float[] x,
float[] y)
public static double squaredDistance(double[] x,
double[] y)
public static double squaredDistance(SparseArray x, SparseArray y)
public static double squaredDistanceWithMissingValues(double[] x,
double[] y)
public static Matrix pdist(int[][] x)
x - Each row is a binary sparse array, which are the indices of
nonzero elements in ascending order.public static Matrix pdist(int[][] x, boolean squared)
x - Each row is a binary sparse array, which are the indices of
nonzero elements in ascending order.squared - If true, compute the squared Euclidean distance.public static Matrix pdist(float[][] x)
x - Rows of x correspond to observations, and columns correspond to variables.public static Matrix pdist(float[][] x, boolean squared)
x - Rows of x correspond to observations, and columns correspond to variables.squared - If true, compute the squared Euclidean distance.public static Matrix pdist(double[][] x)
x - Rows of x correspond to observations, and columns correspond to variables.public static Matrix pdist(double[][] x, boolean squared)
x - Rows of x correspond to observations, and columns correspond to variables.squared - If true, compute the squared Euclidean distance.public static Matrix pdist(SparseArray[] x)
x - Each row is the sparse array of observationspublic static Matrix pdist(SparseArray[] x, boolean squared)
x - Each row is the sparse array of observationssquared - If true, compute the squared Euclidean distance.public static <T> void pdist(T[] x,
double[][] d,
Distance<T> distance)
x - Rows of x correspond to observations, and columns correspond to variables.d - The output distance matrix. It may be only the lower half.distance - The distance lambda.public static double entropy(double[] p)
p - the probabilities.public static double KullbackLeiblerDivergence(double[] x,
double[] y)
Although it is often intuited as a distance metric, the KL divergence is not a true metric - for example, the KL from P to Q is not necessarily the same as the KL from Q to P.
public static double KullbackLeiblerDivergence(SparseArray x, SparseArray y)
Although it is often intuited as a distance metric, the KL divergence is not a true metric - for example, the KL from P to Q is not necessarily the same as the KL from Q to P.
public static double KullbackLeiblerDivergence(double[] x,
SparseArray y)
Although it is often intuited as a distance metric, the KL divergence is not a true metric - for example, the KL from P to Q is not necessarily the same as the KL from Q to P.
public static double KullbackLeiblerDivergence(SparseArray x, double[] y)
Although it is often intuited as a distance metric, the KL divergence is not a true metric - for example, the KL from P to Q is not necessarily the same as the KL from Q to P.
public static double JensenShannonDivergence(double[] x,
double[] y)
public static double JensenShannonDivergence(SparseArray x, SparseArray y)
public static double JensenShannonDivergence(double[] x,
SparseArray y)
public static double JensenShannonDivergence(SparseArray x, double[] y)
public static int dot(int[] x,
int[] y)
public static float dot(float[] x,
float[] y)
public static double dot(double[] x,
double[] y)
public static double dot(SparseArray x, SparseArray y)
public static Matrix pdot(int[][] x)
x - Rows of x correspond to observations, and columns correspond to variables.public static Matrix pdot(float[][] x)
x - Rows of x correspond to observations, and columns correspond to variables.public static Matrix pdot(double[][] x)
x - Rows of x correspond to observations, and columns correspond to variables.public static Matrix pdot(SparseArray[] x)
x - Rows of x correspond to observations, and columns correspond to variables.public static double cov(int[] x,
int[] y)
public static double cov(float[] x,
float[] y)
public static double cov(double[] x,
double[] y)
public static double[][] cov(double[][] data)
public static double[][] cov(double[][] data,
double[] mu)
mu - the known mean of data.public static double cor(int[] x,
int[] y)
public static double cor(float[] x,
float[] y)
public static double cor(double[] x,
double[] y)
public static double[][] cor(double[][] data)
public static double[][] cor(double[][] data,
double[] mu)
mu - the known mean of data.public static double spearman(int[] x,
int[] y)
public static double spearman(float[] x,
float[] y)
public static double spearman(double[] x,
double[] y)
public static double kendall(int[] x,
int[] y)
public static double kendall(float[] x,
float[] y)
public static double kendall(double[] x,
double[] y)
public static float norm1(float[] x)
public static double norm1(double[] x)
public static float norm2(float[] x)
public static double norm2(double[] x)
public static float normInf(float[] x)
public static double normInf(double[] x)
public static float norm(float[] x)
public static double norm(double[] x)
public static float cos(float[] x,
float[] y)
public static double cos(double[] x,
double[] y)
public static void standardize(double[] x)
public static void scale(double[][] x)
public static void standardize(double[][] x)
public static void normalize(double[][] x)
public static void normalize(double[][] x,
boolean centerizing)
centerizing - If true, centerize each column to 0 mean.public static void unitize(double[] x)
x - the array of doublepublic static void unitize1(double[] x)
x - an array of non-negative doublepublic static void unitize2(double[] x)
x - the array of doublepublic static boolean equals(float[] x,
float[] y)
public static boolean equals(float[] x,
float[] y,
float epsilon)
public static boolean equals(double[] x,
double[] y)
public static boolean equals(double[] x,
double[] y,
double eps)
public static boolean equals(float[][] x,
float[][] y)
public static boolean equals(float[][] x,
float[][] y,
float epsilon)
public static boolean equals(double[][] x,
double[][] y)
public static boolean equals(double[][] x,
double[][] y,
double eps)
public static boolean isZero(float x)
public static boolean isZero(float x,
float epsilon)
public static boolean isZero(double x)
public static boolean isZero(double x,
double epsilon)
public static int[][] clone(int[][] x)
public static float[][] clone(float[][] x)
public static double[][] clone(double[][] x)
public static void swap(int[] x,
int i,
int j)
public static void swap(float[] x,
int i,
int j)
public static void swap(double[] x,
int i,
int j)
public static void swap(java.lang.Object[] x,
int i,
int j)
public static void swap(int[] x,
int[] y)
public static void swap(float[] x,
float[] y)
public static void swap(double[] x,
double[] y)
public static <E> void swap(E[] x,
E[] y)
public static void copy(int[] x,
int[] y)
public static void copy(float[] x,
float[] y)
public static void copy(double[] x,
double[] y)
public static void copy(int[][] x,
int[][] y)
public static void copy(float[][] x,
float[][] y)
public static void copy(double[][] x,
double[][] y)
public static void add(double[] y,
double[] x)
public static void sub(double[] y,
double[] x)
y - minuend matrixx - subtrahend matrixpublic static void scale(double a,
double[] x)
public static void scale(double a,
double[] x,
double[] y)
public static double[] axpy(double a,
double[] x,
double[] y)
public static double[] pow(double[] x,
double n)
x - arrayn - scalar exponentpublic static int[] unique(int[] x)
x - an integer array.public static java.lang.String[] unique(java.lang.String[] x)
x - an array of strings.public static int[][] sort(double[][] x)
x - a set of variables to be sorted. Each row is an instance. Each
column is a variable.public static double[] solve(double[] a,
double[] b,
double[] c,
double[] r)
|bi| > |ai| + |ci|.
| b0 c0 0 0 0 ... |
| a1 b1 c1 0 0 ... |
| 0 a2 b2 c2 0 ... |
| ... |
| ... a(n-2) b(n-2) c(n-2) |
| ... 0 a(n-1) b(n-1) |
a - the lower part of tridiagonal matrix. a[0] is undefined and not
referenced by the method.b - the diagonal of tridiagonal matrix.c - the upper of tridiagonal matrix. c[n-1] is undefined and not
referenced by the method.r - the right-hand side of linear equations.