1 | // $Id: LoglikelihoodRatioTestBinomial.cc 3134 2013-11-27 06:12:16Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2013 Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 3 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | |
---|
24 | #include "LoglikelihoodRatioTestBinomial.h" |
---|
25 | |
---|
26 | #include <numeric> |
---|
27 | #include <cassert> |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | namespace yat { |
---|
31 | namespace statistics { |
---|
32 | |
---|
33 | LoglikelihoodRatioTestBinomial::LoglikelihoodRatioTestBinomial(size_t n) |
---|
34 | : neg_(n, 0), pos_(n, 0) |
---|
35 | {} |
---|
36 | |
---|
37 | void LoglikelihoodRatioTestBinomial::add(size_t population, bool positive, |
---|
38 | long int n) |
---|
39 | { |
---|
40 | assert(population < neg_.size()); |
---|
41 | assert(population < pos_.size()); |
---|
42 | if (positive) |
---|
43 | pos_[population] += n; |
---|
44 | else |
---|
45 | neg_[population] += n; |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | unsigned long int LoglikelihoodRatioTestBinomial::n(void) const |
---|
50 | { |
---|
51 | return negative() + positive(); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | unsigned long int LoglikelihoodRatioTestBinomial::n(size_t i) const |
---|
56 | { |
---|
57 | assert(i<neg_.size()); |
---|
58 | assert(i<pos_.size()); |
---|
59 | return pos_[i] + neg_[i]; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | unsigned long int LoglikelihoodRatioTestBinomial::negative(void) const |
---|
64 | { |
---|
65 | return std::accumulate(neg_.begin(), neg_.end(), 0); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | unsigned long int LoglikelihoodRatioTestBinomial::negative(size_t i) const |
---|
70 | { |
---|
71 | assert(i<neg_.size()); |
---|
72 | return neg_[i]; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | unsigned long int LoglikelihoodRatioTestBinomial::positive(void) const |
---|
77 | { |
---|
78 | return std::accumulate(pos_.begin(), pos_.end(), 0); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | unsigned long int LoglikelihoodRatioTestBinomial::positive(size_t i) const |
---|
83 | { |
---|
84 | assert(i<pos_.size()); |
---|
85 | return pos_[i]; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | size_t LoglikelihoodRatioTestBinomial::size(void) const |
---|
90 | { |
---|
91 | assert(neg_.size()==pos_.size()); |
---|
92 | return neg_.size(); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | double LoglikelihoodRatioTestBinomial::operator()(void) const |
---|
97 | { |
---|
98 | return 0.0; |
---|
99 | } |
---|
100 | |
---|
101 | }}} // of namespace theplu yat statistics |
---|