edu.stanford.rsl.konrad.utils
Class DoubleArrayUtil

java.lang.Object
  extended by edu.stanford.rsl.konrad.utils.DoubleArrayUtil

public abstract class DoubleArrayUtil
extends java.lang.Object


Constructor Summary
DoubleArrayUtil()
           
 
Method Summary
static double[] add(double[] sum, double toAdd)
          Adds a constant to the first array
static void add(double[] sum, double[] toAdd)
          Adds one array to the first array
static double computeAverageIncrement(double[] array)
          Computes the average increment of the array
static double computeMean(double[] array)
          Computes the mean value of a given array
static double computeMean(double[] values, int start, int end)
          computes the mean of the array "values" on the interval [start, end].
static double computeMeanSquareError(double[] x, double[] y)
          computes the mean square error of array x to array y
static double computeRootMeanSquareError(double[] x, double[] y)
          computes the root mean square error of array x to array y
static double computeStddev(double[] array, double mean)
          Computes the standard deviation given an array and its mean value
static double concordanceCorrelateDoubleArrays(double[] x, double[] y)
          computes the concordance correlation coefficient between two arrays
static double[] convolve(double[] input, double[] kernel)
          Performs a 1-D convolution of the input array with the kernel array.
New array will be only of size
static double correlateDoubleArrays(double[] x, double[] y)
          computes the correlation coefficient between two arrays after Pearson
static double[] divide(double[] array, double divident)
          Divides all entries of array by divident.
static double[] divide(double[] array, double[] divident)
          Divides all entries of the two arrays element by element.
Works in place and overwrites array.
static void exp(double[] array)
          Uses Math.exp() on all elements of the array Works in place and overwrites array.
static int findClosestIndex(double x, double[] array)
          returns the closest index in the array to the given value
static void forceSymmetryComplexDoubleArray(double[] array)
          Forces an complex double array to be symmetric.
static void forceSymmetryRealDoubleArray(double[] array)
          Forces a real double array to be symmetric.
static double[] gaussianFilter(double[] weights, double sigma)
          Gaussian smoothing of the elements of the array "weights"
static boolean isNaN(double[] array)
          tests if any of the values in the given array is NaN
static void log(double[] array)
          Uses Math.log() on all elements of the array Works in place and overwrites array.
static double[] meanFilter(double[] weights, int context)
          Performs mean filtering of the array.
static double[] min(double[] array, double min)
           
static double[] minAndMaxOfArray(double[] array)
          Returns the minimal and the maximal value in a given array
static double minOfArray(double[] array)
          Returns the minimal value in a given array
static double[] multiply(double[] array, double factor)
          Multiplies all entries of array by factor.
static void multiply(double[] array, double[] array2)
          Multiplies all entries of the two arrays element by element.
Works in place and overwrites array.
static double[] pow(double[] array, double exp)
          calls Math.pow for each element of the array
static void print(double[] array)
          Prints the array on standard out.
static void print(double[] array, java.text.NumberFormat nf)
          Prints the contents of the double array on standard out.
static void print(java.lang.String name, double[] array)
          Prints the array on standard out.
static void print(java.lang.String name, double[] array, java.text.NumberFormat nf)
          Prints the array on standard out and denotes the arrays name.
static void removeOutliers(double[] weights, double threshold)
          Removes outliers from the array which differ more than threshold from the last value.
static void saveForVisualization(int imageNumber, double[] array)
          Stores an array for later visualization at index imageNumber
static void suppressCenter(double[] weights, int threshold)
           
static java.lang.String toString(double[] array)
          Converts the array to a String representation.
static java.lang.String toString(double[] array, java.lang.String delimiter)
          Converts the array to a String representation.
static ij.ImagePlus visualizeBufferedArrays(java.lang.String title)
          Displays the arrays stored with "saveForVisualization" as ImagePlus.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleArrayUtil

public DoubleArrayUtil()
Method Detail

saveForVisualization

public static void saveForVisualization(int imageNumber,
                                        double[] array)
Stores an array for later visualization at index imageNumber

Parameters:
imageNumber - the number
array - the array

convolve

public static double[] convolve(double[] input,
                                double[] kernel)
Performs a 1-D convolution of the input array with the kernel array.
New array will be only of size
 output.lenght = input.length - (2 * (kernel.length/2));
 
(Note that integer arithmetic is used here)

Parameters:
input - the array to be convolved
kernel - the kernel
Returns:
the output array.

visualizeBufferedArrays

public static ij.ImagePlus visualizeBufferedArrays(java.lang.String title)
Displays the arrays stored with "saveForVisualization" as ImagePlus.

Parameters:
title - the title of the ImagePlus
Returns:
the reference to the ImagePlus
See Also:
saveForVisualization(int imageNumber, double [] array)

forceSymmetryComplexDoubleArray

public static void forceSymmetryComplexDoubleArray(double[] array)
Forces an complex double array to be symmetric. Left / first half of the array is mirrored to the right / second half

Parameters:
array - the complex array

isNaN

public static boolean isNaN(double[] array)
tests if any of the values in the given array is NaN

Parameters:
array -
Returns:
true if the array contains at least one entry with NaN

forceSymmetryRealDoubleArray

public static void forceSymmetryRealDoubleArray(double[] array)
Forces a real double array to be symmetric. Left / first half of the array is mirrored to the right / second half

Parameters:
array - the real array

findClosestIndex

public static int findClosestIndex(double x,
                                   double[] array)
