mark.core.math
Class Util

java.lang.Object
  |
  +--mark.core.math.Util

public class Util
extends java.lang.Object

Util is a class that contains a number of simple static utility methods.


Constructor Summary
Util()
           
 
Method Summary
static double constrain(double d, double min, double max)
          Constrains a double.
static boolean equals(double[][][] lhs, double[][][] rhs)
          Returns whether two double[][][]'s are equal.
static boolean equals(double[][] lhs, double[][] rhs)
          Returns whether two double[][]'s are equal.
static void fill(double[][][] a, double val)
          Fills a double[][][] with the given value.
static void fill(double[][] a, double val)
          Fills a double[][] with the given value.
static double log2(double a)
          Calculates the log base 2 of its argument.
static void normalize(double[] a)
          Normalizes the components of a double[] to sum to 1.0.
static double pointwiseChiSquared(double numX1X2, double numX1, double numX2, double num)
          Returns the pointwise chi-squared value of (X1, X2).
static int random(java.util.Random gen, int low, int high)
          Returns a random int in the given range (inclusive).
static double sum(double[] a)
          Returns the sum of a double[].
static double sum(double[][] a)
          Returns the sum of a double[][].
static double sum(double[][][] a)
          Returns the sum of a double[][][].
static double weightedPointwiseMutualInformation(double numX1X2, double numX1, double numX2, double num)
          Returns the weighted pointwise mutual information of (X1 = x1, X2 = x2).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

fill

public static void fill(double[][] a,
                        double val)
Fills a double[][] with the given value.

Parameters:
a - the array.
val - the value.

fill

public static void fill(double[][][] a,
                        double val)
Fills a double[][][] with the given value.

Parameters:
a - the array.
val - the value.

sum

public static double sum(double[] a)
Returns the sum of a double[].

Parameters:
a - the array.
Returns:
the sum.

sum

public static double sum(double[][] a)
Returns the sum of a double[][].

Parameters:
a - the array.
Returns:
the sum.

sum

public static double sum(double[][][] a)
Returns the sum of a double[][][].

Parameters:
a - the array.
Returns:
the sum.

normalize

public static void normalize(double[] a)
Normalizes the components of a double[] to sum to 1.0.

Parameters:
a - the array.

equals

public static boolean equals(double[][] lhs,
                             double[][] rhs)
Returns whether two double[][]'s are equal.

Parameters:
lhs - the first array.
rhs - the second array.
Returns:
whether they are equal.

equals

public static boolean equals(double[][][] lhs,
                             double[][][] rhs)
Returns whether two double[][][]'s are equal.

Parameters:
lhs - the first array.
rhs - the second array.
Returns:
whether they are equal.

random

public static int random(java.util.Random gen,
                         int low,
                         int high)
Returns a random int in the given range (inclusive).

Parameters:
low - the start of the range.
high - the end of the range.
Returns:
the random number.

constrain

public static double constrain(double d,
                               double min,
                               double max)
Constrains a double. If the given double is in the given closed range, then returns the given double. If the given double is greater than the largest value in the range, then returns the largest value in the range. If the double is less than the smallest value in the range, then returns the smallest value in the range.

Parameters:
d - the double.
min - the smallest value in the range.
max - the largest value in the range.
Returns:
the constrained value.

log2

public static double log2(double a)
Calculates the log base 2 of its argument.

Parameters:
a - the argument
Returns:
log base 2 of the argument

weightedPointwiseMutualInformation

public static double weightedPointwiseMutualInformation(double numX1X2,
                                                        double numX1,
                                                        double numX2,
                                                        double num)
Returns the weighted pointwise mutual information of (X1 = x1, X2 = x2).

Parameters:
numX1X2 - #(X1 = x1, X2 = x2).
numX1 - #(X1 = x1).
numX2 - #(X2 = x2).
num - the total number of samples.
Returns:
the weighted pointwise mutual information.

pointwiseChiSquared

public static double pointwiseChiSquared(double numX1X2,
                                         double numX1,
                                         double numX2,
                                         double num)
Returns the pointwise chi-squared value of (X1, X2).

Parameters:
numX1X2 - #(X1 = x1, X2 = x2).
numX1 - #(X1 = x1).
numX2 - #(X2 = x2).
num - the total number of samples.
Returns:
the chi-squared value.