comirva.util
Class MathUtils

java.lang.Object
  extended by comirva.util.MathUtils

public class MathUtils
extends Object


Field Summary
static float ZERO_TOLERANCE
           
 
Constructor Summary
MathUtils()
           
 
Method Summary
static float[] divide(float[] a, float f)
          Create a new array containing each value in a divided by f.
static float euclideanLength(float[] f)
          Determine the euclidean length of f, i.e., the root of the sum of the squared elements of f.
static float log2(double a)
           
static float max(float[] a)
          Returns the maximum of all values in a, as determined by Math.max(float, float).
static float[] max(float f, float[] a)
          Creates a copy of a and replaces each element of a which is smaller than f (as determined by Math.max) with f.
static int max(int[] a)
           
static void maxInPlace(float f, float[] a)
          Same function as max(float f, float[] a) but without creating a new array.
static float mean(ArrayList<Integer> al)
          Calculate the mean value of all integers in the ArrayList.
static float mean(float[] a)
          Returns the mean of all values in a.
static float min(float[] f)
          Determine the minimum value in the array f, as indicated by Math.min(float, float)
static float[] minus(float[] a, float b)
          Return a new array containing at position i the value a[i] - b The values in the original array a are left unchanged.
static float[] mult(float[] a, float[] b)
           
static float multSafe(float a, float b)
          Multiplies a and b and returns the result, unless the result is NaN or +/-infinity, in which case the function returns 0.0f.
static int numelNonzero(float[] a)
          Return the number of elements in a that are not zero.
static float sum_abs(float[] a)
          Sums up the elements after taking their absolute value.
static float sum(float[] a)
          Returns the sum of all elements in a.
static long sum(int[] a)
          Returns the sum of all elements in a.
static void zeros(float[] a)
          Set all values in a to zero.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO_TOLERANCE

public static final float ZERO_TOLERANCE
See Also:
Constant Field Values
Constructor Detail

MathUtils

public MathUtils()
Method Detail

log2

public static float log2(double a)

multSafe

public static float multSafe(float a,
                             float b)
Multiplies a and b and returns the result, unless the result is NaN or +/-infinity, in which case the function returns 0.0f.

Parameters:
a -
b -
Returns:

max

public static int max(int[] a)

mean

public static float mean(ArrayList<Integer> al)
Calculate the mean value of all integers in the ArrayList.

Parameters:
al -
Returns:

sum_abs

public static float sum_abs(float[] a)
Sums up the elements after taking their absolute value. Useful to find out if nonzero elements exist. If a.length == 0, the result is 0.

Parameters:
a -

numelNonzero

public static int numelNonzero(float[] a)
Return the number of elements in a that are not zero. Values that have an absolute value smaller or equal to the constant ZERO_TOLERANCE are considered as being zero.

Parameters:
a -
Returns:

max

public static float max(float[] a)
Returns the maximum of all values in a, as determined by Math.max(float, float). If a is empty, 0 is returned.

Parameters:
a -
Returns:

sum

public static float sum(float[] a)
Returns the sum of all elements in a. If a is empty, an ArrayIndexOutOfBounds exception is thrown.

Parameters:
a -
Returns:

sum

public static long sum(int[] a)
Returns the sum of all elements in a. If a is empty, an ArrayIndexOutOfBounds exception is thrown.

Parameters:
a -
Returns:

zeros

public static void zeros(float[] a)
Set all values in a to zero.

Parameters:
a -

mean

public static float mean(float[] a)
Returns the mean of all values in a. The function adds the values in a before dividing them, which is more accurate for small values, but may fail if a contains very large values close to +/-Float.MAX_VALUE (in which case the sum may become infinity). If a is empty, then an ArrayIndexOutOfBounds exception is thrown.

Parameters:
a -
Returns:

mult

public static float[] mult(float[] a,
                           float[] b)
Parameters:
a -
b -
Returns:
an array containing at position i the value a[i] * b[i].

max

public static float[] max(float f,
                          float[] a)
Creates a copy of a and replaces each element of a which is smaller than f (as determined by Math.max) with f.

Parameters:
f -
a -
Returns:

maxInPlace

public static void maxInPlace(float f,
                              float[] a)
Same function as max(float f, float[] a) but without creating a new array. Rather the values in the original array a are modified.

Parameters:
f -
a -

euclideanLength

public static float euclideanLength(float[] f)
Determine the euclidean length of f, i.e., the root of the sum of the squared elements of f. When after squaring a value in f a NaN or infinite value occurs, this specific value is considered as being zero, not having an influence on the other values of f.

Parameters:
f -
Returns:

min

public static float min(float[] f)
Determine the minimum value in the array f, as indicated by Math.min(float, float)

Parameters:
f -
Returns:

minus

public static float[] minus(float[] a,
                            float b)
Return a new array containing at position i the value a[i] - b The values in the original array a are left unchanged.

Parameters:
a -
b -
Returns:

divide

public static float[] divide(float[] a,
                             float f)
Create a new array containing each value in a divided by f. The values in the original array a are left unchanged.

Parameters:
a -
f -
Returns: