|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.umbc.cs.maple.utils.MathUtils
public class MathUtils
A collection of mathematical utility functions.
Copyright (c) 2008 Eric Eaton
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
| Nested Class Summary | |
|---|---|
static class |
MathUtils.SimilarityMetric
Defines a similarity metric measure |
| Constructor Summary | |
|---|---|
MathUtils()
|
|
| Method Summary | ||
|---|---|---|
static double[] |
append(double[] v1,
double d)
Appends an element to a vector. |
|
static double[] |
append(double[] v1,
double[] v2)
Appends two vectors. |
|
static int[] |
append(int[] v1,
int d)
Appends an element to a vector. |
|
static int[] |
append(int[] v1,
int[] v2)
Appends two vectors. |
|
static double[] |
arrayAdd(double[] d1,
double[] d2)
Adds corresponding elements of two arrays. |
|
static double[] |
arrayDivide(double[] d1,
double denominator)
Divides each element of an array by a number. |
|
static double |
capValue(double value,
double minValue,
double maxValue)
Caps a value to a given range. |
|
static int |
capValue(int value,
int minValue,
int maxValue)
Caps a value to a given range. |
|
static double |
computeSimilarity(int[] targetV,
int[] v,
MathUtils.SimilarityMetric similarityMetric)
Computes the similarity of the two vectors. |
|
static double |
correlation(double[] p,
double[] q)
Computes the correlation between two arrays of the same length, p and q. |
|
static double |
correlation(int[] p,
int[] q)
Computes the correlation between two arrays of the same length, p and q. |
|
static double[][] |
getConfusionMatrix(int[] p,
int[] q)
Computes the normalized confusion matrix for two vectors. |
|
static double |
getMachinePrecision()
Gets the computed machine precision. |
|
static java.util.Random |
getRandomGenerator()
Retrieves the initialized random number generator. |
|
static void |
initializeRandomGenerator(long seed)
Initializes a random number generator with the given seed. |
|
static boolean |
isApproxEqual(double value1,
double value2)
Determines whether two numbers are approximately equal according to the machine precision. |
|
static boolean |
isApproxEqual(double value1,
double value2,
double precision)
Determines whether two numbers are approximately equal according to the precision. |
|
static double |
log2(double d)
Computes the log-base-2 of a number. |
|
static void |
main(java.lang.String[] args)
|
|
static int |
maxIndex(double[] v)
Gets the index of the maximum element in the array. |
|
static int |
maxIndex(int[] v)
Gets the index of the maximum element in the array. |
|
static int |
maxIndexRand(double[] v)
Gets the index of the maximum element in the array. |
|
static int |
maxIndexRand(int[] v)
Gets the index of the maximum element in the array. |
|
static double |
maxValue(double[] values)
Computes the maximum value in the given array. |
|
static int |
maxValue(int[] values)
Computes the maximum value in the given array. |
|
static double |
mean(double[] values)
Computes the mean of the values in the given array. |
|
static double |
mean(int[] values)
Computes the mean of the values in the given array. |
|
static int |
minIndex(double[] v)
Gets the index of the minimum element in the array. |
|
static int |
minIndex(int[] v)
Gets the index of the minimum element in the array. |
|
static int |
minIndexRand(double[] v)
Gets the index of the minimum element in the array. |
|
static int |
minIndexRand(int[] v)
Gets the index of the minimum element in the array. |
|
static double |
minValue(double[] values)
Computes the minimum value in the given array. |
|
static int |
minValue(int[] values)
Computes the minimum value in the given array. |
|
static double |
mutualInformation(int[] p,
int[] q)
Computes the mutual information between two vectors. |
|
static double |
nextRandomGaussian(double mean,
double stdev)
Gets a random number from a one dimensional Gaussian distribution with the given mean and variance. |
|
static double |
nextRandomGaussian(java.util.Random randGenerator,
double mean,
double stdev)
Gets a random number from a one dimensional Gaussian distribution with the given mean and variance. |
|
static double |
pairwiseAgreement(int[] p,
int[] q)
Computes the pairwise agreement between two pairwise arrays of labelings. |
|
static int[] |
permutation(int n)
Generates a random permutation of the numbers {0, ..., n-1} |
|
static int[] |
permutation(int n,
java.util.Random rand)
Generates a random permutation of the numbers {0, ..., n-1} |
|
static void |
rangeCheck(double value,
double min,
double max)
Throws an exception whenever a value falls outside the given range. |
|
static void |
rangeCheck(int value,
int min,
int max)
Throws an exception whenever a value falls outside the given range. |
|
static double[] |
reverse(double[] array)
Reverses the given array. |
|
static int[] |
reverse(int[] array)
Reverses the given array. |
|
static int[] |
reverseCuthillMcKee(int[][] adjacencyLists,
boolean runTwiceForOptimalResult)
Runs the reverse Cuthill-McKee algorithm on the adjacency lists to provide an efficient ordering of the vertices |
|
static double |
rmse(double[] a,
double[] b)
Computes the root mean squared error between two vectors. |
|
static double |
round(double d,
int decimalPlacesRequired)
Reduces the precision of a double to a specified number of decimal places. |
|
static int |
roundToMultiple(int value,
int multipleOf)
Rounds a value to the nearest number that is a specific multiple. |
|
static
|
sampleWithoutReplacement(T[] objs,
double[] probabilityDistribution,
int numSamples)
Samples from a set of weighted objects without replacement. |
|
static
|
sampleWithReplacement(T[] objs,
double[] probabilityDistribution,
int numSamples)
Samples from a set of weighted objects with replacement. |
|
static int[] |
sortOrder(double[] values)
Sorts the given values and returns the order of the original indices. |
|
static int[] |
sortOrder(int[] values)
Sorts the given values and returns the order of the original indices. |
|
static double |
sum(double[] values)
Sums the values in the given array. |
|
static int |
sum(int[] values)
Sums the values in the given array. |
|
static double[] |
uniqueValues(double[] v)
Determines the unique values of v. |
|
static int[] |
uniqueValues(int[] v)
Determines the unique values of v. |
|
static double[] |
vectorAdd(double[] v1,
double[] v2)
Performs vector addition. |
|
static double |
vectorL2Norm(double[] v)
Computes the L2 norm of the given vector. |
|
static double[] |
vectorMultiply(double s,
double[] v)
Performs scalar multiplication on a vector. |
|
static double[] |
vectorNormalize(double[] v)
Normalizes the given vector. |
|
static double[] |
vectorSubtract(double[] v1,
double[] v2)
Performs vector subtraction. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MathUtils()
| Method Detail |
|---|
public static int[] reverseCuthillMcKee(int[][] adjacencyLists,
boolean runTwiceForOptimalResult)
adjacencyLists - a list of the adjacency lists of the graphrunTwiceForOptimalResult - whether to run the algorithm twice to get the optimal result
public static int[] permutation(int n)
n - the length of the set of numbers to permute
public static int[] permutation(int n,
java.util.Random rand)
n - the length of the set of numbers to permuterand - the random number generator
public static int[] append(int[] v1,
int d)
v1 - the vector.d - the element to append.
public static double[] append(double[] v1,
double d)
v1 - the vector.d - the element to append.
public static double[] append(double[] v1,
double[] v2)
v1 - the first vector.v2 - the second vector.
public static int[] append(int[] v1,
int[] v2)
v1 - the first vector.v2 - the second vector.
public static double[] vectorAdd(double[] v1,
double[] v2)
v1 - the first vector.v2 - the second vector.
public static double[] vectorSubtract(double[] v1,
double[] v2)
v1 - the first vector.v2 - the second vector.
public static double[] vectorMultiply(double s,
double[] v)
s - a scalar value.v - the vector.
public static double vectorL2Norm(double[] v)
v - the vector.
public static double[] vectorNormalize(double[] v)
v - the vector.
public static java.util.Random getRandomGenerator()
public static void initializeRandomGenerator(long seed)
seed - the seed for the random generator.
public static double nextRandomGaussian(double mean,
double stdev)
mean - the mean of the Gaussianstdev - the standard deviation of the Gaussian
public static double nextRandomGaussian(java.util.Random randGenerator,
double mean,
double stdev)
randGenerator - the random generator.mean - the mean of the Gaussianstdev - the standard deviation of the Gaussian
public static double rmse(double[] a,
double[] b)
a - b -
public static void main(java.lang.String[] args)
public static <T> java.util.Collection<T> sampleWithoutReplacement(T[] objs,
double[] probabilityDistribution,
int numSamples)
objs - the array of objectsprobabilityDistribution - the probability distribution over the set of objects (i.e. the weight assigned to each object)numSamples - the desired number of samples
public static <T> java.util.Collection<T> sampleWithReplacement(T[] objs,
double[] probabilityDistribution,
int numSamples)
objs - the array of objectsprobabilityDistribution - the probability distribution over the set of objects (i.e. the weight assigned to each object)numSamples - the desired number of samples
public static double capValue(double value,
double minValue,
double maxValue)
value - the value to constrain.minValue - the min value.maxValue - the max value.
public static int capValue(int value,
int minValue,
int maxValue)
value - the value to constrain.minValue - the min value.maxValue - the max value.
public static void rangeCheck(int value,
int min,
int max)
value - min - the minimal valuemax - the maximal value
java.lang.IllegalArgumentException - if the value is outside of the given range.
public static void rangeCheck(double value,
double min,
double max)
value - min - the minimal valuemax - the maximal value
java.lang.IllegalArgumentException - if the value is outside of the given range.
public static final double round(double d,
int decimalPlacesRequired)
d - number to reduce precisiondecimalPlacesRequired - the number of required decimal places
public static final int roundToMultiple(int value,
int multipleOf)
value - the value to roundmultipleOf - the value that the final number should be a multiple of.
public static int minIndex(double[] v)
v -
public static int minIndex(int[] v)
v -
public static int minIndexRand(double[] v)
v -
public static int minIndexRand(int[] v)
v -
public static int maxIndex(double[] v)
v -
public static int maxIndex(int[] v)
v -
public static int maxIndexRand(double[] v)
v -
public static int maxIndexRand(int[] v)
v -
public static int maxValue(int[] values)
values -
public static double maxValue(double[] values)
values -
public static double minValue(double[] values)
values -
public static int minValue(int[] values)
values -
public static double mean(double[] values)
values -
public static double mean(int[] values)
values -
public static double sum(double[] values)
values -
public static int sum(int[] values)
values -
public static double[] arrayAdd(double[] d1,
double[] d2)
d1 - the first arrayd2 - the second array
public static double[] arrayDivide(double[] d1,
double denominator)
d1 - the first arraydenominator - the denominator for the devision
public static int[] sortOrder(int[] values)
values - the values to sort
public static int[] sortOrder(double[] values)
values - the values to sort
public static int[] reverse(int[] array)
array -
public static double[] reverse(double[] array)
array -
public static double getMachinePrecision()
public static boolean isApproxEqual(double value1,
double value2)
value1 - value2 -
public static boolean isApproxEqual(double value1,
double value2,
double precision)
value1 - value2 - precision -
public static double correlation(int[] p,
int[] q)
public static double correlation(double[] p,
double[] q)
public static double pairwiseAgreement(int[] p,
int[] q)
p - An array of labels.q - An array of labels.
public static int[] uniqueValues(int[] v)
v -
public static double[] uniqueValues(double[] v)
v -
public static double[][] getConfusionMatrix(int[] p,
int[] q)
p - the first vectorq - the second vector
public static double mutualInformation(int[] p,
int[] q)
p - the first vector.q - the second vector.
public static double computeSimilarity(int[] targetV,
int[] v,
MathUtils.SimilarityMetric similarityMetric)
targetV - the target vector that forms the basis for comparison.v - the vector for comparisonsimilarityMetric - the metric to use for computing the similarity
public static double log2(double d)
d -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||