yat  0.21pre
PercentileConfidenceInterval.h
1 #ifndef _theplu_yat_statistics_percentile_confidence_interval_
2 #define _theplu_yat_statistics_percentile_confidence_interval_
3 
4 // $Id: PercentileConfidenceInterval.h 4036 2021-01-24 01:02:57Z peter $
5 
6 /*
7  Copyright (C) 2021 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "yat/utility/yat_assert.h"
26 
27 #include <boost/concept_check.hpp>
28 #include <boost/iterator/iterator_concepts.hpp>
29 
30 #include <boost/math/distributions/binomial.hpp>
31 
32 #include <algorithm>
33 #include <vector>
34 
35 namespace theplu {
36 namespace yat {
37 namespace statistics {
38 
56  {
57  public:
63  PercentileConfidenceInterval(double k, double level);
64 
65 
78  template<typename RandomAccessIterator>
79  void operator()(RandomAccessIterator first, RandomAccessIterator last,
80  bool sorted=false)
81  {
82  typedef RandomAccessIterator T;
83  typedef typename std::iterator_traits<T>::value_type value_type;
84  BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<T>));
85  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<T>));
86  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
87  prepare(last - first);
88  process(first, last, sorted);
89  }
90 
94  double alpha(void) const;
95 
99  double lower(void) const;
100 
104  double k(void) const;
105 
109  double upper(void) const;
110 
111  private:
112  double alpha_;
113  double k_;
114  size_t n_;
115  size_t lower_index_;
116  double lower_;
117  size_t upper_index_;
118  double upper_;
119 
120  void prepare(size_t n);
121 
122  template<typename RandomAccessIterator>
123  void process(RandomAccessIterator first, RandomAccessIterator last,
124  bool sorted)
125  {
126  if (!sorted) {
127  std::vector<double> v(first, last);
128  std::sort(v.begin(), v.end());
129  process(v.begin(), v.end(), true);
130  return;
131  }
132  lower_ = first[lower_index_];
133  upper_ = first[upper_index_];
134  }
135 
136  };
137 
138 }}} // of namespace statistics, yat, and theplu
139 
140 #endif
The Department of Theoretical Physics namespace as we define it.
void operator()(RandomAccessIterator first, RandomAccessIterator last, bool sorted=false)
Definition: PercentileConfidenceInterval.h:79
Definition: PercentileConfidenceInterval.h:55

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14