KJB
|
A categorical distribution. More...
#include <prob_distribution.h>
Public Member Functions | |
Categorical_distribution () | |
Construct an empty distribution. More... | |
Categorical_distribution (const std::vector< double > &ps, const T &t1=T(1)) | |
Constructs a categorical distribution over the integers {t1, ..., t1 + K}, where K is the length of the given vector. More... | |
Categorical_distribution (const Vector &ps, const T &=T(1)) | |
Constructs a categorical distribution over the integers {1, ..., K}, where K is the length of the given vector. More... | |
Categorical_distribution (const std::vector< T > &values, const std::vector< double > &probabilities) | |
Constructs a categorical distribution over a set of values. More... | |
Categorical_distribution (const std::map< T, double > &d) | |
Constructs a categorical distribution over a set of values. More... | |
Categorical_distribution (const std::map< T, size_t > &m) | |
Constructs an empirical distribution from a map of vals to counts. More... | |
Categorical_distribution (const T &min, const T &max, const T &step) | |
Constructs a categorical distribution limits. More... | |
Categorical_distribution (const T &x1, const T &x2, double p1, double p2) | |
Creates a two-element categorical distribution. More... | |
Categorical_distribution (const Categorical_distribution< T > &cd) | |
Copy-ctor: needed to make sure init_cdf_ gets called. More... | |
Categorical_distribution< T > & | operator= (const Categorical_distribution< T > &cd) |
Assignment: needed to make sure init_cdf_ gets called. More... | |
size_t | size () const |
Size of this distribution. More... | |
void | erase (const T &key) |
void | remove (const T &key) |
void | insert (const T &key, double weight=1.0) |
void | add (const T &key, double weight=1.0) |
~Categorical_distribution () | |
Static Public Member Functions | |
static Categorical_distribution< T > | construct_from_log_map (const std::map< T, double > &log_map) |
Friends | |
template<class U > | |
double | pdf (const Categorical_distribution< U > &dist, const U &x) |
template<class U > | |
double | cdf (const Categorical_distribution< U > &dist, const U &x) |
template<class U > | |
U | sample (const Categorical_distribution< U > &dist) |
A categorical distribution.
This class implements a categorical distribution. This is a discrete probability distribution that assigns a probability to each of a finite number of numbers. It stores an STL map that relates values with probabilities.
T | The type over which the distribution is over. Must be be a RealType (i.e., a field). |
|
inline |
Construct an empty distribution.
kjb::Categorical_distribution< T >::Categorical_distribution | ( | const std::vector< double > & | ps, |
const T & | t1 = T(1) |
||
) |
Constructs a categorical distribution over the integers {t1, ..., t1 + K}, where K is the length of the given vector.
ps | A std::vector of probabilities |
kjb::Categorical_distribution< T >::Categorical_distribution | ( | const Vector & | ps, |
const T & | t1 = T(1) |
||
) |
Constructs a categorical distribution over the integers {1, ..., K}, where K is the length of the given vector.
ps | A kjb::Vector of probabilities. |
kjb::Categorical_distribution< T >::Categorical_distribution | ( | const std::vector< T > & | values, |
const std::vector< double > & | probabilities | ||
) |
Constructs a categorical distribution over a set of values.
values | A set of values to define probabilities over |
probabilities | The probabilities corresponding to the values. |
|
inline |
Constructs a categorical distribution over a set of values.
values_begin | Beginning of a sequence of values to define probabilities over |
values_end | End of a sequence of values to define probabilities over |
probabilities_begin | The beginning of a sequence of probabilities corresponding to the values. |
d | A map containing the distribution. It must be such that P(X = x) = d[x]. |
|
inline |
Constructs an empirical distribution from a map of vals to counts.
m | A map containing the distribution. It must be such that P(X = x) is proportional to m[x]. |
kjb::Categorical_distribution< T >::Categorical_distribution | ( | const T & | min, |
const T & | max, | ||
const T & | step | ||
) |
Constructs a categorical distribution limits.
Creates a uniform distribution over the set {min, min + step, ..., max}, where each element has probability step / (max - min + 1).
min | smallest element of the support |
max | largest element of the support |
step | gap between elements of the support |
|
inline |
Creates a two-element categorical distribution.
This constructore creates a two-element distribution, with P(X = x1) = p1 and P(X = x2) = p2. Remember that p1 + p2 = 1.
(wait, so this is just a bernoulli distribution? suggest removing this constructor –kyle, March 13, 2012)
|
inline |
Copy-ctor: needed to make sure init_cdf_ gets called.
|
inline |
|
inline |
Alias of insert.
Deprecated in favor of the more STL-esque name, insert().
|
inlinestatic |
Named constructor
Similar to the constructor that recieves a map of value-weight pairs, but in this case, the weights are given in log-space.
This constructor converts to normalized non-log weights, without losing precision even when the unnormalized weights are extremely small.
|
inline |
weight | Remove an item from the collection. |
Cumulative distrbution will be re-constructed from scratch, requiring O(n) time.
Illegal_argument | if key does not exist in the collection. |
|
inline |
weight | Unnormalized weight of new atom. This is added to the total of atom weights, and the normalization constant is updated. |
Running time is O(log n)
|
inline |
Assignment: needed to make sure init_cdf_ gets called.
|
inline |
|
inline |
Size of this distribution.
Returns the size of the support of this distribution
|
friend |
|
friend |
|
friend |