| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfern.tools.NumberTools
public class NumberTools
Contains some common methods to handle number related data structures.
| Constructor Summary | |
|---|---|
NumberTools()
 | 
|
| Method Summary | |
|---|---|
static int | 
argMax(Map<Integer,Integer> l)
Gets the argmax of the given map.  | 
static double | 
avg(double[] a)
Gets the avg of the array  | 
static double | 
calculateHistogramDistance(Map<Integer,Integer> h1,
                           Map<Integer,Integer> h2)
Calculates the histogram distance of two histograms.  | 
static double[] | 
convertIntToDouble(int[] a)
Performs a deep cast of an int[].  | 
static double[][] | 
createHistogram(Collection<double[]> data,
                int numBins,
                int... indices)
Creates a histogram from the given data.  | 
static int[] | 
createHistogram(int[] a)
Create a histogram for the given array.  | 
static Map<Integer,Integer> | 
createHistogramAsMap(int[] a)
Create a histogram map for the given array.  | 
static int[] | 
createInverse(int[] a)
Creates the inverse array to the given array.  | 
static Map<Integer,Integer> | 
createInverseAsMap(int[] a)
Creates the inverse map to the given array.  | 
static void | 
cumSum(int[] l)
Replaces the values in the given array with the cumulative sum of the array.  | 
static int | 
faculty(int i)
Gets the faculty  | 
static int[] | 
getContentAsArray(cern.colt.bitvector.BitVector bv)
Gets the indices of the set bits of the given BitVector as array. | 
static cern.colt.bitvector.BitVector | 
getContentAsBitVector(int[] a)
Gets the content of the given array as BitVector, which means, that
 the BitVector will have a size equal to the maximal value in the 
 array and contains a 1 for each element which is contained at least once in the array | 
static String | 
getHistogramAsString(Map<Integer,Integer> h)
Gets a string representation of the histogram map.  | 
static int[] | 
getNumbersTo(int n)
Gets the numbers from 0 to n in an array.  | 
static double[] | 
interpolateLinear(double interval,
                  double[] time,
                  double[] value)
Performs a linear interpolation of the values.  | 
static double | 
interpolateLinear(double desiredTime,
                  double beforeTime,
                  double afterTime,
                  double beforeValue,
                  double afterValue)
Interpolates a value  | 
static String[] | 
inverse(String[] a)
Inverts the given array in place and returns it.  | 
static String | 
join(String[] a,
     String glue)
Joins the array with the given glue to one String.  | 
static Map<Integer,Integer> | 
loadHistogram(File file)
Reads a previously saved histogram from a file.  | 
static int | 
max(Iterable<Integer> l)
Gets the maximal value within the given Iterable. | 
static int | 
min(Iterable<Integer> l)
Gets the minimal value within the given Iterable. | 
static void | 
saveHistogram(Map<Integer,Integer> histo,
              File file)
Writes a histogram to a file.  | 
static void | 
shuffle(int[] a)
Shuffles the content of the given array.  | 
static double | 
stddev(double[] a)
Gets the standard deviation of the array  | 
static int | 
sum(int[] l)
Gets the sum of the values in the array.  | 
static double[] | 
toArray(Collection<Double> list)
Copies the values of the given collection and unboxes them to an array.  | 
static int[] | 
toArray(Collection<Integer> list)
Copies the values of the given collection and unboxes them to an array.  | 
| Methods inherited from class java.lang.Object | 
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public NumberTools()
| Method Detail | 
|---|
public static int faculty(int i)
i - the number
public static int max(Iterable<Integer> l)
Iterable.
l - the iterable
public static int min(Iterable<Integer> l)
Iterable.
l - the iterable
public static int argMax(Map<Integer,Integer> l)
l - map
public static int sum(int[] l)
l - the array
public static void cumSum(int[] l)
l - the arraypublic static int[] toArray(Collection<Integer> list)
list - collection
public static double[] toArray(Collection<Double> list)
list - collection
public static int[] createInverse(int[] a)
  
 Be careful with sparse arrays, the inverse array could be very large (prefer
  
 a[i]=j <=>  a'[j]=i
 createInverseAsMap(int[]). It should preferably be used
 with bijective arrays.
a - the array
public static Map<Integer,Integer> createInverseAsMap(int[] a)
  
 a[i]=j <=>  a'.get(j)=i
a - the array
public static double[][] createHistogram(Collection<double[]> data,
                                         int numBins,
                                         int... indices)
data - data to create the histogram fornumBins - number of bins, the return array matrix will have numBins rowsindices - the indices of the data to create the histogram for
public static int[] createHistogram(int[] a)
createHistogramAsMap(int[]).
a - the array to create a histogram for
public static Map<Integer,Integer> createHistogramAsMap(int[] a)
a - the array to create a histogram for
public static void saveHistogram(Map<Integer,Integer> histo,
                                 File file)
                          throws IOException
 loadHistogram.
histo - the histogram to savefile - the file
IOException
public static Map<Integer,Integer> loadHistogram(File file)
                                          throws IOException
file - the file
IOExceptionpublic static String getHistogramAsString(Map<Integer,Integer> h)
h - histogram
public static cern.colt.bitvector.BitVector getContentAsBitVector(int[] a)
BitVector, which means, that
 the BitVector will have a size equal to the maximal value in the 
 array and contains a 1 for each element which is contained at least once in the array
a - array
BitVector> for the arraypublic static int[] getContentAsArray(cern.colt.bitvector.BitVector bv)
BitVector as array.
bv - the BitVector
public static void shuffle(int[] a)
a - arraypublic static double[] convertIntToDouble(int[] a)
a - the array
public static int[] getNumbersTo(int n)
n - maximal number
public static double calculateHistogramDistance(Map<Integer,Integer> h1,
                                                Map<Integer,Integer> h2)
For reference see Cao & Petzold, Accuracy limitations and the measurement of errors in the stochastic simulation of chemically reacting systems, Journal of Computational Physics 212 (2006) 6�24
h1 - first histogramh2 - second histogram
public static double avg(double[] a)
a - array
public static double stddev(double[] a)
a - array
public static String[] inverse(String[] a)
a - array
public static String join(String[] a,
                          String glue)
a - arrayglue - glue
public static double[] interpolateLinear(double interval,
                                         double[] time,
                                         double[] value)
interval - the intervaltime - time arrayvalue - value array
public static double interpolateLinear(double desiredTime,
                                       double beforeTime,
                                       double afterTime,
                                       double beforeValue,
                                       double afterValue)
desiredTime - beforeTime - afterTime - beforeValue - afterValue - 
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||