ModErn Text Analysis
META Enumerates Textual Applications
statistics.h
Go to the documentation of this file.
1 
9 #ifndef META_STATS_STATISTICS_H_
10 #define META_STATS_STATISTICS_H_
11 
12 #include <cmath>
13 #include <type_traits>
14 
15 namespace meta
16 {
17 namespace stats
18 {
19 
31 template <class Dist, class Fun>
32 double expected_value(Dist&& dist, Fun&& fun)
33 {
34  using T = typename std::remove_reference<Dist>::type::event_type;
35  auto total = 0.0;
36  dist.each_seen_event([&](const T& event)
37  {
38  total += dist.probability(event) * fun(event);
39  });
40  return total;
41 }
42 
49 template <class Dist>
50 double entropy(Dist&& dist)
51 {
52  using T = typename std::remove_reference<Dist>::type::event_type;
53  return expected_value(dist, [&](const T& event)
54  {
55  return -std::log2(dist.probability(event));
56  });
57 }
58 }
59 }
60 #endif
double expected_value(Dist &&dist, Fun &&fun)
Computation for where is specified by the dist parameter and is the fun parameter.
Definition: statistics.h:32
double entropy(Dist &&dist)
Computes the entropy .
Definition: statistics.h:50
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