be.ac.ulb.mlg.utils
Class MeasureUtils

java.lang.Object
  extended by be.ac.ulb.mlg.utils.MeasureUtils

public final class MeasureUtils
extends Object


Field Summary
static double EPSILON
          The precision value
 
Constructor Summary
MeasureUtils()
           
 
Method Summary
static void bubbleSort(double[] comparable, int[] toSort)
          Apply bubble sort to sort indices (toSort) array based on the values (comparable) array which is also sorted
static boolean[] constructComputable(double[][] vars)
          Compute the missing value array for the matrix (samples x vars)
static long countOccurencies(double[][] vectors, double[] frequencies, boolean[] computable)
          Compute the number of occurrences of each distinct value with a precision of EPSILON (consider integers).
static long countOccurencies(double[] vector, double[] frequencies, boolean hasMissing)
          Compute the number of occurrences of each distinct value with a precision of EPSILON (consider integers).
static double fastMean(double[] vector, boolean hasMissing)
          Compute the mean by summing all elements of the vector in left-right manner
static double fastMean(double[] vector, boolean[] computable)
          Compute the mean by summing all elements of the vector in left-right manner
static double fastSum(double[] vector, boolean[] computable)
          Compute the sum by summing all elements of the vector in left-right manner
static double log(double value)
          Compute the log, base e but return 0 if the value is less than EPSILON
static int naturalRank(boolean[] computable, double[] vector, double[] ranks)
          Computed the natural rank of values
static int naturalRank(boolean[] computable, double[] vector, double[] ranks, int[] untied)
          Computed the natural rank of values
static double sqrt(double value)
          Compute the square root value by using the formula exp(0.5*log(x)) <=> sqrt(x) in order to avoid underflow.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EPSILON

public static final double EPSILON
The precision value

See Also:
Constant Field Values
Constructor Detail

MeasureUtils

public MeasureUtils()
Method Detail

fastSum

public static final double fastSum(double[] vector,
                                   boolean[] computable)
Compute the sum by summing all elements of the vector in left-right manner

Parameters:
vector - The data vector
computable - The boolean array which specifies if indexes must be taken
Returns:
The mean of the data vector

fastMean

public static final double fastMean(double[] vector,
                                    boolean[] computable)
Compute the mean by summing all elements of the vector in left-right manner

Parameters:
vector - The data vector
computable - The boolean array which specifies if indexes must be taken
Returns:
The mean of the data vector

fastMean

public static final double fastMean(double[] vector,
                                    boolean hasMissing)
Compute the mean by summing all elements of the vector in left-right manner

Parameters:
vector - The data vector
hasMissing - True if missing values are contained in the vector
Returns:
The mean of the data vector

bubbleSort

public static void bubbleSort(double[] comparable,
                              int[] toSort)
Apply bubble sort to sort indices (toSort) array based on the values (comparable) array which is also sorted

Parameters:
comparable - The value array
toSort - The indices array

naturalRank

public static int naturalRank(boolean[] computable,
                              double[] vector,
                              double[] ranks)
Computed the natural rank of values

Parameters:
computable - The boolean array which specifies if indexes must be taken
vector - The data vector (values) to rank
ranks - The rank destination vector (must have the same size that the vector argument)
Returns:
The number of tied values

naturalRank

public static int naturalRank(boolean[] computable,
                              double[] vector,
                              double[] ranks,
                              int[] untied)
Computed the natural rank of values

Parameters:
computable - The boolean array which specifies if indexes must be taken
vector - The data vector (values) to rank
ranks - The rank destination vector (must have the same size that the vector argument)
untied - Copy the natural rank attribution without dealing with ties (sort index from 1 to length)
Returns:
The number of tied values

constructComputable

public static boolean[] constructComputable(double[][] vars)
Compute the missing value array for the matrix (samples x vars)

Parameters:
vars - The matrix
Returns:
The missing value array: true if computable, false if missing

countOccurencies

public static final long countOccurencies(double[] vector,
                                          double[] frequencies,
                                          boolean hasMissing)
Compute the number of occurrences of each distinct value with a precision of EPSILON (consider integers).

Parameters:
vector - The vector of values
frequencies - The occurrences matrix, 0 for NaN if hasMissing is true, 0 for redundant value (because n times a same distinct value result in a occurrence value of n)
hasMissing - if true, check for missing value in order to ignore them
Returns:
The number of distinct values for the first part of the long (<<32) and the number of values for the second part, (avoiding missing if hasMissing)

countOccurencies

public static final long countOccurencies(double[][] vectors,
                                          double[] frequencies,
                                          boolean[] computable)
Compute the number of occurrences of each distinct value with a precision of EPSILON (consider integers).

Parameters:
vectors - The matrix of values, have to be composed of two vectors of the same size
frequencies - The occurrences matrix, 0 for NaN if hasMissing is true, 0 for redundant value (because n times a same distinct value result in a occurrence value of n)
computable - The vector of missing value for the vector indexes
Returns:
The number of distinct values for the first part of the long (<<32) and the number of values for the second part, (avoiding missing if hasMissing)

sqrt

public static double sqrt(double value)
Compute the square root value by using the formula exp(0.5*log(x)) <=> sqrt(x) in order to avoid underflow.

Parameters:
value - The value for which the function compute the square root
Returns:
The square root of the given value

log

public static double log(double value)
Compute the log, base e but return 0 if the value is less than EPSILON

Parameters:
value - The value for which the function compute the square root
Returns:
The square root of the given value