ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Private Attributes | List of all members
meta::stats::multinomial< T > Class Template Reference

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_
 

Detailed Description

template<class T>
class meta::stats::multinomial< T >

Represents a multinomial/categorical distribution.

Constructor & Destructor Documentation

template<class T >
meta::stats::multinomial< T >::multinomial ( )

Creates a multinomial distribution.

No events or probabilities are initialized.

template<class T>
meta::stats::multinomial< T >::multinomial ( dirichlet< T >  prior)

Creates a multinomial distribution with a Dirichlet prior distribution over the parameters.

Parameters
priorThe prior distribution

Member Function Documentation

template<class T>
void meta::stats::multinomial< T >::increment ( const T &  event,
double  count 
)

Observes an event and adjusts the distribution's probabilities accordingly.

Parameters
eventThe event observed
countThe number of times it was observed
template<class T>
void meta::stats::multinomial< T >::decrement ( const T &  event,
double  count 
)

Removes observations of an event and adjusts the distribution's probabilities accordingly.

Parameters
eventThe event
countThe number of counts of this event to remove
template<class T>
double meta::stats::multinomial< T >::counts ( const T &  event) const
Parameters
eventThe event
Returns
the number of observations (including the prior) for this event
template<class T>
double meta::stats::multinomial< T >::counts ( ) const
Returns
the total number of observations (including the prior)
template<class T >
template<class Fun >
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.

Parameters
funThe function to run for each seen event for this distribution
template<class T >
const dirichlet< T > & meta::stats::multinomial< T >::prior ( ) const
Returns
the prior
template<class T >
template<class Generator >
const T & meta::stats::multinomial< T >::operator() ( Generator &&  gen) const

Samples from the distribution.

Parameters
genThe random number generator to be used
template<class T>
multinomial< T > & meta::stats::multinomial< T >::operator+= ( const multinomial< T > &  other)

Adds in the observations of another multinomial to this one.

Parameters
otherThe other multinomial to merge with.

The documentation for this class was generated from the following files: