public class BasicMathFunctions extends Object
Constructor and Description |
---|
BasicMathFunctions()
Empty default constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkProbabilityRange(double p)
Checks that a probability is between 0 and 1 and throws an
IllegalArgumentException otherwise.
|
static void |
checkProbabilityRangeInPercent(double p)
Checks that a probability is between 0 % and 100 % and throws an
IllegalArgumentException otherwise.
|
static long |
factorial(int n)
Returns n! as a long.
|
static long |
factorial(int n,
int k)
Returns n!/k!, an error is thrown if it cannot fit in a long.
|
static double |
factorialDouble(int n)
Returns n! as a double.
|
static double |
factorialDouble(int n,
int k)
Returns n!/k! as double.
|
static long |
getCombination(int k,
int n)
Returns the number of k-combinations in a set of n elements.
|
static double |
getCombinationDouble(int k,
int n)
Returns the number of k-combinations in a set of n elements.
|
static double |
getCorrelation(ArrayList<Double> series1,
ArrayList<Double> series2)
Returns the population Pearson correlation r between series1 and series2.
|
static long[] |
getFactorialsCache()
Returns factorial 0 to 20 in an array.
|
static double |
getOneOverCombinationDouble(int k,
int n)
Returns the invert of the number of k-combinations in a set of n
elements.
|
static ArrayList<Integer> |
getRandomIndexes(int n,
int min,
int max)
Returns a list of n random indexes between min and max included.
|
static int |
getRandomInteger(int min,
int max)
Returns an integer randomly chosen between min and max included.
|
static double |
getRobustCorrelation(ArrayList<Double> series1,
ArrayList<Double> series2)
Returns the population Pearson correlation r between series1 and series2.
|
static double |
log(double input,
double base)
Returns the log of the input in the desired base.
|
static double |
mad(ArrayList<Double> ratios)
Method estimating the median absolute deviation.
|
static double |
mad(double[] ratios)
Method estimating the median absolute deviation.
|
static double |
mean(ArrayList<Double> input)
Convenience method returning the mean of a list of doubles.
|
static double |
median(ArrayList<Double> input)
Method to estimate the median of an unsorted list.
|
static double |
median(double[] input)
Method to estimate the median for an unsorted list.
|
static double |
medianSorted(ArrayList<Double> input)
Method to estimate the median of a sorted list.
|
static double |
medianSorted(double[] input)
Method to estimate the median for a sorted list.
|
static double |
percentile(ArrayList<Double> input,
double percentile)
Returns the desired percentile in a list of unsorted double values.
|
static double |
percentile(double[] input,
double percentile)
Returns the desired percentile in a given array of unsorted double
values.
|
static double |
percentileSorted(ArrayList<Double> input,
double percentile)
Returns the desired percentile in a list of sorted double values.
|
static double |
percentileSorted(double[] input,
double percentile)
Returns the desired percentile in an array of sorted double values.
|
static double |
std(ArrayList<Double> input)
Convenience method returning the standard deviation of a list of doubles.
|
static double |
sum(ArrayList<Double> input)
Convenience method returning the sum of a list of doubles.
|
public static long[] getFactorialsCache()
public static double factorialDouble(int n)
n
- a given integerpublic static long factorial(int n)
n
- a given integerpublic static double factorialDouble(int n, int k)
n
- nk
- kpublic static long factorial(int n, int k)
n
- nk
- kpublic static double getCombinationDouble(int k, int n)
k
- the number of k-combinationsn
- the number of elementspublic static double getOneOverCombinationDouble(int k, int n)
k
- the number of k-combinationsn
- the number of elementspublic static long getCombination(int k, int n)
k
- the number of k-combinationsn
- the number of elementspublic static double median(double[] input)
input
- array of doublepublic static double medianSorted(double[] input)
input
- array of doublepublic static double median(ArrayList<Double> input)
input
- ArrayList of doublepublic static double medianSorted(ArrayList<Double> input)
input
- ArrayList of doublepublic static double percentile(double[] input, double percentile)
input
- the input arraypercentile
- the desired percentile. 0.01 returns the first
percentile. 0.5 returns the median.public static double percentileSorted(double[] input, double percentile)
input
- the input arraypercentile
- the desired percentile. 0.01 returns the first
percentile. 0.5 returns the median.public static double percentile(ArrayList<Double> input, double percentile)
input
- the input listpercentile
- the desired percentile. 0.01 returns the first
percentile. 0.5 returns the median.public static double percentileSorted(ArrayList<Double> input, double percentile)
input
- the input listpercentile
- the desired percentile. 0.01 returns the first
percentile. 0.5 returns the median.public static double mad(double[] ratios)
ratios
- array of doublespublic static double mad(ArrayList<Double> ratios)
ratios
- array of doublespublic static double log(double input, double base)
input
- the inputbase
- the log basepublic static double std(ArrayList<Double> input)
input
- input listpublic static double mean(ArrayList<Double> input)
input
- input listpublic static double sum(ArrayList<Double> input)
input
- input listpublic static double getCorrelation(ArrayList<Double> series1, ArrayList<Double> series2)
series1
- first series to compareseries2
- second series to comparepublic static double getRobustCorrelation(ArrayList<Double> series1, ArrayList<Double> series2)
series1
- the first series to inspectseries2
- the second series to inspectpublic static void checkProbabilityRange(double p)
p
- the probabilitypublic static void checkProbabilityRangeInPercent(double p)
p
- the probabilitypublic static int getRandomInteger(int min, int max)
min
- the lower limitmax
- the higher limitpublic static ArrayList<Integer> getRandomIndexes(int n, int min, int max)
n
- the number of indexes to returnmin
- the lower limitmax
- the higher limitCopyright © 2021. All rights reserved.