public class ToolBox extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ToolBox.TiedRanks
Handling of tied ranks in
rank(double[], TiedRanks) . |
Constructor and Description |
---|
ToolBox() |
Modifier and Type | Method and Description |
---|---|
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 int |
getMinIndex(double[] w)
Returns the index with minimum value in a
double array. |
static int |
getMinIndex(int start,
int end,
double[] w)
Returns the index with minimum 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 |
mean(int start,
int end,
double[] array)
This method returns the mean 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 median 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 int[] |
order(double[] values,
boolean descending)
This method computes the order of the elements to obtain a sorted array.
|
static <K> Hashtable<K,Integer> |
parseHashSet2IndexHashtable(HashSet<K> set)
|
static double |
pearsonCorrelation(double[] v1,
double[] v2)
The method computes the Pearson correlation of two vectors.
|
static double |
pearsonCorrelation(double[] v1,
double[] v2,
double[] w)
Computes the Pearson correlation of two vectors with weights on the individual entries.
|
static double |
pearsonCorrelation(double[] v1,
double[] v2,
int off1,
int off2)
The method computes the Pearson correlation of two vectors beginning at specific offsets.
|
static double |
pearsonCorrelation(double[] v1,
double[] v2,
int off1,
int off2,
int length)
The method computes the Pearson correlation of two vectors beginning at specific offsets and using a given number of entries.
|
static double |
percentile(double[] array,
double percent)
Returns the
percent percentile of the array, i.e.,
returns the element at percent*(array.length) of the sorted array. |
static double |
percentile(int start,
int end,
double[] array,
double percent)
Returns the
percent percentile of the array between start and end, i.e.,
returns the element at percent*(end-start) of the sorted sub-array. |
static double[] |
permute(double[] values)
Creates and returns a permutation of the values in
values . |
static double[] |
permute(double[] values,
double[] permutation)
Creates a new permutation of the values in
values . |
static int[] |
rank(double[] values,
boolean sameRank)
Ranks the values in
values , where the greatest value obtains the lowest rank. |
static int[] |
rank(double[] values,
ToolBox.TiedRanks ties)
Ranks the values in
values , where the greatest value obtains the lowest rank. |
static double |
sd(int start,
int end,
double[] array)
This method returns the standard deviation of the elements of an
array
between start and end . |
static void |
sortAlongWith(double[] arrayToBeSorted,
double[]... alongWith)
This method implements a sort algorithm on the array
arrayToBeSorted . |
static double |
spearmanCorrelation(double[] v1,
double[] v2)
The method computes the Spearman correlation of two vectors.
|
static double |
spearmanCorrelation(double[] v1,
double[] v2,
double[] w)
Computes the Spearman correlation of two vectors with weights on the individual entries.
|
static int |
sum(boolean[] bools)
Counts the number of
true values in bools (similar to sum on booleans in R). |
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 String |
toString(double[] array,
NumberFormat nf)
This methods returns a
String representation of a double array using the specified NumberFormat . |
static double[][] |
transpose(double[][] sp)
Transpose a
double matrix. |
static double |
weightPercentile(double[] array,
double percent)
Returns the element in the sorted variant of
array (considered in descending order)
that yields percent of the cumulative value of array elements. |
public static <K> Hashtable<K,Integer> parseHashSet2IndexHashtable(HashSet<K> set)
HashSet
in a Hashtable
with unique indices starting at 0.
The indices are derived from the order of the Iterator
of the HashSet
.K
- the type of the keysset
- the set of keysHashtable
with keys and unique indices starting at 0public static double max(double... array)
array
.array
- the array of valuespublic static double min(double... array)
array
.array
- the array of valuespublic static double max(int start, int end, double[] array)
array
between start
and end
.start
- start position (inclusive)end
- end position (exclusive)array
- the array of valuespublic static double min(int start, int end, double[] array)
array
between start
and end
.start
- start position (inclusive)end
- end position (exclusive)array
- the array of valuespublic static final int getMaxIndex(double[] w)
double
array.w
- the given double
arraypublic static final int getMaxIndex(int start, int end, double[] w)
double
array.w
- the given double
arraystart
- start position (inclusive)end
- end position (exclusive)public static double median(double... array)
array
.array
- the array of valuespublic static double median(int start, int end, double[] array)
array
between start
and end
.start
- start position (inclusive)end
- end position (exclusive)array
- the array of valuespublic static double mean(int start, int end, double[] array)
array
between start
and end
.start
- start position (inclusive)end
- end position (exclusive)array
- the array of valuespublic static double sd(int start, int end, double[] array)
array
between start
and end
.start
- start position (inclusive)end
- end position (exclusive)array
- the array of valuespublic static double percentile(double[] array, double percent)
percent
percentile of the array, i.e.,
returns the element at percent*(array.length)
of the sorted array.array
- the arraypercent
- the percentagepublic static double percentile(int start, int end, double[] array, double percent)
percent
percentile of the array between start and end, i.e.,
returns the element at percent*(end-start)
of the sorted sub-array.start
- the first index to considerend
- the end index (exclusive)array
- the arraypercent
- the percentagepublic static double weightPercentile(double[] array, double percent)
array
(considered in descending order)
that yields percent
of the cumulative value of array elements.array
- the arraypercent
- the percentagepublic static final int[] rank(double[] values, boolean sameRank)
values
, where the greatest value obtains the lowest rank.
The boolean sameRank
allows to decide whether tied values should obtain the same rank.values
- the valuessameRank
- a switch whether tied values obtain the same rank.public static final int[] order(double[] values, boolean descending)
values
- the arraydescending
- a switch whether the array should be sorted ascending or descendingpublic static final int[] rank(double[] values, ToolBox.TiedRanks ties)
values
, where the greatest value obtains the lowest rank.
The enum ties
allows to choose how tied ranks are handled.values
- the valuesties
- a switch how to handle tied ranksToolBox.TiedRanks
public static double spearmanCorrelation(double[] v1, double[] v2) throws Exception
v1
- the first vectorv2
- the second vectorException
- if the vectors have different lengthpublic static double spearmanCorrelation(double[] v1, double[] v2, double[] w) throws Exception
v1
- the first vectorv2
- the second vectorw
- the weights of the paired elements in v1
and v2
Exception
- if the vectors have different lengthpublic static double pearsonCorrelation(double[] v1, double[] v2) throws Exception
v1
- the first vectorv2
- the second vectorException
- if the vectors have different lengthpublic static double pearsonCorrelation(double[] v1, double[] v2, double[] w) throws Exception
v1
- the first vectorv2
- the second vectorw
- the weights of the paired elements in v1
and v2
Exception
- if the vectors have different lengthpublic static double pearsonCorrelation(double[] v1, double[] v2, int off1, int off2) throws Exception
v1
- the first vectorv2
- the second vectoroff1
- the offset for the first vectoroff2
- the offset for the second vectorException
- if the vectors have different lengthpublic static double pearsonCorrelation(double[] v1, double[] v2, int off1, int off2, int length) throws Exception
v1
- the first vectorv2
- the second vectoroff1
- the offset for the first vectoroff2
- the offset for the second vectorlength
- the number of elements to be used for computing the correlationException
- if the vectors have different lengthpublic static double sum(double... array)
array
array
- the arrayarray
public static double sum(int start, int end, double[] array)
array
starting at
start
until end
.start
- the index of the first element in the sum (inclusive)end
- the end index (exclusive)array
- the arrayarray
from start
to end
public static double[][] transpose(double[][] sp) throws Exception
double
matrix.sp
- the arrayException
- if sp
is no matrixpublic static double[] getUniqueHueValues(int number)
number
- the number of colorspublic static void sortAlongWith(double[] arrayToBeSorted, double[]... alongWith)
arrayToBeSorted
.
However, the entries of the array alongWith
are reordered in the same way asarrayToBeSorted
.arrayToBeSorted
- the array to be sortedalongWith
- a series of arrays that is in the same way reordered as arrayToBeSorted
.Arrays.sort(Object[], Comparator)
,
DoubleArrayComparator
public static String toString(double[] array, NumberFormat nf)
String
representation of a double array using the specified NumberFormat
.array
- the array to be representednf
- the NumberFormat
to be usedString
representationpublic static double[] permute(double[] values)
values
.values
- the valuespublic static double[] permute(double[] values, double[] permutation)
values
. If the array supplied as
permutation
has the same dimension as values
and is not null
,
the values are returned in this array (and, additionally, as return value), which may save memory
in multiple successive calls to this method.values
- the valuespermutation
- the permutation (may be null
)public static int sum(boolean[] bools)
true
values in bools
(similar to sum on booleans in R).bools
- the boolean valuestrue
spublic static int getMinIndex(double[] w)
double
array.w
- the given double
arraypublic static int getMinIndex(int start, int end, double[] w)
double
array.w
- the given double
arraystart
- start position (inclusive)end
- end position (exclusive)