returns the closest index in the array to the given value

Parameters:
x - the value
array - the array
Returns:
the desired index in the array

correlateDoubleArrays

public static double correlateDoubleArrays(double[] x,
                                           double[] y)
computes the correlation coefficient between two arrays after Pearson

Parameters:
x - the one array
y - the other array
Returns:
the correlation

concordanceCorrelateDoubleArrays

public static double concordanceCorrelateDoubleArrays(double[] x,
                                                      double[] y)
computes the concordance correlation coefficient between two arrays

Parameters:
x - the one array
y - the other array
Returns:
the correlation

computeMeanSquareError

public static double computeMeanSquareError(double[] x,
                                            double[] y)
computes the mean square error of array x to array y

Parameters:
x - the one array
y - the other array
Returns:
the mean square error

computeRootMeanSquareError

public static double computeRootMeanSquareError(double[] x,
                                                double[] y)
computes the root mean square error of array x to array y

Parameters:
x - the one array
y - the other array
Returns:
the root mean square error.

suppressCenter

public static void suppressCenter(double[] weights,
                                  int threshold)

removeOutliers

public static void removeOutliers(double[] weights,
                                  double threshold)
Removes outliers from the array which differ more than threshold from the last value.

Parameters:
weights - the weight
threshold - the threshold

computeMean

public static double computeMean(double[] values,
                                 int start,
                                 int end)
computes the mean of the array "values" on the interval [start, end].

Parameters:
values - the array
start - the start index
end - the end index
Returns:
the mean value

computeAverageIncrement

public static double computeAverageIncrement(double[] array)
Computes the average increment of the array

Parameters:
array - the array
Returns:
the average increment

meanFilter

public static double[] meanFilter(double[] weights,
                                  int context)
Performs mean filtering of the array.

Parameters:
weights - the array
context - the context to be used for smoothing (from -context/2 to context/2)
Returns:
the smoothed array

gaussianFilter

public static double[] gaussianFilter(double[] weights,
                                      double sigma)
Gaussian smoothing of the elements of the array "weights"

Parameters:
weights - the array
sigma - the standard deviation
Returns:
the smoothed array

computeStddev

public static double computeStddev(double[] array,
                                   double mean)
Computes the standard deviation given an array and its mean value

Parameters:
array - the array
mean - the mean value of the array
Returns:
the standard deviation

computeMean

public static double computeMean(double[] array)
Computes the mean value of a given array

Parameters:
array - the array
Returns:
the mean value as double

minAndMaxOfArray

public static double[] minAndMaxOfArray(double[] array)
Returns the minimal and the maximal value in a given array

Parameters:
array - the array
Returns:
an array with minimal and maximal value

minOfArray

public static double minOfArray(double[] array)
Returns the minimal value in a given array

Parameters:
array - the array
Returns:
the minimal value

add

public static void add(double[] sum,
                       double[] toAdd)
Adds one array to the first array

Parameters:
sum - the first array
toAdd - the array to add

add

public static double[] add(double[] sum,
                           double toAdd)
Adds a constant to the first array

Parameters:
sum - the first array
toAdd - the constant to add

divide

public static double[] divide(double[] array,
                              double divident)
Divides all entries of array by divident.

Parameters:
array - the array
divident - the number used for division.

multiply

public static double[] multiply(double[] array,
                                double factor)
Multiplies all entries of array by factor.

Parameters:
array - the array
factor - the number used for multiplication.

multiply

public static void multiply(double[] array,
                            double[] array2)
Multiplies all entries of the two arrays element by element.
Works in place and overwrites array.

Parameters:
array - the array
array2 - the other array.

exp

public static void exp(double[] array)
Uses Math.exp() on all elements of the array Works in place and overwrites array.

Parameters:
array - the array

divide

public static double[] divide(double[] array,
                              double[] divident)
Divides all entries of the two arrays element by element.
Works in place and overwrites array.

Parameters:
array - the array
divident - the other array.

log

public static void log(double[] array)
Uses Math.log() on all elements of the array Works in place and overwrites array.

Parameters:
array - the array

print

public static void print(double[] array,
                         java.text.NumberFormat nf)
Prints the contents of the double array on standard out.

Parameters:
array -
nf - the NumberFormat

print

public static void print(java.lang.String name,
                         double[] array,
                         java.text.NumberFormat nf)
Prints the array on standard out and denotes the arrays name.

Parameters:
name - the name
array - the array
nf - the number format

print

public static void print(java.lang.String name,
                         double[] array)
Prints the array on standard out. Uses NumberFormat.getInstance() for number formatting

Parameters:
name - the name
array - the array

print

public static void print(double[] array)
Prints the array on standard out. Uses NumberFormat.getInstance() for number formatting

Parameters:
array - the array

pow

public static double[] pow(double[] array,
                           double exp)
calls Math.pow for each element of the array

Parameters:
array -
exp - the exponent.
Returns:
reference to the input array

min

public static double[] min(double[] array,
                           double min)

toString

public static java.lang.String toString(double[] array)
Converts the array to a String representation. Calls toString(array, " ").

Parameters:
array - the array
Returns:
the String representation
See Also:
toString(double[],String)

toString

public static java.lang.String toString(double[] array,
                                        java.lang.String delimiter)
Converts the array to a String representation. delimiter is used to connect the elements of the array.

Parameters:
array - the array
delimiter - the delimiter
Returns:
the String representation