ModErn Text Analysis
META Enumerates Textual Applications
|
Represents a multinomial/categorical distribution. More...
#include <multinomial.h>
Public Types | |
using | event_type = T |
The event type for this distribution. | |
Public Member Functions | |
multinomial () | |
Creates a multinomial distribution. More... | |
multinomial (dirichlet< T > prior) | |
Creates a multinomial distribution with a Dirichlet prior distribution over the parameters. More... | |
void | increment (const T &event, double count) |
Observes an event and adjusts the distribution's probabilities accordingly. More... | |
void | decrement (const T &event, double count) |
Removes observations of an event and adjusts the distribution's probabilities accordingly. More... | |
double | counts (const T &event) const |
double | counts () const |
template<class Fun > | |
void | each_seen_event (Fun &&fun) const |
Runs a function for each observed event for this distribution. More... | |
void | clear () |
Removes all observations. | |
double | probability (const T &event) const |
Obtains the probability of an event. | |
const dirichlet< T > & | prior () const |
template<class Generator > | |
const T & | operator() (Generator &&gen) const |
Samples from the distribution. More... | |
multinomial< T > & | operator+= (const multinomial< T > &other) |
Adds in the observations of another multinomial to this one. More... | |
Private Attributes | |
util::sparse_vector< T, double > | counts_ |
double | total_counts_ |
dirichlet< T > | prior_ |
Represents a multinomial/categorical distribution.
meta::stats::multinomial< T >::multinomial | ( | ) |
Creates a multinomial distribution.
No events or probabilities are initialized.
meta::stats::multinomial< T >::multinomial | ( | dirichlet< T > | prior | ) |
Creates a multinomial distribution with a Dirichlet prior distribution over the parameters.
prior | The prior distribution |
void meta::stats::multinomial< T >::increment | ( | const T & | event, |
double | count | ||
) |
Observes an event and adjusts the distribution's probabilities accordingly.
event | The event observed |
count | The number of times it was observed |
void meta::stats::multinomial< T >::decrement | ( | const T & | event, |
double | count | ||
) |
Removes observations of an event and adjusts the distribution's probabilities accordingly.
event | The event |
count | The number of counts of this event to remove |
double meta::stats::multinomial< T >::counts | ( | const T & | event | ) | const |
event | The event |
double meta::stats::multinomial< T >::counts | ( | ) | const |
void meta::stats::multinomial< T >::each_seen_event | ( | Fun && | fun | ) | const |
Runs a function for each observed event for this distribution.
Note that this does not include the prior, only events that have been explicitly observed with e.g. the increment() function.
fun | The function to run for each seen event for this distribution |
const dirichlet< T > & meta::stats::multinomial< T >::prior | ( | ) | const |
const T & meta::stats::multinomial< T >::operator() | ( | Generator && | gen | ) | const |
Samples from the distribution.
gen | The random number generator to be used |
multinomial< T > & meta::stats::multinomial< T >::operator+= | ( | const multinomial< T > & | other | ) |
Adds in the observations of another multinomial to this one.
other | The other multinomial to merge with. |