mark.core.math
Class Cube

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

public class Cube
extends java.lang.Object

Assume a sampling process, where each sample determines three discrete random variables, X1, X2, and X3. The range of Xi is the integers in [0, l(Xi) - 1], where l(Xi) is the number of elements Xi can assume. A NumberBox maintains joint counts of X1, X2, and X3. Counts may be doubles, meaning that a count of 0.5, for example, is legal.


Constructor Summary
Cube(double[][][] a)
          Initializes all counts with the values in the given array.
Cube(int X1Length, int X2Length, int X3Length)
          Initializes all counts to zero.
Cube(int X1Length, int X2Length, int X3Length, boolean laplace)
          Initializes all counts to zero if not laplace and to one if laplace.
 
Method Summary
 java.lang.Object clone()
          Clones the Cube.
 boolean equals(java.lang.Object rhs)
          Returns whether the Cube is equivalent to the given Cube.
 void inc(int x1, int x2, int x3)
          Increments #(X1 = x1, X2 = x2, X = x3).
 void inc(int x1, int x2, int x3, double c)
          Increments #(X1 = x1, X2 = x2, X = x3) by the given count.
static void main(java.lang.String[] a)
          Tests the class.
 double mutualInformationX1X2GivenX3()
          Returns the mutual information of (X1, X2) given X3: I((X1;X2)|X3).
 void normalizeCounts()
          Divides each count by the sum of the counts.
 double num()
          Returns the total number of samples.
 double numX1(int x1)
          Returns #(X1 = x1).
 double numX1X2(int x1, int x2)
          Returns #(X1 = x1, X2 = x2).
 double numX1X2X3(int x1, int x2, int x3)
          Returns #(X1 = x1, X2 = x2, X3 = x3).
 double numX1X3(int x1, int x3)
          Returns #(X1 = x1, X3 = x3).
 double numX2(int x2)
          Returns #(X2 = x2).
 double numX2X3(int x2, int x3)
          Returns #(X1 = x2, X3 = x3).
 double numX3(int x3)
          Returns #(X3 = x3).
 double pointwiseMutualInformationX1X2GivenX3(int x1, int x3)
          Returns the pointwise mutual information of (X1, X2) given X3: I((X1;X2)|X3).
 double prob()
          Returns 1.0.
 double probX1(int x1)
          Returns p(X1 = x1).
 double probX1X2(int x1, int x2)
          Returns p(X1 = x1, X2 = x2).
 double probX1X2X3(int x1, int x2, int x3)
          Returns p(X1 = x1, X2 = x2, X3 = x3).
 double probX1X3(int x1, int x3)
          Returns p(X1 = x1, X3 = x3).
 double probX2(int x2)
          Returns p(X2 = x2).
 double probX2X3(int x2, int x3)
          Returns p(X2 = x2, X3 = x3).
 double probX3(int x3)
          Returns p(X3 = x3).
 void reset(boolean laplace)
          Resets all counts to zero if not laplace and to one if laplace.
 void set(int x1, int x2, int x3, double c)
          Sets #(X1 = x1, X2 = x2, X3 = x3).
 double[][][] toDoubleArray()
          Returns a representation as a double[][][].
 java.lang.String toString()
          Returns a string representation of the table.
 int X1Length()
          Returns the number of values X1 can assume.
 int X2Length()
          Returns the number of values X2 can assume.
 int X3Length()
          Returns the number of values X3 can assume.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cube

public Cube(int X1Length,
            int X2Length,
            int X3Length)
Initializes all counts to zero.

Parameters:
X1Length - l(X1), the number of values X1 can assume.
X2Length - l(X2), the number of values X2 can assume.
X3Length - l(X3), the number of values X3 can assume.

Cube

public Cube(int X1Length,
            int X2Length,
            int X3Length,
            boolean laplace)
Initializes all counts to zero if not laplace and to one if laplace.

Parameters:
X1Length - l(X1), the number of values X1 can assume.
X2Length - l(X2), the number of values X2 can assume.
X3Length - l(X3), the number of values X3 can assume.
laplace - whether to use laplace smoothing.

Cube

public Cube(double[][][] a)
Initializes all counts with the values in the given array.

Parameters:
a - the array.
Method Detail

clone

public java.lang.Object clone()
Clones the Cube.

Overrides:
clone in class java.lang.Object
Returns:
the copy.

equals

public boolean equals(java.lang.Object rhs)
Returns whether the Cube is equivalent to the given Cube.

Overrides:
equals in class java.lang.Object
Parameters:
rhs - the given Cube.
Returns:
whether the two Cubes are equivalent.

toString

public java.lang.String toString()
Returns a string representation of the table.

Overrides:
toString in class java.lang.Object
Returns:
the representation.

toDoubleArray

