|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--mark.core.math.Array
Maintains a (dense) count array and totals for a one dimensional random variable. That is, this class should be renamed to Vector! Assume a sampling process, where each sample determines a discrete random variable X. The range of X is the integers in [0, l(X) - 1], where l(X) is the number of values X can assume. An Array maintains counts of X. Counts may be doubles, meaning that a count of 0.5, for example, is legal.
| Constructor Summary | |
Array(double[] a)
Initializes all counts with the values in the given array. |
|
Array(int Xlength)
Initializes all counts to zero. |
|
Array(int Xlength,
boolean laplace)
Initializes all counts to zero if not laplace and to one if laplace. |
|
| Method Summary | |
void |
add(Array v)
Performs vector addition. |
static Array |
add(Array v1,
Array v2)
Performs vector addition. |
int |
argmax()
Returns the X value of the largest count in the Array. |
int |
argmin()
Returns the X value of the smallest value in the Array. |
java.lang.Object |
clone()
Clones the Array. |
double |
dot(Array v)
Performs a dot product. |
static double |
dot(Array v1,
Array v2)
Performs a dot product. |
boolean |
equals(java.lang.Object rhs)
Returns whether the Array is equivalent to the given Array. |
void |
fromLog()
Subtracts the smallest value from every element, converts from log space, and then normalizes counts. |
void |
inc(int x)
Increments #(X = x). |
void |
inc(int x,
double c)
Increments #(X = x) by the given count. |
int |
length()
Returns the number of values X can assume. |
double |
magnitude()
Returns the magnitude of the vector. |
static void |
main(java.lang.String[] a)
Tests the class. |
double |
max()
Returns the largest count in the Array. |
double |
min()
Returns the smallest count in the Array. |
static Array |
multiply(Array v,
double s)
Performs scalar multiplication. |
void |
multiply(double s)
Performs scalar multiplication. |
static Array |
multiply(double s,
Array v)
Performs scalar multiplication. |
void |
normalizeCounts()
Divides each count by the sum of the counts. |
void |
normalizeMagnitude()
Normalizes the vector to have magnitude 1. |
static Array |
normalizeMagnitude(Array v)
Normalizes the vector to have magnitude 1. |
double |
num()
Returns the total number of samples. |
double |
numX(int x)
Returns #(X = x). |
double |
prob()
Returns 1.0. |
double |
probX(int x)
Returns p (X = x). |
void |
reset(boolean laplace)
Resets all counts to zero if not laplace and to one if laplace. |
void |
set(int x,
double c)
Sets #(X = x). |
void |
subtract(Array v)
Performs vector subtraction. |
static Array |
subtract(Array v1,
Array v2)
Performs vector subtraction. |
double[] |
toDoubleArray()
Returns a representation as a double[]. |
void |
toLog()
Normalizes counts, and then converts into log space. |
java.lang.String |
toString()
Returns a string representation of the vector. |
| Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Array(int Xlength)
public Array(int Xlength,
boolean laplace)
laplace - whether to use laplace smoothing.public Array(double[] a)
a - the array.| Method Detail |
public java.lang.Object clone()
clone in class java.lang.Objectpublic boolean equals(java.lang.Object rhs)
equals in class java.lang.Objectrhs - the given Array.
public java.lang.String toString()
toString in class java.lang.Objectpublic double[] toDoubleArray()
public void reset(boolean laplace)
laplace - whether to use laplace smoothing.public int length()
public double numX(int x)
x - the X value.
public double num()
public double probX(int x)
x - the X value.
public double prob()
public void set(int x,
double c)
x - the X value.c - the count.public void inc(int x)
x - the X value.
public void inc(int x,
double c)
x - the X value.c - the count.public void normalizeCounts()
public static void main(java.lang.String[] a)
throws java.lang.Exception
a - ignored.
java.lang.Exceptionpublic double max()
public double min()
public int argmax()
public int argmin()
public void toLog()
public void fromLog()
public void add(Array v)
v - the rhs.public void subtract(Array v)
v - the rhs.public void multiply(double s)
s - the scalar.public double dot(Array v)
v - the rhs.
public double magnitude()
public void normalizeMagnitude()
public static Array add(Array v1,
Array v2)
v1 - the lhs.v2 - the rhs.
public static Array subtract(Array v1,
Array v2)
v1 - the lhs.v2 - the rhs.
public static Array multiply(Array v,
double s)
v - the lhs.s - the rhs.
public static Array multiply(double s,
Array v)
s - the lhs.v - the rhs.
public static double dot(Array v1,
Array v2)
v1 - the lhs.v2 - the rhs.
public static Array normalizeMagnitude(Array v)
v - the vector to normalize.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||