gov.sandia.cognition.statistics.distribution
Class CategoricalDistribution

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.statistics.AbstractDistribution<Vector>
          extended by gov.sandia.cognition.statistics.distribution.CategoricalDistribution
All Implemented Interfaces:
Vectorizable, ClosedFormComputableDiscreteDistribution<Vector>, ClosedFormComputableDistribution<Vector>, ClosedFormDistribution<Vector>, ComputableDistribution<Vector>, DiscreteDistribution<Vector>, Distribution<Vector>, DistributionWithMean<Vector>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
CategoricalDistribution.PMF

@PublicationReference(author="Wikipedia",
                      title="Categoical Distribution",
                      type=WebPage,
                      year=2011,
                      url="http://en.wikipedia.org/wiki/Categorical_distribution")
public class CategoricalDistribution
extends AbstractDistribution<Vector>
implements ClosedFormComputableDiscreteDistribution<Vector>

The Categorical Distribution is the multivariate generalization of the Bernoulli distribution, where the outcome of an experiment is a one-of-N output, where the output is a selector Vector. This Vector will have all zeros except one index will have a 1.0.

Since:
3.3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
static class CategoricalDistribution.PMF
          PMF of the Categorical Distribution
 
Field Summary
static int DEFAULT_NUM_CLASSES
          Default number of classes (labels or parameters), 2.
protected  Vector parameters
          Parameters of the multinomial distribution, must be at least 2-dimensional and each element must be nonnegative.
 
Constructor Summary
CategoricalDistribution()
          Creates a new instance of CategoricalDistribution
CategoricalDistribution(CategoricalDistribution other)
          Copy constructor
CategoricalDistribution(int numClasses)
          Creates a new instance of CategoricalDistribution
CategoricalDistribution(Vector parameters)
          Creates a new instance of CategoricalDistribution
 
Method Summary
 CategoricalDistribution clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector convertToVector()
          Converts the object to a vector.
 Set<Vector> getDomain()
          Returns an object that allows an iteration through the domain (x-axis, independent variable) of the Distribution
 int getDomainSize()
          Gets the size of the domain.
 int getInputDimensionality()
          Gets the dimensionality of the input vectors
 Vector getMean()
          Gets the arithmetic mean, or "first central moment" or "expectation", of the distribution.
 Vector getParameters()
          Getter for parameters
 CategoricalDistribution.PMF getProbabilityFunction()
          Gets the distribution function associated with this Distribution, either the PDF or PMF.
 ArrayList<Vector> sample(Random random, int numSamples)
          Draws multiple random samples from the distribution.
 void setParameters(Vector parameters)
          Setter for parameters
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractDistribution
sample
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.statistics.Distribution
sample
 

Field Detail

DEFAULT_NUM_CLASSES

public static final int DEFAULT_NUM_CLASSES
Default number of classes (labels or parameters), 2.

See Also:
Constant Field Values

parameters

protected Vector parameters
Parameters of the multinomial distribution, must be at least 2-dimensional and each element must be nonnegative.

Constructor Detail

CategoricalDistribution

public CategoricalDistribution()
Creates a new instance of CategoricalDistribution


CategoricalDistribution

public CategoricalDistribution(int numClasses)
Creates a new instance of CategoricalDistribution

Parameters:
numClasses - Number of classes (labels or parameters) to use.

CategoricalDistribution

public CategoricalDistribution(Vector parameters)
Creates a new instance of CategoricalDistribution

Parameters:
parameters - Parameters of the multinomial distribution, must be at least 2-dimensional and each element must be nonnegative.

CategoricalDistribution

public CategoricalDistribution(CategoricalDistribution other)
Copy constructor

Parameters:
other - CategoricalDistribution to copy
Method Detail

clone

public CategoricalDistribution clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface Vectorizable
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

getParameters

public Vector getParameters()
Getter for parameters

Returns:
Parameters of the multinomial distribution, must be at least 2-dimensional and each element must be nonnegative.

setParameters

public void setParameters(Vector parameters)
Setter for parameters

Parameters:
parameters - Parameters of the multinomial distribution, must be at least 2-dimensional and each element must be nonnegative.

sample

public ArrayList<Vector> sample(Random random,
                                int numSamples)
Description copied from interface: Distribution
Draws multiple random samples from the distribution. It is generally more efficient to use this multiple-sample method than multiple calls of the single-sample method. (But not always.)

Specified by:
sample in interface Distribution<Vector>
Parameters:
random - Random-number generator to use in order to generate random numbers.
numSamples - Number of samples to draw from the distribution.
Returns:
Samples drawn according to this distribution.

getMean

public Vector getMean()
Description copied from interface: DistributionWithMean
Gets the arithmetic mean, or "first central moment" or "expectation", of the distribution.

Specified by:
getMean in interface DistributionWithMean<Vector>
Returns:
Mean of the distribution.

convertToVector

public Vector convertToVector()
Description copied from interface: Vectorizable
Converts the object to a vector.

Specified by:
convertToVector in interface Vectorizable
Returns:
The Vector form of the object.

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Vectorizable
Converts the object from a Vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameters to incorporate.

getInputDimensionality

public int getInputDimensionality()
Gets the dimensionality of the input vectors

Returns:
Dimensionality of the input vectors

getDomain

public Set<Vector> getDomain()
Description copied from interface: DiscreteDistribution
Returns an object that allows an iteration through the domain (x-axis, independent variable) of the Distribution

Specified by:
getDomain in interface DiscreteDistribution<Vector>
Returns:
Collection that enumerates each value that the domain can take

getDomainSize

public int getDomainSize()
Description copied from interface: DiscreteDistribution
Gets the size of the domain.

Specified by:
getDomainSize in interface DiscreteDistribution<Vector>
Returns:
The size of the domain.

getProbabilityFunction

public CategoricalDistribution.PMF getProbabilityFunction()
Description copied from interface: ComputableDistribution
Gets the distribution function associated with this Distribution, either the PDF or PMF.

Specified by:
getProbabilityFunction in interface ComputableDistribution<Vector>
Specified by:
getProbabilityFunction in interface DiscreteDistribution<Vector>
Returns:
Distribution function associated with this Distribution.