de.jstacs.utils
Class Normalisation

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

public class Normalisation
extends Object

This class can be used for normalisation of any double array or a part of a double array.

Author:
Jens Keilwagen, Jan Grau

Constructor Summary
Normalisation()
           
 
Method Summary
static double getLogSum(double... lnVal)
          Returns the logarithm of the sum of values val[i] given as lnVal[i] = Math.log( val[i] ).
static double getLogSum(int start, int end, double... lnVal)
          Returns the logarithm of the sum of values v[i] given as lnVal[i] = Math.log( val[i] ) between a start and end index.
static double logSumNormalisation(double[] d)
          The method does a log-sum-normalisation on the array d, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, double offset)
          The method does a log-sum-normalisation on the array d, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, int startD, int endD)
          The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, int startD, int endD, double[] secondValues)
          The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, int startD, int endD, double[] secondValues, double[] dest, int startDest)
          The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, int startD, int endD, double[] dest, int startDest)
          The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, int startD, int endD, double offset, double[] secondValues, double[] dest, int startDest)
          The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised.
static double logSumNormalisation(double[] d, int startD, int endD, double offset, double[] dest, int startDest)
          The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised.
static void normalisation(double[] d, double v)
          The method does a normalisation on d using the value v for normalisation.
static void normalisation(double[] d, double v, double[] dest, int start)
          The method does a normalisation on d writing the result to dest starting at position start while d remains unchanged.
static void normalisation(double[] d, double v, int start, int end)
          The method does a sum normalisation on d between start index start and end index end using the value v for the normalisation.
static double sumNormalisation(double[] d)
          The method does a sum-normalisation on d, i.e. divides all values in d by the sum over all values in d and returns the sum of the values.
static double sumNormalisation(double[] d, double[] dest, int start)
          The method does a sum-normalisation on d, i.e. divides all values in d by the sum over all values in d and writes the result to dest starting at position start while d remains unchanged.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Normalisation

public Normalisation()
Method Detail

getLogSum

public static double getLogSum(double... lnVal)
Returns the logarithm of the sum of values val[i] given as lnVal[i] = Math.log( val[i] ).

Parameters:
lnVal - the logs of the values, i.e. lnVal[i] = Math.log( val[i] )
Returns:
the logarithm of the sum of values $\log(\sum_i \mathrm{val}[i])$
See Also:
getLogSum(int, int, double...)

getLogSum

public static double getLogSum(int start,
                               int end,
                               double... lnVal)
Returns the logarithm of the sum of values v[i] given as lnVal[i] = Math.log( val[i] ) between a start and end index.

Parameters:
start - the first index in lnVal considered for the sum
end - the index after the last index considered for the sum
lnVal - the logs of the values, i.e. lnVal[i] = Math.log( val[i] )
Returns:
the logarithm of the sum of values between the start and end index $\log(\sum_{i=start}^{end - 1} \mathrm{val}[i])$

logSumNormalisation

public static double logSumNormalisation(double[] d)
The method does a log-sum-normalisation on the array d, where the values of d are assumed to be logarithmised. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=0}^{\mathrm{length}(d)-1} v_i$. Then after log-sum-normalisation, the array d contains the normalized original values, i.e., $d_i$ is set to $d_i := \frac{v_i}{s}$ . The method returns the log-sum of the values, $\log(s)$ .

Parameters:
d - the array with the logarithmised values that should be normalised
Returns:
the logarithm of the sum of the values $\log(\sum_{i=0}^{\mathrm{length}(d)-1} v_i)$
See Also:
logSumNormalisation(double[], int, int, double[], int)

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         int startD,
                                         int endD)
The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i$. Then after log-sum-normalisation, the part of the array d between start index startD and end index endD contains the normalized original values, i.e., $\forall i=\mathrm{startD},\ldots,\mathrm{endD}\ d_i$ is set to $d_i := \frac{v_i}{s}$ . The method returns the log-sum of the values, $\log(s)$ .

Parameters:
d - the array with the logarithms of the values that should be normalised
startD - the first index in d considered for the log-sum-normalisation
endD - the index after the last index in d considered for the log-sum-normalisation
Returns:
the logarithm of the sum of the values between startD and endD $\log(\sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} val[i])$
See Also:
logSumNormalisation(double[], int, int, double[], int)

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         int startD,
                                         int endD,
                                         double[] secondValues)
The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised. In addition to d another array of values secondValues is considered for the normalization constant, but not normalized itself. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i + \sum_{i=0}^{\mathrm{length(secondValues)}-1} \exp(\mathrm{secondValues}_i)$. Then after log-sum-normalisation, the part of the array d starting at index startD contains the normalized original values, i.e., $\forall i=\mathrm{startD},\ldots,\mathrm{endD}-1\ d_i$ is set to $d_i := \frac{v_i}{s}$ . The method returns the log-sum of the values, $\log(s)$ . The method overwrites the values of d starting at position startD!. secondValues will be changed during log-sum-normalisation and will not be written to d.

Parameters:
d - the array with the logarithmised values that should be normalised
startD - the first index in d considered for the log-sum-normalisation
endD - the index after the last index in d considered for the log-sum-normalisation
secondValues - second array with additional values, the whole array is considered for the log-sum-normalisation
Returns:
the logarithm of the sum of the values of d between startD and endD and the values of secondValue
$\log(\sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i + \sum_{i=0}^{\mathrm{length(secondValues)}-1} \exp(\mathrm{secondValues}_i))$

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         int startD,
                                         int endD,
                                         double[] dest,
                                         int startDest)
The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i$. Then after log-sum-normalisation, the part of the array dest starting at index startDest contains the normalized original values, i.e., $\forall i=\mathrm{startDest},\ldots,\mathrm{startDest}+(\mathrm{endD}-\mathrm{startD})-1\ \mathrm{dest}_i$ is set to $\mathrm{dest}_i := \frac{v_j}{s}$ where $j = i - \mathrm{startDest} + \mathrm{startD}$. The method returns the log-sum of the values, $\log(s)$ . The method writes the result of d in dest starting at position startDest while d remains unchanged. secondValues will be changed during log-sum-normalisation and will not be written to dest.

Parameters:
d - the array with the logarithmised values that should be normalised
startD - the first index in d considered for the log-sum-normalisation
endD - the index after the last index in d considered for the log-sum-normalisation
dest - the destination array for the normalised values
startDest - the start index of the destination array
Returns:
the logarithm of the sum of the values of d between startD and endD $\log(\sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i )$

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         int startD,
                                         int endD,
                                         double[] secondValues,
                                         double[] dest,
                                         int startDest)
The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised. In addition to d another array of values secondValues is considered for the normalization constant, but not normalized itself. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i + \sum_{i=0}^{\mathrm{length(secondValues)}-1} \exp(\mathrm{secondValues}_i)$. Then after log-sum-normalisation, the part of the array dest starting at index startDest contains the normalized original values, i.e., $\forall i=\mathrm{startDest},\ldots,\mathrm{startDest}+(\mathrm{endD}-\mathrm{startD})-1\ \mathrm{dest}_i$ is set to $\mathrm{dest}_i := \frac{v_j}{s}$ where $j = i - \mathrm{startDest} + \mathrm{startD}$. The method returns the log-sum of the values, $\log(s)$ . The method writes the result of d in dest starting at position startDest while d remains unchanged. secondValues will be changed during log-sum-normalisation and will not be written to dest.

Parameters:
d - the array with the logarithmised values that should be normalised
startD - the first index in d considered for the log-sum-normalisation
endD - the index after the last index in d considered for the log-sum-normalisation
secondValues - second array with additional values, the whole array is considered for the log-sum-normalisation
dest - the destination array for the normalised values
startDest - the start index of the destination array
Returns:
the logarithm of the sum of the values of d between startD and endD and the values of secondValue
$\log(\sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i + \sum_{i=0}^{\mathrm{length(secondValues)}-1} \exp(\mathrm{secondValues}_i))$

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         double offset)
The method does a log-sum-normalisation on the array d, where the values of d are assumed to be logarithmised. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=0}^{\mathrm{length}(d)-1} v_i$. Then after log-sum-normalisation, the array d contains the normalized original values, i.e., $d_i$ is set to $d_i := \frac{v_i}{s}$ . The method returns the log-sum of the values, $\log(s)$ .

Parameters:
d - the array with the logarithmised values that should be normalised
offset - the offset on the log-values which is used to get more accurate results in the normalization. Typically, this is set to the maximum of the log-values.
Returns:
the logarithm of the sum of the values $\log(\sum_{i=0}^{\mathrm{length}(d)-1} v_i)$
See Also:
logSumNormalisation(double[], int, int, double[], int)

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         int startD,
                                         int endD,
                                         double offset,
                                         double[] dest,
                                         int startDest)
The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i$. Then after log-sum-normalisation, the part of the array dest starting at index startDest contains the normalized original values, i.e., $\forall i=\mathrm{startDest},\ldots,\mathrm{startDest}+(\mathrm{endD}-\mathrm{startD})-1\ \mathrm{dest}_i$ is set to $\mathrm{dest}_i := \frac{v_j}{s}$ where $j = i - \mathrm{startDest} + \mathrm{startD}$. The method returns the log-sum of the values, $\log(s)$ . The method writes the result of d in dest starting at position startDest while d remains unchanged. secondValues will be changed during log-sum-normalisation and will not be written to dest.

