|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object blog.AbstractCondProbDistrib blog.distrib.Categorical
public class Categorical
Distribution over a finite set of possible values numbered 0, ..., k-1, parameterized by a vector of probabilities pi0, ..., pik-1 that sum to one. The possible values can be the user-defined guaranteed objects of some type, or a finite prefix of the natural numbers. The probability vector can be specified when the distribution is constructed, or as an argument to the getProb and sampleVal methods (in the form of a column vector).
Field Summary | |
---|---|
static int |
LOG
Value that can be bitwise or'ed with a flag argument
to indicate that the weights are given as (natural) logs. |
static int |
NO_FLAGS
Value for constructor's flag argument indicating
that all flags are false. |
static int |
NORMALIZED
Value that can be bitwise or'ed with a flag argument
to indicate that the given weights are normalized (sum to 1). |
static int |
SORTED
Value that can be bitwise or'ed with a flag argument
to indicate that the weights are sorted in non-increasing order
(largest first). |
Constructor Summary | |
---|---|
Categorical(double[] probs)
Creates a new Categorical distribution with the given probability vector. |
|
Categorical(double[] weights,
int flags)
Creates a new Categorical distribution with the given probability weights. |
|
Categorical(int numValues)
Creates a new Categorical distribution representing the uniform distribution over the given number of values. |
|
Categorical(java.util.List params)
Creates a new Categorical distribution from the given parameter list. |
Method Summary | |
---|---|
double |
getLogProb(int index)
Returns the log probability of the value with the given index under this distribution. |
int |
getNumValues()
Returns the number of values to which this distribution explicitly assigns a probability. |
double |
getProb(int index)
Returns the probability of the value with the given index under this distribution. |
double |
getProb(java.util.List args,
java.lang.Object childValue)
Returns the probability of the given child value conditioned on the given argument values. |
int |
sampleVal()
Returns an index sampled from this distribution. |
java.lang.Object |
sampleVal(java.util.List args,
Type childType)
Returns a value sampled from the given child type according to this distribution. |
Methods inherited from class blog.AbstractCondProbDistrib |
---|
getLogProb, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int NO_FLAGS
flag
argument indicating
that all flags are false.
public static final int NORMALIZED
flag
argument
to indicate that the given weights are normalized (sum to 1).
public static final int LOG
flag
argument
to indicate that the weights are given as (natural) logs.
public static final int SORTED
flag
argument
to indicate that the weights are sorted in non-increasing order
(largest first). This allows log weights to be normalized slightly
faster (the code divides each weight by the largest one before
exponentiating, to avoid underflow).
Constructor Detail |
---|
public Categorical(int numValues)
public Categorical(double[] probs)
public Categorical(double[] weights, int flags)
flags
argument is treated as a bit
vector indicating what assumptions can be made about the given
weights. The possible flags are public static fields of the
Categorical class.
public Categorical(java.util.List params)
Method Detail |
---|
public int getNumValues()
java.lang.IllegalStateException
- if the probability vector was not
specified when this distribution was
constructedpublic double getProb(int index)
java.lang.IllegalStateException
- if the probability vector was not
specified when this distribution was
constructed
java.lang.IllegalArgumentException
- if index
is negativepublic double getLogProb(int index)
java.lang.IllegalStateException
- if the probability vector was not
specified when this distribution was
constructed
java.lang.IllegalArgumentException
- if index
is negativepublic double getProb(java.util.List args, java.lang.Object childValue)
childValue
's
index, or 0 if childValue
does not have an index
or its index is beyond the end of the probability vector
java.lang.IllegalArgumentException
- if the probability vector was
specified at construction and
args
is non-empty, or
if the probability vector was not
specified and args
is
emptypublic int sampleVal()
java.lang.IllegalStateException
- if the probability vector was not
specified when this distribution was
constructedpublic java.lang.Object sampleVal(java.util.List args, Type childType)
java.lang.IllegalArgumentException
- if the probability vector was
specified at construction and
args
is non-empty, or
if the probability vector was not
specified and args
is
empty
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |