@PublicationReference(author="Michael I. Jordan",title="Dirichlet Processes, Chinese Restaurant Processes and All That",year=2005,type=Conference,publication="NIPS Tutorial",url="http://www.cs.berkeley.edu/~jordan/nips-tutorial05.ps") @PublicationReference(author="Wikipedia",title="http://en.wikipedia.org/wiki/Chinese_restaurant_process",year=2010,type=WebPage,url="http://en.wikipedia.org/wiki/Chinese_restaurant_process",notes="Very poor, unclear description.") public class ChineseRestaurantProcess extends AbstractDistribution<Vector> implements ClosedFormComputableDiscreteDistribution<Vector>
Modifier and Type | Class and Description |
---|---|
static class |
ChineseRestaurantProcess.PMF
PMF of the Chinese Restaurant Process
|
Modifier and Type | Field and Description |
---|---|
protected double |
alpha
CRP concentration parameter, must be greater than zero.
|
static double |
DEFAULT_ALPHA
Default concentration parameter, 1.0.
|
static int |
DEFAULT_NUM_CUSTOMERS
Default number of customers, 2.
|
protected int |
numCustomers
Total number of customers that we will arrange around tables,
must be greater than zero.
|
Constructor and Description |
---|
ChineseRestaurantProcess()
Creates a new instance of ChineseRestaurantProcess
|
ChineseRestaurantProcess(ChineseRestaurantProcess other)
Default constructor
|
ChineseRestaurantProcess(double alpha,
int numCustomers)
Creates a new instance of ChineseRestaurantProcess
|
Modifier and Type | Method and Description |
---|---|
ChineseRestaurantProcess |
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.
|
double |
getAlpha()
Getter for alpha.
|
java.util.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.
|
Vector |
getMean()
Gets the arithmetic mean, or "first central moment" or "expectation",
of the distribution.
|
int |
getNumCustomers()
Getter for numCustomers
|
ChineseRestaurantProcess.PMF |
getProbabilityFunction()
Gets the distribution function associated with this Distribution,
either the PDF or PMF.
|
Vector |
sample(java.util.Random random)
Draws a single random sample from the distribution.
|
void |
sampleInto(java.util.Random random,
int sampleCount,
java.util.Collection<? super Vector> output)
Draws multiple random samples from the distribution and puts the result
into the given collection.
|
static int |
sampleNextCustomer(java.util.Collection<java.lang.Integer> tables,
int numCustomers,
double alpha,
java.util.Random random)
Determines where the next customer sits, given the number of customers
already sitting at the various tables and the concentration parameter
alpha.
|
void |
setAlpha(double alpha)
Setter for alpha.
|
void |
setNumCustomers(int numCustomers)
Setter for numCustomers
|
sample
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
sample
public static final double DEFAULT_ALPHA
public static final int DEFAULT_NUM_CUSTOMERS
protected double alpha
protected int numCustomers
public ChineseRestaurantProcess()
public ChineseRestaurantProcess(double alpha, int numCustomers)
alpha
- CRP concentration parameter, must be greater than zero.numCustomers
- Total number of customers that we will arrange around tables,
must be greater than zero.public ChineseRestaurantProcess(ChineseRestaurantProcess other)
other
- CRP to copypublic ChineseRestaurantProcess clone()
AbstractCloneableSerializable
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.clone
in interface Vectorizable
clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public Vector getMean()
DistributionWithMean
getMean
in interface DistributionWithMean<Vector>
public Vector sample(java.util.Random random)
Distribution
sample
in interface Distribution<Vector>
sample
in class AbstractDistribution<Vector>
random
- Random-number generator to use in order to generate random numbers.public static int sampleNextCustomer(java.util.Collection<java.lang.Integer> tables, int numCustomers, double alpha, java.util.Random random)
tables
- Number of customers sitting at the various tables.numCustomers
- Number of customers already sitting, should equal the sum
of "tables".alpha
- Concentration parameter.random
- Random number generator.public void sampleInto(java.util.Random random, int sampleCount, java.util.Collection<? super Vector> output)
Distribution
sampleInto
in interface Distribution<Vector>
random
- Random number generator to use.sampleCount
- The number of samples to draw. Cannot be negative.output
- The collection to add the samples into.public double getAlpha()
public void setAlpha(double alpha)
alpha
- CRP concentration parameter, must be greater than zero.public int getNumCustomers()
public void setNumCustomers(int numCustomers)
numCustomers
- Total number of customers that we will arrange around tables,
must be greater than zero.public java.util.Set<Vector> getDomain()
DiscreteDistribution
getDomain
in interface DiscreteDistribution<Vector>
public int getDomainSize()
DiscreteDistribution
getDomainSize
in interface DiscreteDistribution<Vector>
public ChineseRestaurantProcess.PMF getProbabilityFunction()
ComputableDistribution
getProbabilityFunction
in interface ComputableDistribution<Vector>
getProbabilityFunction
in interface DiscreteDistribution<Vector>
public Vector convertToVector()
Vectorizable
convertToVector
in interface Vectorizable
public void convertFromVector(Vector parameters)
Vectorizable
convertFromVector
in interface Vectorizable
parameters
- The parameters to incorporate.