2510 |
08 Jul 11 |
peter |
// $Id$ |
2510 |
08 Jul 11 |
peter |
2 |
|
2510 |
08 Jul 11 |
peter |
3 |
/* |
3875 |
05 Mar 20 |
peter |
Copyright (C) 2011, 2012, 2016, 2020 Peter Johansson |
2510 |
08 Jul 11 |
peter |
5 |
|
2510 |
08 Jul 11 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2510 |
08 Jul 11 |
peter |
7 |
|
2510 |
08 Jul 11 |
peter |
The yat library is free software; you can redistribute it and/or |
2510 |
08 Jul 11 |
peter |
modify it under the terms of the GNU General Public License as |
2510 |
08 Jul 11 |
peter |
published by the Free Software Foundation; either version 3 of the |
2510 |
08 Jul 11 |
peter |
License, or (at your option) any later version. |
2510 |
08 Jul 11 |
peter |
12 |
|
2510 |
08 Jul 11 |
peter |
The yat library is distributed in the hope that it will be useful, |
2510 |
08 Jul 11 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2510 |
08 Jul 11 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2510 |
08 Jul 11 |
peter |
General Public License for more details. |
2510 |
08 Jul 11 |
peter |
17 |
|
2510 |
08 Jul 11 |
peter |
You should have received a copy of the GNU General Public License |
2510 |
08 Jul 11 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2510 |
08 Jul 11 |
peter |
20 |
*/ |
2510 |
08 Jul 11 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2510 |
08 Jul 11 |
peter |
24 |
#include "Suite.h" |
2510 |
08 Jul 11 |
peter |
25 |
|
2510 |
08 Jul 11 |
peter |
26 |
#include "yat/statistics/TukeyBiweightEstimator.h" |
2510 |
08 Jul 11 |
peter |
27 |
|
3512 |
22 Jul 16 |
peter |
28 |
#include <boost/concept_archetype.hpp> |
3512 |
22 Jul 16 |
peter |
29 |
#include <boost/iterator/iterator_archetypes.hpp> |
3512 |
22 Jul 16 |
peter |
30 |
|
2510 |
08 Jul 11 |
peter |
31 |
#include <vector> |
2510 |
08 Jul 11 |
peter |
32 |
|
2510 |
08 Jul 11 |
peter |
33 |
using namespace theplu::yat; |
2510 |
08 Jul 11 |
peter |
34 |
using namespace statistics; |
2510 |
08 Jul 11 |
peter |
35 |
|
2510 |
08 Jul 11 |
peter |
36 |
template<typename T> |
2510 |
08 Jul 11 |
peter |
37 |
void do_test(const T& data, double, test::Suite& suite); |
2510 |
08 Jul 11 |
peter |
38 |
|
2510 |
08 Jul 11 |
peter |
39 |
int main(int argc,char* argv[]) |
3512 |
22 Jul 16 |
peter |
40 |
{ |
2510 |
08 Jul 11 |
peter |
41 |
test::Suite suite(argc, argv); |
2510 |
08 Jul 11 |
peter |
42 |
|
2510 |
08 Jul 11 |
peter |
43 |
std::vector<double> x; |
2510 |
08 Jul 11 |
peter |
44 |
x.push_back(100); |
2510 |
08 Jul 11 |
peter |
45 |
x.push_back(-10); |
2510 |
08 Jul 11 |
peter |
46 |
x.push_back(-10); |
2510 |
08 Jul 11 |
peter |
47 |
x.push_back(0); |
2510 |
08 Jul 11 |
peter |
48 |
x.push_back(1); |
2510 |
08 Jul 11 |
peter |
49 |
x.push_back(2); |
2510 |
08 Jul 11 |
peter |
50 |
x.push_back(3); |
2510 |
08 Jul 11 |
peter |
51 |
x.push_back(4); |
2510 |
08 Jul 11 |
peter |
52 |
do_test(x, 2.0, suite); |
2510 |
08 Jul 11 |
peter |
53 |
std::vector<utility::DataWeight> xw; |
2510 |
08 Jul 11 |
peter |
54 |
xw.push_back(utility::DataWeight(2,1.1)); |
2510 |
08 Jul 11 |
peter |
55 |
do_test(xw, 2, suite); |
2510 |
08 Jul 11 |
peter |
56 |
xw.push_back(utility::DataWeight(0,1.1)); |
2510 |
08 Jul 11 |
peter |
57 |
do_test(xw, 1, suite); |
2510 |
08 Jul 11 |
peter |
58 |
xw.push_back(utility::DataWeight(2,0)); |
2510 |
08 Jul 11 |
peter |
59 |
do_test(xw, 1, suite); |
2510 |
08 Jul 11 |
peter |
60 |
xw.push_back(utility::DataWeight(2000,1)); |
2510 |
08 Jul 11 |
peter |
61 |
do_test(xw, 1, suite); |
2510 |
08 Jul 11 |
peter |
62 |
xw.push_back(utility::DataWeight(1,10)); |
2510 |
08 Jul 11 |
peter |
63 |
do_test(xw, 1, suite); |
2510 |
08 Jul 11 |
peter |
64 |
|
3512 |
22 Jul 16 |
peter |
// do not run compilation tests |
3512 |
22 Jul 16 |
peter |
66 |
if (false) { |
3870 |
24 Feb 20 |
peter |
67 |
typedef boost::iterator_archetypes::readable_lvalue_iterator_t Access; |
3512 |
22 Jul 16 |
peter |
68 |
typedef boost::random_access_traversal_tag Traversal; |
3512 |
22 Jul 16 |
peter |
69 |
boost::iterator_archetype<double, Access, Traversal> input; |
3512 |
22 Jul 16 |
peter |
70 |
TukeyBiweightEstimator estimator; |
3512 |
22 Jul 16 |
peter |
71 |
double x = estimator(input, input); |
3870 |
24 Feb 20 |
peter |
72 |
typedef boost::iterator_archetypes::readable_iterator_t Access2; |
3870 |
24 Feb 20 |
peter |
73 |
boost::iterator_archetype<utility::DataWeight, Access2, Traversal> input2; |
3512 |
22 Jul 16 |
peter |
74 |
x = estimator(input2, input2); |
3512 |
22 Jul 16 |
peter |
75 |
test::avoid_compiler_warning(x); |
3512 |
22 Jul 16 |
peter |
76 |
} |
3512 |
22 Jul 16 |
peter |
77 |
|
2510 |
08 Jul 11 |
peter |
78 |
return suite.return_value(); |
2510 |
08 Jul 11 |
peter |
79 |
} |
2510 |
08 Jul 11 |
peter |
80 |
|
2510 |
08 Jul 11 |
peter |
81 |
template<typename T> |
2510 |
08 Jul 11 |
peter |
82 |
void do_test(const T& data, double correct, test::Suite& suite) |
2510 |
08 Jul 11 |
peter |
83 |
{ |
2510 |
08 Jul 11 |
peter |
84 |
TukeyBiweightEstimator estimator(5, false); |
2510 |
08 Jul 11 |
peter |
85 |
double x = estimator(data.begin(), data.end()); |
2558 |
24 Sep 11 |
peter |
86 |
suite.add(suite.equal(x, correct, 2)); |
2510 |
08 Jul 11 |
peter |
87 |
double y = estimator(data.begin(), data.end()); |
2510 |
08 Jul 11 |
peter |
88 |
TukeyBiweightEstimator estimator2(5, true); |
2510 |
08 Jul 11 |
peter |
89 |
double z = estimator2(data.begin(), data.end()); |
2510 |
08 Jul 11 |
peter |
90 |
z += z; // avoid compiler warning |
2510 |
08 Jul 11 |
peter |
91 |
suite.add(suite.equal(x, y)); |
2510 |
08 Jul 11 |
peter |
92 |
} |