de.jstacs.utils
Class ToolBox

java.lang.Object
  extended by de.jstacs.utils.ToolBox

public class ToolBox
extends Object

This class is a collection of methods which might be useful for the programmer.

Author:
Jens Keilwagen, Jan Grau

Constructor Summary
ToolBox()
           
 
Method Summary
static int getMaxIndex(double[] w)
          Returns the index with maximal value in a double array.
static int getMaxIndex(int start, int end, double[] w)
          Returns the index with maximal value in a double array.
static double[] getUniqueHueValues(int number)
          Creates an array of hue values that can be used for the representation of probabilities.
static double max(double... array)
          This method returns the maximum of the elements of an array.
static double max(int start, int end, double[] array)
          This method returns the maximum of the elements of an array between start and end.
static double median(double... array)
          This method returns the median of the elements of array.
static double median(int start, int end, double[] array)
          This method returns the medin of the elements of an array between start and end.
static double min(double... array)
          This method returns the minimum of the elements of an array.
static double min(int start, int end, double[] array)
          This method returns the minimum of the elements of an array between start and end.
static
<K> Hashtable<K,Integer>
parseHashSet2IndexHashtable(HashSet<K> set)
          This method converts a HashSet in a Hashtable with unique indices starting at 0.
static double pearsonCorrelation(double[] v1, double[] v2)
          The method computes the Pearson correlation of two vectors.
static int[] rank(double[] values, boolean sameRank)
          Ranks the values in values, where the greatest value obtains the lowest rank.
static double spearmanCorrelation(double[] v1, double[] v2)
          The method computes the Spearman correlation of two vectors.
static double sum(double... array)
          Computes the sum of the values in array
static double sum(int start, int end, double[] array)
          Computes the sum of the values in array starting at start until end.
static double[][] transpose(double[][] sp)
          Transpose a double matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolBox

public ToolBox()
Method Detail

parseHashSet2IndexHashtable

public static <K> Hashtable<K,Integer> parseHashSet2IndexHashtable(HashSet<K> set)
This method converts a HashSet in a Hashtable with unique indices starting at 0. The indices are derived from the order of the Iterator of the HashSet.

Type Parameters:
K - the type of the keys
Parameters:
set - the set of keys
Returns:
a Hashtable with keys and unique indices starting at 0

max

public static double max(double... array)
This method returns the maximum of the elements of an array.

Parameters:
array - the array of values
Returns:
the maximum

min

public static double min(double... array)
This method returns the minimum of the elements of an array.

Parameters:
array - the array of values
Returns:
the minimum

max

public static double max(int start,
                         int end,
                         double[] array)
This method returns the maximum of the elements of an array between start and end.

Parameters:
start - start position (inclusive)
end - end position (exclusive)
array - the array of values
Returns:
the maximum

min

public static double min(int start,
                         int end,
                         double[] array)
This method returns the minimum of the elements of an array between start and end.

Parameters:
start - start position (inclusive)
end - end position (exclusive)
array - the array of values
Returns:
the minimum

getMaxIndex

public static final int getMaxIndex(double[] w)
Returns the index with maximal value in a double array.

Parameters:
w - the given double array
Returns:
the index

getMaxIndex

public static final int getMaxIndex(int start,
                                    int end,
                                    double[] w)
Returns the index with maximal value in a double array.

Parameters:
w - the given double array
start - start position (inclusive)
end - end position (exclusive)
Returns:
the index

median

public static double median(double... array)
This method returns the median of the elements of array.

Parameters:
array - the array of values
Returns:
the median

median

public static double median(int start,
                            int end,
                            double[] array)
This method returns the medin of the elements of an array between start and end.

Parameters:
start - start position (inclusive)
end - end position (exclusive)
array - the array of values
Returns:
the median

rank

public static final int[] rank(double[] values,
                               boolean sameRank)
Ranks the values in values, where the greatest value obtains the lowest rank. The boolean sameRank allows to decide whether tied values should obtain the same rank.

Parameters:
values - the values
sameRank - a switch whether tied values obtain the same rank.
Returns:
the ranks

spearmanCorrelation

public static double spearmanCorrelation(double[] v1,
                                         double[] v2)
                                  throws Exception
The method computes the Spearman correlation of two vectors.

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
the Spearman correlation of the two vectors
Throws:
Exception - if the vectors have different length

pearsonCorrelation

public static double pearsonCorrelation(double[] v1,
                                        double[] v2)
                                 throws Exception
The method computes the Pearson correlation of two vectors.

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
the Pearson correlation of the two vectors
Throws:
Exception - if the vectors have different length

sum

public static double sum(double... array)
Computes the sum of the values in array

Parameters:
array - the array
Returns:
the sum of the elements in array

sum

public static double sum(int start,
                         int end,
                         double[] array)
Computes the sum of the values in array starting at start until end.

Parameters:
start - the index of the first element in the sum (inclusive)
end - the end index (exclusive)
array - the array
Returns:
the sum of the elements in array from start to end

transpose

public static double[][] transpose(double[][] sp)
                            throws Exception
Transpose a double matrix.

Parameters:
sp - the array
Returns:
the transposed array
Throws:
Exception - if sp is no matrix

getUniqueHueValues

public static double[] getUniqueHueValues(int number)
Creates an array of hue values that can be used for the representation of probabilities. The first four hues are always equal to those of the sequence-logo colors.

Parameters:
number - the number of colors
Returns:
the hue values