Changeset 3138
- Timestamp:
- Nov 29, 2013, 3:07:58 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Makefile.am
r3134 r3138 59 59 test/kernel_pca.test test/kernel.test \ 60 60 test/knn.test test/kolmogorov_smirnov.test test/large_file.test \ 61 test/l oglikelihood_ratio_test_binomial.test \61 test/likelihood_ratio_test_binomial.test \ 62 62 test/matrix_lookup.test \ 63 63 test/matrix_lookup_weighted.test test/matrix.test \ … … 81 81 82 82 # tests not passing through yet 83 XFAIL_TESTS = test/loglikelihood_ratio_test_binomial.test83 XFAIL_TESTS = 84 84 85 85 DISTRIBUTED_TESTS = \ -
trunk/test/likelihood_ratio_test_binomial.cc
r3134 r3138 24 24 #include "Suite.h" 25 25 26 #include "yat/statistics/L oglikelihoodRatioTestBinomial.h"26 #include "yat/statistics/LikelihoodRatioTestBinomial.h" 27 27 28 28 using namespace theplu::yat; … … 32 32 test::Suite suite(argc, argv); 33 33 34 statistics::L oglikelihoodRatioTestBinomial lrt;34 statistics::LikelihoodRatioTestBinomial lrt; 35 35 36 36 suite.add(lrt.size() == 2); … … 49 49 suite.add(lrt.negative(1) == 5000); 50 50 51 double log_lambda = lrt ();51 double log_lambda = lrt.llr(); 52 52 suite.out() << log_lambda << "\n"; 53 53 suite.add(log_lambda > 0); -
trunk/yat/statistics/LikelihoodRatioTestBinomial.cc
r3134 r3138 22 22 #include <config.h> 23 23 24 #include "L oglikelihoodRatioTestBinomial.h"24 #include "LikelihoodRatioTestBinomial.h" 25 25 26 #include <cassert> 27 #include <cmath> 26 28 #include <numeric> 27 #include <cassert>28 29 29 30 namespace theplu { … … 31 32 namespace statistics { 32 33 33 L oglikelihoodRatioTestBinomial::LoglikelihoodRatioTestBinomial(size_t n)34 : neg_(n, 0), pos_(n, 0)34 LikelihoodRatioTestBinomial::LikelihoodRatioTestBinomial(size_t n) 35 : count_(2, n, 0) 35 36 {} 36 37 37 void L oglikelihoodRatioTestBinomial::add(size_t population, bool positive,38 void LikelihoodRatioTestBinomial::add(size_t population, bool positive, 38 39 long int n) 39 40 { 40 assert(population < neg_.size()); 41 assert(population < pos_.size()); 42 if (positive) 43 pos_[population] += n; 44 else 45 neg_[population] += n; 41 assert(population < count_.columns()); 42 assert(population < count_.columns()); 43 count_(positive ? 1 : 0, population) += n; 46 44 } 47 45 48 46 49 unsigned long int L oglikelihoodRatioTestBinomial::n(void) const47 unsigned long int LikelihoodRatioTestBinomial::n(void) const 50 48 { 51 return negative() + positive();49 return positive() + negative(); 52 50 } 53 51 54 52 55 unsigned long int L oglikelihoodRatioTestBinomial::n(size_t i) const53 unsigned long int LikelihoodRatioTestBinomial::n(size_t i) const 56 54 { 57 assert(i<neg_.size()); 58 assert(i<pos_.size()); 59 return pos_[i] + neg_[i]; 55 return positive(i) + negative(i); 60 56 } 61 57 62 58 63 unsigned long int L oglikelihoodRatioTestBinomial::negative(void) const59 unsigned long int LikelihoodRatioTestBinomial::negative(void) const 64 60 { 65 return s td::accumulate(neg_.begin(), neg_.end(), 0);61 return sum(count_.row_const_view(0)); 66 62 } 67 63 68 64 69 unsigned long int L oglikelihoodRatioTestBinomial::negative(size_t i) const65 unsigned long int LikelihoodRatioTestBinomial::negative(size_t i) const 70 66 { 71 assert(i< neg_.size());72 return neg_[i];67 assert(i<count_.columns()); 68 return count_(0, i); 73 69 } 74 70 75 71 76 unsigned long int L oglikelihoodRatioTestBinomial::positive(void) const72 unsigned long int LikelihoodRatioTestBinomial::positive(void) const 77 73 { 78 return s td::accumulate(pos_.begin(), pos_.end(), 0);74 return sum(count_.row_const_view(1)); 79 75 } 80 76 81 77 82 unsigned long int L oglikelihoodRatioTestBinomial::positive(size_t i) const78 unsigned long int LikelihoodRatioTestBinomial::positive(size_t i) const 83 79 { 84 assert(i< pos_.size());85 return pos_[i];80 assert(i<count_.columns()); 81 return count_(1, i); 86 82 } 87 83 88 84 89 size_t L oglikelihoodRatioTestBinomial::size(void) const85 size_t LikelihoodRatioTestBinomial::size(void) const 90 86 { 91 assert(neg_.size()==pos_.size()); 92 return neg_.size(); 87 return count_.columns(); 93 88 } 94 89 95 90 96 double L oglikelihoodRatioTestBinomial::operator()(void) const91 double LikelihoodRatioTestBinomial::llr(void) const 97 92 { 98 return 0.0; 93 double res = 0; 94 for (size_t i=0; i<size(); ++i) { 95 double ni = n(i); 96 if (positive(i)) 97 res += positive(i) * std::log(positive(i)/ni); 98 if (negative(i)) 99 res += negative(i) * std::log(negative(i)/ni); 100 } 101 double npos = positive(); 102 double nneg = negative(); 103 double n = npos + nneg; 104 res -= npos * std::log(npos/n); 105 res -= nneg * std::log(nneg/n); 106 return res; 99 107 } 100 108 -
trunk/yat/statistics/LikelihoodRatioTestBinomial.h
r3134 r3138 23 23 */ 24 24 25 #include <vector>25 #include "yat/utility/Matrix.h" 26 26 27 27 namespace theplu { … … 30 30 31 31 /** 32 \brief L oglikelihood-ratio test for binomial data32 \brief Likelihood-ratio test for binomial data 33 33 34 34 This class is useful when having binomial data for several … … 36 36 differen samples. 37 37 */ 38 class L oglikelihoodRatioTestBinomial38 class LikelihoodRatioTestBinomial 39 39 { 40 40 public: … … 43 43 \param n number of populations in data 44 44 */ 45 L oglikelihoodRatioTestBinomial(size_t n=2);45 LikelihoodRatioTestBinomial(size_t n=2); 46 46 47 47 /** … … 90 90 /** 91 91 \brief Calculate natural logarithm of likelihood ratios 92 93 The logairithm of the likelihood ratio is calculated as 94 \f$ LLR = \sum_i \left ( n_{i+} \ln \frac{n_{i+}}{n_i} + 95 n_{i-} \ln \frac{n_{i-}}{n_i} \right ) - 96 \left ( n_+ \ln \frac{n_+}{n} + 97 n_- \ln \frac{n_-}{n} \right ) 98 \f$ 92 99 */ 93 double operator()(void) const;100 double llr(void) const; 94 101 95 102 private: 96 std::vector<unsigned long int> neg_; 97 std::vector<unsigned long int> pos_; 103 utility::Matrix count_; 98 104 }; 99 105 -
trunk/yat/statistics/Makefile.am
r3134 r3138 32 32 yat/statistics/Kendall.cc yat/statistics/KolmogorovSmirnov.cc \ 33 33 yat/statistics/KolmogorovSmirnovOneSample.cc \ 34 yat/statistics/L oglikelihoodRatioTestBinomial.cc \34 yat/statistics/LikelihoodRatioTestBinomial.cc \ 35 35 yat/statistics/Pearson.cc \ 36 36 yat/statistics/PearsonCorrelation.cc yat/statistics/Percentiler.cc \ … … 62 62 $(srcdir)/yat/statistics/KolmogorovSmirnov.h \ 63 63 $(srcdir)/yat/statistics/KolmogorovSmirnovOneSample.h \ 64 $(srcdir)/yat/statistics/L oglikelihoodRatioTestBinomial.h \64 $(srcdir)/yat/statistics/LikelihoodRatioTestBinomial.h \ 65 65 $(srcdir)/yat/statistics/Pearson.h \ 66 66 $(srcdir)/yat/statistics/PearsonCorrelation.h \
Note: See TracChangeset
for help on using the changeset viewer.