Changeset 1926
- Timestamp:
- Apr 30, 2009, 4:02:14 PM (12 years ago)
- Location:
- branches/0.5-stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.5-stable/test/statistics_test.cc
r1797 r1926 6 6 Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér 7 7 Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson 8 Copyright (C) 2009 Peter Johansson 8 9 9 10 This file is part of the yat library, http://dev.thep.lu.se/yat … … 33 34 #include <cstdlib> 34 35 #include <iostream> 36 #include <limits> 35 37 #include <map> 36 38 #include <vector> … … 38 40 using namespace theplu::yat; 39 41 void test_percentiler(test::Suite&); 42 void test_percentiler_nan(test::Suite&); 40 43 41 44 template<typename RandomAccessIterator> … … 71 74 // testing percentile2 72 75 test_percentiler(suite); 76 77 // test weighted percentiler with NaNs 78 test_percentiler_nan(suite); 73 79 74 80 double skewness_gsl=statistics::skewness(gsl_vec); … … 144 150 } 145 151 152 void test_percentiler_nan(test::Suite& suite) 153 { 154 using utility::DataWeight; 155 std::vector<double> v; 156 v.push_back(1); 157 v.push_back(10); 158 v.push_back(4); 159 v.push_back(2); 160 std::vector<DataWeight> wv(5); 161 wv[0] = DataWeight(v[0]); 162 wv[1] = DataWeight(v[1]); 163 wv[2] = DataWeight(std::numeric_limits<double>::quiet_NaN(), 0.0); 164 wv[3] = DataWeight(v[2]); 165 wv[4] = DataWeight(v[3]); 166 167 cmp_percentiler(suite, v.begin(), v.end(), wv.begin(), wv.end()); 168 } 169 146 170 template<typename RandomAccessIterator> 147 171 void test_percentiler(test::Suite& suite, -
branches/0.5-stable/yat/statistics/Percentiler.h
r1797 r1926 6 6 /* 7 7 Copyright (C) 2008 Jari Häkkinen, Peter Johansson 8 Copyright (C) 2009 Peter Johansson 8 9 9 10 This file is part of the yat library, http://dev.thep.lu.se/yat … … 184 185 std::vector<utility::DataWeight> v_copy; 185 186 v_copy.reserve(last-first); 186 std::copy(first, last, std::back_inserter(v_copy)); 187 utility::iterator_traits<RandomAccessIterator> traits; 188 for ( ; first!=last; ++first) 189 if (traits.weight(first)) // ignore zero weights 190 v_copy.push_back(*first); 187 191 std::sort(v_copy.begin(), v_copy.end()); 188 192 return calculate(v_copy.begin(), v_copy.end(), true, tag);
Note: See TracChangeset
for help on using the changeset viewer.