]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
a945c346 | 3 | // Copyright (C) 2005-2024 Free Software Foundation, Inc. |
4569a895 AT |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the terms | |
7 | // of the GNU General Public License as published by the Free Software | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
9 | // version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, but | |
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License | |
748086b7 JJ |
17 | // along with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
4569a895 AT |
20 | |
21 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
22 | ||
23 | // Permission to use, copy, modify, sell, and distribute this software | |
24 | // is hereby granted without fee, provided that the above copyright | |
25 | // notice appears in all copies, and that both that copyright notice | |
26 | // and this permission notice appear in supporting documentation. None | |
27 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
28 | // representation about the suitability of this software for any | |
29 | // purpose. It is provided "as is" without express or implied | |
30 | // warranty. | |
31 | ||
32 | /** | |
382a1351 | 33 | * @file result_recorder.hpp |
4569a895 AT |
34 | * Contains a class for recording results |
35 | */ | |
36 | ||
37 | #ifndef PB_DS_RES_RECORDER_HPP | |
38 | #define PB_DS_RES_RECORDER_HPP | |
39 | ||
40 | #include <statistic/sample_mean.hpp> | |
382a1351 | 41 | #include <statistic/sample_variance.hpp> |
4569a895 AT |
42 | #include <statistic/sample_mean_confidence_checker.hpp> |
43 | ||
5e11f978 | 44 | namespace __gnu_pbds |
4569a895 | 45 | { |
4569a895 AT |
46 | namespace test |
47 | { | |
4569a895 AT |
48 | namespace detail |
49 | { | |
4569a895 AT |
50 | /* |
51 | * Records results until the probability that the sample mean is 10% away | |
382a1351 | 52 | * from the true mean is ~ 0.05. |
4569a895 | 53 | */ |
382a1351 BK |
54 | template<typename Value_Type> |
55 | class result_recorder | |
4569a895 AT |
56 | { |
57 | public: | |
58 | typedef Value_Type value_type; | |
59 | ||
382a1351 BK |
60 | result_recorder() |
61 | : m_sample_mean(value_type()), m_sample_var(value_type()) | |
62 | { } | |
4569a895 AT |
63 | |
64 | bool | |
382a1351 | 65 | add_result(value_type res); |
4569a895 AT |
66 | |
67 | inline value_type | |
382a1351 BK |
68 | get_sample_mean() const |
69 | { return m_sample_mean; } | |
4569a895 AT |
70 | |
71 | private: | |
382a1351 | 72 | typedef std::list<value_type> list_type; |
4569a895 | 73 | |
382a1351 | 74 | list_type m_l; |
4569a895 | 75 | value_type m_sample_mean; |
4569a895 AT |
76 | value_type m_sample_var; |
77 | }; | |
78 | ||
4569a895 | 79 | |
382a1351 | 80 | template<typename Value_Type> |
4569a895 | 81 | bool |
382a1351 BK |
82 | result_recorder<Value_Type>:: |
83 | add_result(value_type res) | |
4569a895 AT |
84 | { |
85 | m_l.push_back(res); | |
382a1351 BK |
86 | m_sample_mean = sample_mean(m_l.begin(), m_l.end()); |
87 | m_sample_var = sample_variance(m_l.begin(), m_l.end(), m_sample_mean); | |
4569a895 | 88 | |
382a1351 BK |
89 | size_t dist = std::distance(m_l.begin(), m_l.end()); |
90 | return sample_mean_confidence_checker(m_sample_mean, m_sample_var, | |
91 | dist, 0.1); | |
4569a895 | 92 | } |
4569a895 | 93 | } // namespace detail |
4569a895 | 94 | } // namespace test |
5e11f978 | 95 | } // namespace __gnu_pbds |
4569a895 | 96 | |
f92ab29f | 97 | #endif |
4569a895 | 98 |