public double[][][] toDoubleArray()
Returns a representation as a double[][][].

Returns:
the double[].

reset

public void reset(boolean laplace)
Resets all counts to zero if not laplace and to one if laplace.

Parameters:
laplace - whether to use laplace smoothing.

X1Length

public int X1Length()
Returns the number of values X1 can assume.

Returns:
l(X1).

X2Length

public int X2Length()
Returns the number of values X2 can assume.

Returns:
l(X2).

X3Length

public int X3Length()
Returns the number of values X3 can assume.

Returns:
l(X3).

numX1X2X3

public double numX1X2X3(int x1,
                        int x2,
                        int x3)
Returns #(X1 = x1, X2 = x2, X3 = x3).

Parameters:
x1 - the X1 value.
Returns:
the count.

numX1X2

public double numX1X2(int x1,
                      int x2)
Returns #(X1 = x1, X2 = x2).

Parameters:
x1 - the X1 value.
Returns:
the count.

numX1X3

public double numX1X3(int x1,
                      int x3)
Returns #(X1 = x1, X3 = x3).

Parameters:
x1 - the X1 value.
x3 - the X3 value.
Returns:
the count.

numX2X3

public double numX2X3(int x2,
                      int x3)
Returns #(X1 = x2, X3 = x3). Returns the number of samples given a value for X1 and X2.

Parameters:
x2 - the X2 value.
x3 - the X3 value.
Returns:
the count.

numX1

public double numX1(int x1)
Returns #(X1 = x1).

Parameters:
x1 - the X1 value.
Returns:
the count.

numX2

public double numX2(int x2)
Returns #(X2 = x2).

Parameters:
x2 - the X2 value.
Returns:
the count.

numX3

public double numX3(int x3)
Returns #(X3 = x3).

Parameters:
x3 - the X3 value.
Returns:
the count.

num

public double num()
Returns the total number of samples.

Returns:
the count.

probX1X2X3

public double probX1X2X3(int x1,
                         int x2,
                         int x3)
Returns p(X1 = x1, X2 = x2, X3 = x3).

Parameters:
x1 - the X1 value.
x2 - the X2 value.
x3 - the X3 value.
Returns:
the probability.

probX1X2

public double probX1X2(int x1,
                       int x2)
Returns p(X1 = x1, X2 = x2).

Parameters:
x1 - the X1 value.
x2 - the X2 value.
Returns:
the probability.

probX1X3

public double probX1X3(int x1,
                       int x3)
Returns p(X1 = x1, X3 = x3).

Parameters:
x1 - the X1 value.
x3 - the X3 value.
Returns:
the probability.

probX2X3

public double probX2X3(int x2,
                       int x3)
Returns p(X2 = x2, X3 = x3).

Parameters:
x2 - the X2 value.
x3 - the X3 value.
Returns:
the probability.

probX1

public double probX1(int x1)
Returns p(X1 = x1).

Parameters:
x1 - the X1 value.
Returns:
the probability.

probX2

public double probX2(int x2)
Returns p(X2 = x2).

Parameters:
x2 - the X2 value.
Returns:
the probability.

probX3

public double probX3(int x3)
Returns p(X3 = x3).

Parameters:
x3 - the X3 value.
Returns:
the probability.

prob

public double prob()
Returns 1.0.

Returns:
the probability.

set

public void set(int x1,
                int x2,
                int x3,
                double c)
Sets #(X1 = x1, X2 = x2, X3 = x3).

Parameters:
x1 - the X1 value.
x2 - the X2 value.
x3 - the X3 value.
c - the count.

inc

public void inc(int x1,
                int x2,
                int x3)
Increments #(X1 = x1, X2 = x2, X = x3).

Parameters:
x1 - the X1 value.

inc

public void inc(int x1,
                int x2,
                int x3,
                double c)
Increments #(X1 = x1, X2 = x2, X = x3) by the given count.

Parameters:
x1 - the X1 value.
x2 - the X2 value.
x3 - the X3 value.
c - the count.

normalizeCounts

public void normalizeCounts()
Divides each count by the sum of the counts.


main

public static void main(java.lang.String[] a)
                 throws java.lang.Exception
Tests the class. This code assumes that toDoubleArray works.

Parameters:
a - ignored.
java.lang.Exception

mutualInformationX1X2GivenX3

public double mutualInformationX1X2GivenX3()
Returns the mutual information of (X1, X2) given X3: I((X1;X2)|X3).

Returns:
the mutual information.

pointwiseMutualInformationX1X2GivenX3

public double pointwiseMutualInformationX1X2GivenX3(int x1,
                                                    int x3)
Returns the pointwise mutual information of (X1, X2) given X3: I((X1;X2)|X3).

Parameters:
x1 - the X1 value.
x3 - the X3 value.
Returns:
the pointwise mutual information.