ModErn Text Analysis
META Enumerates Textual Applications
multinomial.h
Go to the documentation of this file.
1 
9 #ifndef META_STATS_MULTINOMIAL_H_
10 #define META_STATS_MULTINOMIAL_H_
11 
12 #include <cstdint>
13 #include <random>
14 #include "stats/dirichlet.h"
15 #include "util/sparse_vector.h"
16 
17 namespace meta
18 {
19 namespace stats
20 {
21 
25 template <class T>
27 {
28  public:
32  using event_type = T;
33 
38  multinomial();
39 
47 
55  void increment(const T& event, double count);
56 
64  void decrement(const T& event, double count);
65 
71  double counts(const T& event) const;
72 
76  double counts() const;
77 
86  template <class Fun>
87  void each_seen_event(Fun&& fun) const;
88 
92  void clear();
93 
97  double probability(const T& event) const;
98 
102  const dirichlet<T>& prior() const;
103 
108  template <class Generator>
109  const T& operator()(Generator&& gen) const;
110 
117 
118  private:
120  double total_counts_;
121  dirichlet<T> prior_;
122 };
123 
124 template <class T>
125 multinomial<T> operator+(const multinomial<T>& lhs, const multinomial<T>& rhs)
126 {
127  multinomial<T> res{lhs};
128  res += rhs;
129  return res;
130 }
131 
132 template <class T>
133 multinomial<T> operator+(multinomial<T>&& lhs, const multinomial<T>& rhs)
134 {
135  return lhs += rhs;
136 }
137 
138 template <class T>
139 multinomial<T> operator+(const multinomial<T>& lhs, multinomial<T>&& rhs)
140 {
141  return rhs += lhs;
142 }
143 
144 template <class T>
145 multinomial<T> operator+(multinomial<T>&& lhs, multinomial<T>&& rhs)
146 {
147  return lhs += rhs;
148 }
149 
150 }
151 }
152 #include "stats/multinomial.tcc"
153 #endif
void clear()
Removes all observations.
Definition: multinomial.tcc:65
Represents a Dirichlet distribution.
Definition: dirichlet.h:27
void each_seen_event(Fun &&fun) const
Runs a function for each observed event for this distribution.
Definition: multinomial.tcc:58
const dirichlet< T > & prior() const
Definition: multinomial.tcc:78
void decrement(const T &event, double count)
Removes observations of an event and adjusts the distribution's probabilities accordingly.
Definition: multinomial.tcc:38
double probability(const T &event) const
Obtains the probability of an event.
Definition: multinomial.tcc:72
topic_id event_type
The event type for this distribution.
Definition: multinomial.h:32
const T & operator()(Generator &&gen) const
Samples from the distribution.
Definition: multinomial.tcc:85
void increment(const T &event, double count)
Observes an event and adjusts the distribution's probabilities accordingly.
Definition: multinomial.tcc:31
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
multinomial< T > & operator+=(const multinomial< T > &other)
Adds in the observations of another multinomial to this one.
Definition: multinomial.tcc:99
double counts() const
Definition: multinomial.tcc:51
multinomial()
Creates a multinomial distribution.
Definition: multinomial.tcc:17
Represents a multinomial/categorical distribution.
Definition: multinomial.h:26