Package unifeat.util
Class MathFunc
java.lang.Object
unifeat.util.MathFunc
This java class is used to implement various utility methods for performing
basic statistical operation such as the mean and variance.
Also, some numeric operation on the matrices are provides such as multiple of two matrices, subtract of two matrices, and transpose of the matrix.
The methods in this class is contained brief description of the applications.
- Author:
- Sina Tabakhi
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]
computeAverageArray
(double[][] array) Calculates the average values of all columnsstatic double[][]
computeErrorRate
(double[][] accuracy) Calculates the error rate values based on the array of accuraciesstatic double
computeMean
(double[][] data, int index) Computes the mean value of the data corresponding to a given column (column index)static double
computePearsonCorCoef
(double[][] data, int index1, int index2) Computes the correlation value between two features using Pearson correlation coefficientstatic double
computeSimilarity
(double[][] data, int index1, int index2) Computes the similarity value between two features using cosine similaritystatic double
computeStandardDeviation
(double[][] data, double mean, int index, double denominatorValue) Computes the standard deviation value of the data corresponding to a given column (column index) based on a specific denominator valuestatic double
computeVariance
(double[][] data, double mean, int index) Computes the variance value of the data corresponding to a given column (column index)static double
computeVariance
(double[][] data, double mean, int index, double denominatorValue) Computes the variance value of the data corresponding to a given column (column index) based on a specific denominator valuestatic int
findMinimumIndex
(double[] array) Finds the minimum value of the input array and returns its indexstatic double
findMinimumValue
(double[] array) Finds the minimum value of the input arraystatic double
generateRandNum
(double start, double end) Generates a random number that is drawn from a uniform distribution in a specific interval.static double
generateRandNum
(double start, double end, Random rand) Generates a random double number that is drawn from a uniform distribution in a specific interval.static int
generateRandNum
(int start, int end, Random rand) Generates a random integer number that is drawn from a uniform distribution in a specific interval.static boolean
Checks whether the input string is an double value or notstatic boolean
Checks whether the input string is an integer value or notstatic double
log2
(double x) Returns the base 2 logarithm of a double valuestatic double[][]
multMatrix
(double[][] matrix1, double[][] matrix2) Computes the multiple of two matricesstatic double[]
normalizeVector
(double[] vector) Normalizes values of the vectorstatic void
randomize
(double[][] array) Shuffles a given array using Fisher–Yates shuffle Algorithmstatic <T> void
randomize
(T[] array) Shuffles a given array using Fisher–Yates shuffle Algorithmstatic String
roundDouble
(double num, int numFloatPoint) Rounds the argument value to a double value with given number of floating-pointstatic double[][]
subMatrix
(double[][] matrix1, double[][] matrix2) Computes the subtract of two matricesstatic double
sum
(double[] array) Computes the sum of the elements of input arraystatic double
sum
(double[] array, int start, int end) Computes the sum of the elements of input array in the range of [start, end)static int
sum
(int[] array) Computes the sum of the elements of input arraystatic int
sum
(int[] array, int start, int end) Computes the sum of the elements of input array in the range of [start, end)static void
swap
(double[][] array, int firstIndex, int secondIndex) Changes the values of the two rows in the input array identified by firstIndex and secondIndexstatic void
swap
(int[] array, int firstIndex, int secondIndex) Changes the values of the two elements in the input array identified by firstIndex and secondIndexstatic <T> void
swap
(T[] array, int firstIndex, int secondIndex) Changes the values of the two elements in the input array identified by firstIndex and secondIndexstatic double[][]
transMatrix
(double[][] matrix) Computes the transpose of the input matrix
-
Constructor Details
-
MathFunc
public MathFunc()
-
-
Method Details
-
log2
public static double log2(double x) Returns the base 2 logarithm of a double value- Parameters:
x
- a value- Returns:
- the based 2 logarithm of x
-
isInteger
Checks whether the input string is an integer value or not- Parameters:
input
- input string- Returns:
- true if the input string is an integer value
-
isDouble
Checks whether the input string is an double value or not- Parameters:
input
- input string- Returns:
- true if the input string is an double value
-
roundDouble
Rounds the argument value to a double value with given number of floating-point- Parameters:
num
- a floating-point valuenumFloatPoint
- the number of floating-point of the num- Returns:
- the string value of the argument rounded with given number of floating-point
-
sum
public static double sum(double[] array) Computes the sum of the elements of input array- Parameters:
array
- the input array- Returns:
- the sum of the elements of input array
-
sum
public static int sum(int[] array) Computes the sum of the elements of input array- Parameters:
array
- the input array- Returns:
- the sum of the elements of input array
-
sum
public static double sum(double[] array, int start, int end) Computes the sum of the elements of input array in the range of [start, end)- Parameters:
array
- the input arraystart
- the first index of the input arrayend
- the second index of the input array (exclusive)- Returns:
- the sum of the elements of input array
-
sum
public static int sum(int[] array, int start, int end) Computes the sum of the elements of input array in the range of [start, end)- Parameters:
array
- the input arraystart
- the first index of the input arrayend
- the second index of the input array (exclusive)- Returns:
- the sum of the elements of input array
-
computeMean
public static double computeMean(double[][] data, int index) Computes the mean value of the data corresponding to a given column (column index)- Parameters:
data
- the input dataindex
- the index of the given column- Returns:
- the mean value of the data
-
computeAverageArray
public static double[][] computeAverageArray(double[][] array) Calculates the average values of all columns- Parameters:
array
- the input array- Returns:
- the average values of columns of the input array
-
computeVariance
public static double computeVariance(double[][] data, double mean, int index) Computes the variance value of the data corresponding to a given column (column index)- Parameters:
data
- the input datamean
- the mean value of the data corresponding to a given columnindex
- the index of the given column- Returns:
- the variance value of the data
-
computeVariance
public static double computeVariance(double[][] data, double mean, int index, double denominatorValue) Computes the variance value of the data corresponding to a given column (column index) based on a specific denominator value- Parameters:
data
- the input datamean
- the mean value of the data corresponding to a given columnindex
- the index of the given columndenominatorValue
- the denominator value of the final division- Returns:
- the variance value of the data
-
computeStandardDeviation
public static double computeStandardDeviation(double[][] data, double mean, int index, double denominatorValue) Computes the standard deviation value of the data corresponding to a given column (column index) based on a specific denominator value- Parameters:
data
- the input datamean
- the mean value of the data corresponding to a given columnindex
- the index of the given columndenominatorValue
- the denominator value of the final division- Returns:
- the standard deviation value of the data
-
computeSimilarity
public static double computeSimilarity(double[][] data, int index1, int index2) Computes the similarity value between two features using cosine similarity- Parameters:
data
- the input dataindex1
- the index of the first featureindex2
- the index of the second feature- Returns:
- the similarity value
-
computePearsonCorCoef
public static double computePearsonCorCoef(double[][] data, int index1, int index2) Computes the correlation value between two features using Pearson correlation coefficient- Parameters:
data
- the input dataindex1
- the index of the first featureindex2
- the index of the second feature- Returns:
- the Pearson correlation coefficient value
-
computeErrorRate
public static double[][] computeErrorRate(double[][] accuracy) Calculates the error rate values based on the array of accuracies- Parameters:
accuracy
- the input array from accuracies- Returns:
- the error rate values
-
multMatrix
public static double[][] multMatrix(double[][] matrix1, double[][] matrix2) Computes the multiple of two matrices- Parameters:
matrix1
- the first input matrixmatrix2
- the second input matrix- Returns:
- a matrix based on the result of the multiple of two matrices
-
subMatrix
public static double[][] subMatrix(double[][] matrix1, double[][] matrix2) Computes the subtract of two matrices- Parameters:
matrix1
- the first input matrixmatrix2
- the second input matrix- Returns:
- a matrix based on the result of the subtract of two matrices
-
transMatrix
public static double[][] transMatrix(double[][] matrix) Computes the transpose of the input matrix- Parameters:
matrix
- the input matrix- Returns:
- a matrix based on the result of the transpose of the matrix
-
findMinimumValue
public static double findMinimumValue(double[] array) Finds the minimum value of the input array- Parameters:
array
- the input array- Returns:
- a minimum value of the array
-
findMinimumIndex
public static int findMinimumIndex(double[] array) Finds the minimum value of the input array and returns its index- Parameters:
array
- the input array- Returns:
- the index of the minimum value in the array
-
swap
public static void swap(int[] array, int firstIndex, int secondIndex) Changes the values of the two elements in the input array identified by firstIndex and secondIndex- Parameters:
array
- the input arrayfirstIndex
- the first index of the input arraysecondIndex
- the second index of the input array
-
swap
public static <T> void swap(T[] array, int firstIndex, int secondIndex) Changes the values of the two elements in the input array identified by firstIndex and secondIndex- Type Parameters:
T
- type of the array- Parameters:
array
- the input arrayfirstIndex
- the first index of the input arraysecondIndex
- the second index of the input array
-
swap
public static void swap(double[][] array, int firstIndex, int secondIndex) Changes the values of the two rows in the input array identified by firstIndex and secondIndex- Parameters:
array
- the input arrayfirstIndex
- the first index of the input arraysecondIndex
- the second index of the input array
-
normalizeVector
public static double[] normalizeVector(double[] vector) Normalizes values of the vector- Parameters:
vector
- the input vector- Returns:
- the normalized values of the input vector
-
randomize
public static void randomize(double[][] array) Shuffles a given array using Fisher–Yates shuffle Algorithm- Parameters:
array
- the input array
-
randomize
public static <T> void randomize(T[] array) Shuffles a given array using Fisher–Yates shuffle Algorithm- Type Parameters:
T
- type of the input array- Parameters:
array
- the input array
-
generateRandNum
public static double generateRandNum(double start, double end) Generates a random number that is drawn from a uniform distribution in a specific interval.- Parameters:
start
- the beginning number of the intervalend
- the end number of the interval- Returns:
- a generated random number in the specific interval
-
generateRandNum
Generates a random double number that is drawn from a uniform distribution in a specific interval.- Parameters:
start
- the beginning number of the intervalend
- the end number of the intervalrand
- the Random class for generating number- Returns:
- a generated random double number in the specific interval
-
generateRandNum
Generates a random integer number that is drawn from a uniform distribution in a specific interval.- Parameters:
start
- the beginning number of the intervalend
- the end number of the intervalrand
- the Random class for generating number- Returns:
- a generated random integer number in the specific interval
-