|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmckay.utilities.staticlibraries.MathAndStatsMethods
public class MathAndStatsMethods
A holder class for static methods relating to statistical and mathematical analysis.
Constructor Summary | |
---|---|
MathAndStatsMethods()
|
Method Summary | |
---|---|
static double |
calculateEuclideanDistance(double[] x,
double[] y)
Returns the Euclidian distance between x and y. |
static int |
ensureIsPowerOfN(int x,
int n)
If the given x is a power of the given n, then x is returned. |
static int |
generateRandomNumber(int max)
Returns a random integer from 0 to max - 1, based on the uniform distribution. |
static double |
getArraySum(double[] to_sum)
Returns the sum of the contents of all of the entries of the given array. |
static double |
getAverage(double[] data)
Returns the average of a set of doubles. |
static double |
getAverage(int[] data)
Returns the average of a set of ints. |
static long |
getFactorial(long n)
Calculates the factorial of the given value. |
static int |
getIndexOfLargest(double[] values)
Returns the index of the entry of an array of doubles with the largest value. |
static int |
getIndexOfLargest(float[] values)
Returns the index of the entry of an array of floats with the largest value. |
static int |
getIndexOfLargest(int[] values)
Returns the index of the entry of an array of itegers with the largest value. |
static int |
getIndexOfMedian(double[] values)
Returns the index of the entry of an array of doubles that corresponds. |
static int |
getIndexOfSmallest(double[] values)
Returns the index of the entry of an array of doubles with the smallest value. |
static int |
getIndexOfSmallest(int[] values)
Returns the index of the entry of an array of doubles with the smallest value. |
static int |
getNumberPerumutations(int set_size,
int permutation_size)
Calculates the number of permutations of the given parameters without replacement. |
static double |
getPercentage(int value,
int total)
Returns the percentage of the given total that the given value represents. |
static int[] |
getRandomOrdering(int number_entries)
Returns an array number_entries arrays. |
static double |
getStandardDeviation(double[] data)
Returns the standard deviation of a set of doubles. |
static double |
getStandardDeviation(int[] data)
Returns the standard deviation of a set of ints. |
static boolean |
isFactorOrMultiple(int x,
int y,
int[] z)
Returns whether or not x is either a factor or a multiple of y. |
static double |
logBaseN(double x,
double n)
Returns the logarithm of the specified base of the given number. |
static double[] |
normalize(double[] to_normalize)
Return a normalized copy of the the given array. |
static double[][] |
normalize(double[][] to_normalize)
Return a normalized copy of the the given array. |
static double[][] |
normalizeEntirely(double[][] to_normalize)
Return a normalized copy of the the given array. |
static int |
pow(int a,
int b)
Returns the given a raised to the power of the given b. |
static int[] |
removeRedundantEntries(int[] to_check)
Returns a copy of the given array, but with any duplicate entries removed (e.g. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathAndStatsMethods()
Method Detail |
---|
public static double getPercentage(int value, int total)
value
- The numerator in the percentage calculation.total
- The denominator in the percentage calculation.
public static double getAverage(double[] data)
data
- The data to be averaged.
public static double getAverage(int[] data)
data
- The data to be averaged.
public static double getStandardDeviation(double[] data)
data
- The data for which the standard deviation is to be
found.
public static double getStandardDeviation(int[] data)
data
- The data for which the standard deviation is to be
found.
public static long getFactorial(long n) throws java.lang.Exception
n
- The number to find the factorial of.
java.lang.Exception
- Throws an informative exception if n is below 0
or greater than 20.public static int getIndexOfSmallest(double[] values)
public static int getIndexOfSmallest(int[] values)
public static int getIndexOfMedian(double[] values)
public static int getIndexOfLargest(float[] values)
public static int getIndexOfLargest(double[] values)
public static int getIndexOfLargest(int[] values)
public static int[] removeRedundantEntries(int[] to_check)
to_check
- The array to remove double entries from.
public static double calculateEuclideanDistance(double[] x, double[] y) throws java.lang.Exception
java.lang.Exception
public static int generateRandomNumber(int max)
public static int[] getRandomOrdering(int number_entries)
public static double getArraySum(double[] to_sum)
public static double[] normalize(double[] to_normalize)
public static double[][] normalize(double[][] to_normalize)
public static double[][] normalizeEntirely(double[][] to_normalize)
public static int pow(int a, int b)
IMPORTANT: b must be greater than zero.
a
- The base.b
- The exponent.public static double logBaseN(double x, double n)
IMPORTANT: Both x and n must be greater than zero.
x
- The value to find the log of.n
- The base of the logarithm.public static int ensureIsPowerOfN(int x, int n)
IMPORTANT: Both x and n must be greater than zero.
x
- The value to ensure is a power of n.n
- The power to base x's validation on.public static int getNumberPerumutations(int set_size, int permutation_size) throws java.lang.Exception
For example, if one wishes to find the number of ordered ways that the letters C, A and T can be combined into a set of size 2, then the set_size paramter would be 3 (because there are three letters in the alphabet being used) and the permutation_size parameter would be 2.
set_size
- The number of entries in the alphabet
that can be used to construct
permutations.permutation_size
- The size of the permutation sets to
considered.
java.lang.Exception
- An informative Exception is thrown if
set_size is greater than 20, as this
would necessitate the calculation of an
overly large factorial. An Exception is
also thrown if permutation_size is
greater than set_size.public static boolean isFactorOrMultiple(int x, int y, int[] z)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |