public class NumberTools extends Object
Constructor and Description |
---|
NumberTools() |
Modifier and Type | Method and Description |
---|---|
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[] |
toDoubleArray(Collection<Double> list)
Copies the values of the given collection and unboxes them to an array.
|
static int[] |
toIntArray(Collection<Integer> list)
Copies the values of the given collection and unboxes them to an array.
|
public static int faculty(int i)
i
- the numberpublic static int max(Iterable<Integer> l)
Iterable
.l
- the iterablepublic static int min(Iterable<Integer> l)
Iterable
.l
- the iterablepublic static int argMax(Map<Integer,Integer> l)
l
- mappublic static int sum(int[] l)
l
- the arraypublic static void cumSum(int[] l)
l
- the arraypublic static int[] toIntArray(Collection<Integer> list)
list
- collectionpublic static double[] toDoubleArray(Collection<Double> list)
list
- collectionpublic static int[] createInverse(int[] a)
a[i] = j
⇔ a'[j] = i
createInverseAsMap(int[])
. It should preferably be used with bijective arrays.a
- the arraypublic static Map<Integer,Integer> createInverseAsMap(int[] a)
a[i] = j
⇔ a'.get(j) = i
a
- the arraypublic 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 forpublic static int[] createHistogram(int[] a)
createHistogramAsMap(int[])
.a
- the array to create a histogram forpublic static Map<Integer,Integer> createHistogramAsMap(int[] a)
a
- the array to create a histogram forpublic static void saveHistogram(Map<Integer,Integer> histo, File file) throws IOException
loadHistogram
.histo
- the histogram to savefile
- the fileIOException
public static Map<Integer,Integer> loadHistogram(File file) throws IOException
file
- the fileIOException
public static String getHistogramAsString(Map<Integer,Integer> h)
h
- histogrampublic 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 arraya
- arrayBitVector
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 arraypublic static int[] getNumbersTo(int n)
n
- maximal numberpublic 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, doi: 10.1016/j.jcp.2005.06.012
h1
- first histogramh2
- second histogrampublic static double avg(double[] a)
a
- arraypublic static double stddev(double[] a)
a
- arraypublic static String[] inverse(String[] a)
a
- arraypublic static String join(String[] a, String glue)
a
- arrayglue
- gluepublic static double[] interpolateLinear(double interval, double[] time, double[] value)
interval
- the intervaltime
- time arrayvalue
- value arraypublic static double interpolateLinear(double desiredTime, double beforeTime, double afterTime, double beforeValue, double afterValue)
desiredTime
- beforeTime
- afterTime
- beforeValue
- afterValue
- Copyright © 2007–2021. All rights reserved.