ModErn Text Analysis
META Enumerates Textual Applications
dirichlet.h
Go to the documentation of this file.
1 
9 #ifndef META_STATS_DIRICHLET_H_
10 #define META_STATS_DIRICHLET_H_
11 
12 #include <cstdint>
13 #include <memory>
14 #include "util/sparse_vector.h"
15 
16 namespace meta
17 {
18 namespace stats
19 {
20 
26 template <class T>
27 class dirichlet
28 {
29  public:
37  dirichlet(double alpha, uint64_t n);
38 
47  template <class Iter>
48  dirichlet(Iter begin, Iter end);
49 
53  dirichlet(const dirichlet& other);
54 
58  dirichlet(dirichlet&& other);
59 
64 
68  ~dirichlet();
69 
77  double pseudo_counts(const T& event) const;
78 
83  double pseudo_counts() const;
84 
89  void swap(dirichlet& other);
90 
91  private:
92 
93  enum class type
94  {
95  SYMMETRIC,
96  ASYMMETRIC
97  } type_;
98 
99  union parameters
100  {
101  parameters()
102  {
103  // nothing
104  }
105 
106  parameters(double alpha)
107  {
108  fixed_alpha_ = alpha;
109  }
110 
111  template <class Iter>
112  parameters(Iter begin, Iter end)
113  {
114  new (&sparse_alpha_) util::sparse_vector<T, double>{begin, end};
115  }
116 
117  ~parameters()
118  {
119  // nothing
120  }
121 
122  double fixed_alpha_;
123  util::sparse_vector<T, double> sparse_alpha_;
124  } params_;
125 
126  double alpha_sum_;
127 };
128 }
129 }
130 
131 #include "stats/dirichlet.tcc"
132 #endif
dirichlet & operator=(dirichlet rhs)
Assignment operator.
Definition: dirichlet.tcc:68
Represents a Dirichlet distribution.
Definition: dirichlet.h:27
~dirichlet()
Destructor.
Definition: dirichlet.tcc:75
double pseudo_counts() const
Obtains the number of total "pseudo-counts" associated with this distribution when used as a prior fo...
Definition: dirichlet.tcc:101
Definition: dirichlet.h:99
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
void swap(dirichlet &other)
Swaps this dirichlet with the parameter.
Definition: dirichlet.tcc:107
dirichlet(double alpha, uint64_t n)
Constructs a symmetric Dirichlet with concentration parameter and dimension .
Definition: dirichlet.tcc:16