Parameters:
d - the array with the logarithmised values that should be normalised
startD - the first index in d considered for the log-sum-normalisation
endD - the index after the last index in d considered for the log-sum-normalisation
offset - the offset on the log-values which is used to get more accurate results in the normalization. Typically, this is set to the maximum of the log-values.
dest - the destination array for the normalised values
startDest - the start index of the destination array
Returns:
the logarithm of the sum of the values of d between startD and endD $\log(\sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i )$

logSumNormalisation

public static double logSumNormalisation(double[] d,
                                         int startD,
                                         int endD,
                                         double offset,
                                         double[] secondValues,
                                         double[] dest,
                                         int startDest)
The method does a log-sum-normalisation on the values of the array d between start index startD and end index endD, where the values of d are assumed to be logarithmised. In addition to d another array of values secondValues is considered for the normalization constant, but not normalized itself. Let $d_i = \log(v_i) \Leftrightarrow v_i = \exp(d_i)$ and $s := \sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i + \sum_{i=0}^{\mathrm{length(secondValues)}-1} \exp(\mathrm{secondValues}_i)$. Then after log-sum-normalisation, the part of the array dest starting at index startDest contains the normalized original values, i.e., $\forall i=\mathrm{startDest},\ldots,\mathrm{startDest}+(\mathrm{endD}-\mathrm{startD})-1\ \mathrm{dest}_i$ is set to $\mathrm{dest}_i := \frac{v_j}{s}$ where $j = i - \mathrm{startDest} + \mathrm{startD}$. The method returns the log-sum of the values, $\log(s)$ . The method writes the result of d in dest starting at position startDest while d remains unchanged. secondValues will be changed during log-sum-normalisation and will not be written to dest.

Parameters:
d - the array with the logarithmised values that should be normalised
startD - the first index in d considered for the log-sum-normalisation
endD - the index after the last index in d considered for the log-sum-normalisation
offset - the offset on the log-values which is used to get more accurate results in the normalization. Typically, this is set to the maximum of the log-values.
secondValues - second array with additional values, the whole array is considered for the log-sum-normalisation
dest - the destination array for the normalised values
startDest - the start index of the destination array
Returns:
the logarithm of the sum of the values of d between startD and endD and the values of secondValue
$\log(\sum_{i=\mathrm{startD}}^{\mathrm{endD}-1} v_i + \sum_{i=0}^{\mathrm{length(secondValues)}-1} \exp(\mathrm{secondValues}_i))$

sumNormalisation

public static double sumNormalisation(double[] d)
The method does a sum-normalisation on d, i.e. divides all values in d by the sum over all values in d and returns the sum of the values.

Parameters:
d - the array with the values that should be normalised
Returns:
the sum of the values of d $\sum_{i=0}^{\mathrm{length}(d)-1} d[i]$
See Also:
sumNormalisation(double[], double[], int)

sumNormalisation

public static double sumNormalisation(double[] d,
                                      double[] dest,
                                      int start)
The method does a sum-normalisation on d, i.e. divides all values in d by the sum over all values in d and writes the result to dest starting at position start while d remains unchanged. The sum of the values of d will be returned.

Parameters:
d - the array with the values that should be normalised
dest - the destination array for the normalised values
start - the start index of the destination array
Returns:
the sum of the values of d $\sum_{i=0}^{\mathrm{length}(d)-1} d[i] $

normalisation

public static void normalisation(double[] d,
                                 double v)
The method does a normalisation on d using the value v for normalisation.

Parameters:
d - the array with the values that should be normalised
v - the value for the normalisation
See Also:
normalisation(double[], double, double[], int)

normalisation

public static void normalisation(double[] d,
                                 double v,
                                 double[] dest,
                                 int start)
The method does a normalisation on d writing the result to dest starting at position start while d remains unchanged. The value v is used for the normalisation.

Parameters:
d - the array with the values that should be normalised
v - the value for normalisation
dest - the destination array for the normalised values
start - the start index of the destination array

normalisation

public static void normalisation(double[] d,
                                 double v,
                                 int start,
                                 int end)
The method does a sum normalisation on d between start index start and end index end using the value v for the normalisation.

Parameters:
d - the array with the values that should be normalised
v - the value for normalisation
start - the first index in d considered for the log-sum-normalisation
end - the index after the last index in d considered for the log-sum-normalisation