Package unifeat.util

Class MathFunc

java.lang.Object
unifeat.util.MathFunc

public final class MathFunc extends Object
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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[][]
    computeAverageArray(double[][] array)
    Calculates the average values of all columns
    static double[][]
    computeErrorRate(double[][] accuracy)
    Calculates the error rate values based on the array of accuracies
    static 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 coefficient
    static double
    computeSimilarity(double[][] data, int index1, int index2)
    Computes the similarity value between two features using cosine similarity
    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
    static 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 value
    static int
    findMinimumIndex(double[] array)
    Finds the minimum value of the input array and returns its index
    static double
    findMinimumValue(double[] array)
    Finds the minimum value of the input array
    static 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 not
    static boolean
    Checks whether the input string is an integer value or not
    static double
    log2(double x)
    Returns the base 2 logarithm of a double value
    static double[][]
    multMatrix(double[][] matrix1, double[][] matrix2)
    Computes the multiple of two matrices
    static double[]
    normalizeVector(double[] vector)
    Normalizes values of the vector
    static void
    randomize(double[][] array)
    Shuffles a given array using Fisher–Yates shuffle Algorithm
    static <T> void
    randomize(T[] array)
    Shuffles a given array using Fisher–Yates shuffle Algorithm
    static String
    roundDouble(double num, int numFloatPoint)
    Rounds the argument value to a double value with given number of floating-point
    static double[][]
    subMatrix(double[][] matrix1, double[][] matrix2)
    Computes the subtract of two matrices
    static double
    sum(double[] array)
    Computes the sum of the elements of input array
    static 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 array
    static 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 secondIndex
    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
    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
    static double[][]
    transMatrix(double[][] matrix)
    Computes the transpose of the input matrix

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static boolean isInteger(String input)
      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

      public static boolean isDouble(String input)
      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

      public static String roundDouble(double num, int numFloatPoint)
      Rounds the argument value to a double value with given number of floating-point
      Parameters:
      num - a floating-point value
      numFloatPoint - 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 array
      start - the first index of the input array
      end - 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 array
      start - the first index of the input array
      end - 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 data
      index - 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 data
      mean - the mean value of the data corresponding to a given column
      index - 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 data
      mean - the mean value of the data corresponding to a given column
      index - the index of the given column
      denominatorValue - 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 data
      mean - the mean value of the data corresponding to a given column
      index - the index of the given column
      denominatorValue - 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 data
      index1 - the index of the first feature
      index2 - 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 data
      index1 - the index of the first feature
      index2 - 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 matrix
      matrix2 - 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 matrix
      matrix2 - 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 array
      firstIndex - the first index of the input array
      secondIndex - 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 array
      firstIndex - the first index of the input array
      secondIndex - 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 array
      firstIndex - the first index of the input array
      secondIndex - 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 interval
      end - the end number of the interval
      Returns:
      a generated random number in the specific interval
    • generateRandNum

      public 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.
      Parameters:
      start - the beginning number of the interval
      end - the end number of the interval
      rand - the Random class for generating number
      Returns:
      a generated random double number in the specific interval
    • generateRandNum

      public 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.
      Parameters:
      start - the beginning number of the interval
      end - the end number of the interval
      rand - the Random class for generating number
      Returns:
      a generated random integer number in the specific interval