SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
statistics.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
68 
75 #ifndef SLIP_STATISTICS_HPP
76 #define SLIP_STATISTICS_HPP
77 
78 #include <iostream>
79 #include <algorithm>
80 #include <iterator>
81 #include <numeric>
82 #include <cassert>
83 #include <cmath>
84 #include <set>
85 #include <vector>
86 #include "Array.hpp"
87 #include "macros.hpp"
88 #include "iterator_types.hpp"
89 #include "Block.hpp"
90 
91 namespace slip
92 {
93 
94 
106 template <typename T>
108 {
114  T& min()
115  {
116  return stat_[0];
117  }
118 
124  {
125  return stat_[1];
126  }
127 
132  T& median()
133  {
134  return stat_[2];
135  }
136 
142  {
143  return stat_[3];
144  }
145 
150  T& max()
151  {
152  return stat_[4];
153  }
154 
159  T& mean()
160  {
161  return stat_[5];
162  }
163 
168  T& std_dev()
169  {
170  return stat_[6];
171  }
172 
177  T& skewness()
178  {
179  return stat_[7];
180  }
181 
186  T& kurtosis()
187  {
188  return stat_[8];
189  }
190 
195  T& cardinal()
196  {
197  return stat_[9];
198  }
199 
205  {
206  return stat_;
207  }
208 
210 };
211 
212  template<typename Integer, typename>
213  struct __cardinal
214  {
215  template <typename _II>
216  static Integer
217  cardinal(_II first, _II last)
218  {
219  return static_cast<Integer>(last-first);
220 
221  }
222  };
223 
224  template<typename Integer>
225  struct __cardinal<Integer,std::random_access_iterator_tag>
226  {
227  template <typename _II>
228  static Integer
229  cardinal(_II first, _II last)
230  {
231  return static_cast<Integer>(last-first);
232  }
233  };
234 
235  template<typename Integer>
236  struct __cardinal<Integer,std::random_access_iterator2d_tag>
237  {
238  template <typename _II>
239  static Integer
240  cardinal(_II first, _II last)
241  {
242  Integer count = 0;
243  while(first != last)
244  {
245  count++;
246  first++;
247  }
248  return count;
249 
250  }
251  };
252 
253 
254  template<typename Integer>
255  struct __cardinal<Integer,std::random_access_iterator3d_tag>
256  {
257  template <typename _II>
258  static Integer
259  cardinal(_II first, _II last)
260  {
262  }
263  };
264 
283  template<typename Integer,typename InputIterator>
284  inline
285  Integer cardinal(InputIterator first,
286  InputIterator last)
287  {
288  typedef typename std::iterator_traits<InputIterator>::iterator_category _Category;
289 
290  return __cardinal<Integer,_Category>::cardinal(first,last);
291  }
292 
312  template<typename Value_T,typename InputIterator>
313  inline
314  Value_T mean(InputIterator first,
315  InputIterator last)
316  {
317  assert(first != last);
318  Value_T sum = Value_T(0);
319  long int count = 0;
320  while(first != last)
321  {
322  sum += *first++;
323  ++count;
324  }
325  return Value_T(sum) / Value_T(count);
326  }
327 
350  template<typename Value_T,typename InputIterator>
351  inline
352  Value_T weighted_mean(InputIterator first,
353  InputIterator last,
354  InputIterator w_first,
355  InputIterator w_last)
356  {
357  assert(first != last);
358  assert(slip::cardinal<std::size_t>(first,last) ==
359  slip::cardinal<std::size_t>(w_first,w_last));
360 
361  Value_T proj = Value_T(0);
362  Value_T sum = Value_T(0);
363  for (; first != last; ++first, ++w_first)
364  {
365  proj = proj + (*first) * (*w_first);
366  sum = sum + *w_first;
367  }
368  return Value_T(proj) / Value_T(sum);
369  }
370 
371 
372 
373 
374 
375 
397  template<typename T, int N, typename InputIterator>
398  inline
399  T nth_moment(InputIterator first, InputIterator last, T mean)
400  {
401  assert(last != first);
402  T __init = T();
403  int count = 0;
404  for (; first != last; ++first)
405  {
406  __init = __init + slip::nth_power<N>(*first - mean);
407  count++;
408  }
409  return __init / count;
410  }
411 
412 
441  template<typename T, typename InputIterator, typename InputIterator2>
442  inline
443  T covariance(InputIterator first, InputIterator last,
444  InputIterator2 first2,
445  T mean1, T mean2)
446  {
447  assert(last != first);
448  T __init = T();
449  long int count = 0;
450  for (; first != last; ++first, ++first2)
451  {
452  __init = __init + (*first - mean1) * (*first2 - mean2);
453  count++;
454  }
455  return __init / count;
456  }
457 
486  template<typename T, typename InputIterator, typename InputIterator2>
487  inline
488  T unbiased_covariance(InputIterator first, InputIterator last,
489  InputIterator2 first2,
490  T mean1, T mean2)
491  {
492  assert(last != first);
493  T __init = T();
494  long int count = 0;
495  for (; first != last; ++first, ++first2)
496  {
497  __init = __init + (*first - mean1) * (*first2 - mean2);
498  count++;
499  }
500  T result = T();
501  if(count != 1)
502  {
503  result = __init / (count - 1);
504  }
505 
506  return result;
507  }
533  template<typename T, typename InputIterator>
534  inline
535  T variance(InputIterator first, InputIterator last, T mean)
536  {
537  return slip::covariance(first,last,first,mean,mean);
538  }
539 
564  template<typename T, typename InputIterator>
565  inline
566  T unbiased_variance(InputIterator first, InputIterator last, T mean)
567  {
568  return slip::unbiased_covariance(first,last,first,mean,mean);
569  }
570 
594  template<typename T, typename InputIterator>
595  inline
596  T std_dev(InputIterator first, InputIterator last, T mean)
597  {
598  return std::sqrt(slip::variance(first,last,mean));
599  }
600 
624  template<typename T, typename InputIterator>
625  inline
626  T unbiased_std_dev(InputIterator first, InputIterator last, T mean)
627  {
628  return std::sqrt(slip::unbiased_variance(first,last,mean));
629  }
630 
631 
664  template<typename T, typename InputIterator>
665  inline
666  T kurtosis(InputIterator first, InputIterator last, T mean)
667  {
668  assert(first != last);
669  T __init = T(0);
670  T __init2 = T(0);
671  long int count = 0;
672  for (; first != last; ++first)
673  {
674  T p2 = slip::nth_power<2>(*first - mean);
675  __init = __init + p2;
676  __init2 = __init2 + (p2 * p2);
677  count++;
678  }
679  T result = T(0);
680  if(__init != T(0))
681  {
682  result = (__init2 * T(count)) / (__init * __init);
683  }
684  return result;
685  }
686 
687 
713  template<typename T, typename InputIterator>
714  inline
715  T unbiased_kurtosis(InputIterator first, InputIterator last, T mean)
716  {
717  assert(slip::cardinal<int>(first,last) > 3);
718  T __init = T(0);
719  T __init2 = T(0);
720  long int count = 0;
721  for (; first != last; ++first)
722  {
723  T p2 = slip::nth_power<2>(*first - mean);
724  __init = __init + p2;
725  __init2 = __init2 + (p2 * p2);
726  count++;
727  }
728  T count_m1 = T(count - 1);
729  T count_m2 = T(count - 2);
730  T count_m3 = T(count - 3);
731 
732  T result = T(0);
733  if(__init != T(0))
734  {
735 
736  result = (((T(count+1)*T(count)* count_m1) * __init2 )
737  / ( (count_m2 * count_m3) * (__init * __init) ))
738  - ( (T(3)* (count_m1*count_m1)) / (count_m2 * count_m3)) + T(3);
739  }
740  return result;
741  }
742 
768  template<typename T, typename InputIterator>
769  inline
770  T skewness(InputIterator first, InputIterator last, T mean)
771  {
772  assert(first != last);
773  T __init = T();
774  T __init2 = T();
775  long int count = 0;
776  for (; first != last; ++first)
777  {
778  T p1 = (*first - mean);
779  T p2 = p1 * p1;
780  __init = __init + p2;
781  __init2 = __init2 + (p2 * p1);
782  count++;
783  }
784  T result = T(0);
785  if(__init != T(0))
786  {
787  result = __init2 / (T(count)*slip::nth_power<3>(std::sqrt(__init/T(count))));
788  }
789  return result;
790  }
791 
818  template<typename T, typename InputIterator>
819  inline
820  T unbiased_skewness(InputIterator first, InputIterator last, T mean)
821  {
822  assert(slip::cardinal<int>(first,last) > 2);
823  T __init = T();
824  T __init2 = T();
825  long int count = 0;
826  for (; first != last; ++first)
827  {
828  T p1 = (*first - mean);
829  T p2 = p1 * p1;
830  __init = __init + p2;
831  __init2 = __init2 + (p2 * p1);
832  count++;
833  }
834  T result = T(0);
835  if(__init != T(0))
836  {
837  result = (__init2 * T(count)) / (T(count-1)*T(count-2)*slip::nth_power<3>(std::sqrt(__init/T(count-1))));
838  }
839  return result;
840 }
841 
842 
864  template<typename T, typename InputIterator>
865  inline
866  T rms(InputIterator first, InputIterator last)
867  {
868  return std::sqrt(slip::covariance(first,last,first,T(0),T(0)));
869  }
870 
871 
888  template<typename InputIterator>
889  inline
890  typename std::iterator_traits<InputIterator>::value_type
891  median_from_sorted_data(InputIterator first, InputIterator last)
892  {
893  return *(first + (last - first) / 2);
894  }
895 
896 
910  template<typename RandomAccessIterator, typename Size>
911  inline
912  typename std::iterator_traits<RandomAccessIterator>::value_type
913  median_from_sorted_data_n(RandomAccessIterator first, Size n)
914  {
915  return *(first + n/2);
916  }
917 
918 
919 
920 
921 
941  template<typename RandomAccessIterator, typename Size>
942  inline
943  typename std::iterator_traits<RandomAccessIterator>::value_type
944  median_from_data_n(RandomAccessIterator first, RandomAccessIterator last,
945  Size n)
946  {
947  assert(last != first);
949  tmp(n,first,last);
950  std::sort(tmp.begin(),tmp.end());
951  return slip::median_from_sorted_data_n(tmp.begin(),n);
952  }
953 
974  template<typename RandomAccessIterator,
975  typename Size,
976  typename StrictWeakOrdering>
977  inline
978  typename std::iterator_traits<RandomAccessIterator>::value_type
979  median_from_data_n(RandomAccessIterator first, RandomAccessIterator last,
980  Size n,
981  StrictWeakOrdering comp)
982  {
983  assert(last != first);
985  tmp(n,first,last);
986  std::sort(tmp.begin(),tmp.end(),comp);
987  return slip::median_from_sorted_data_n(tmp.begin(),n);
988  }
989 
990 
991  template<typename>
992  struct __median
993  {
994  template <typename _II>
995  static typename std::iterator_traits<_II>::value_type
996  median(_II first, _II last)
997  {
998  typedef typename std::iterator_traits<_II>::value_type value_type;
999  return slip::median_from_data_n(first,last,slip::cardinal<int>(first,last));
1000  }
1001  template <typename _II, typename StrictWeakOrdering>
1002  static typename std::iterator_traits<_II>::value_type
1003  median(_II first, _II last, StrictWeakOrdering comp)
1004  {
1005  typedef typename std::iterator_traits<_II>::value_type value_type;
1006  return slip::median_from_data_n(first,last,slip::cardinal<int>(first,last),comp);
1007  }
1008  template <typename _II,typename SizeType>
1009  static typename std::iterator_traits<_II>::value_type
1010  median_n(_II first, _II last, SizeType n)
1011  {
1012  typedef typename std::iterator_traits<_II>::value_type value_type;
1013  return slip::median_from_data_n(first,last,n);
1014  }
1015  template <typename _II,typename SizeType, typename StrictWeakOrdering>
1016  static typename std::iterator_traits<_II>::value_type
1017  median_n(_II first, _II last, SizeType n, StrictWeakOrdering comp)
1018  {
1019  typedef typename std::iterator_traits<_II>::value_type value_type;
1020  return slip::median_from_data_n(first,last,n,comp);
1021  }
1022  };
1023 
1024 
1025  template<>
1026  struct __median<std::random_access_iterator_tag>
1027  {
1028  template <typename _II>
1029  static typename std::iterator_traits<_II>::value_type
1030  median(_II first, _II last)
1031  {
1032  typedef typename std::iterator_traits<_II>::value_type value_type;
1033  return slip::median_from_data_n(first,last,(last-first));
1034  }
1035  template <typename _II, typename StrictWeakOrdering>
1036  static typename std::iterator_traits<_II>::value_type
1037  median(_II first, _II last, StrictWeakOrdering comp)
1038  {
1039  typedef typename std::iterator_traits<_II>::value_type value_type;
1040  return slip::median_from_data_n(first,last,(last-first),comp);
1041  }
1042  template <typename _II,typename SizeType>
1043  static typename std::iterator_traits<_II>::value_type
1044  median_n(_II first, _II last, SizeType n)
1045  {
1046  typedef typename std::iterator_traits<_II>::value_type value_type;
1047  return slip::median_from_data_n(first,last,n);
1048  }
1049 
1050  template <typename _II,typename SizeType, typename StrictWeakOrdering>
1051  static typename std::iterator_traits<_II>::value_type
1052  median_n(_II first, _II last, SizeType n, StrictWeakOrdering comp)
1053  {
1054  typedef typename std::iterator_traits<_II>::value_type value_type;
1055  return slip::median_from_data_n(first,last,n,comp);
1056  }
1057  };
1058 
1077  template<typename RandomAccessIterator>
1078  inline
1079  typename std::iterator_traits<RandomAccessIterator>::value_type
1080  median(RandomAccessIterator first, RandomAccessIterator last)
1081  {
1082  typedef typename std::iterator_traits<RandomAccessIterator>::iterator_category _Category;
1083 
1084  return __median<_Category>::median(first,last);
1085  }
1086 
1087 
1107  template<typename RandomAccessIterator, typename StrictWeakOrdering>
1108  inline
1109  typename std::iterator_traits<RandomAccessIterator>::value_type
1110  median(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp)
1111  {
1112  typedef typename std::iterator_traits<RandomAccessIterator>::iterator_category _Category;
1113 
1114  return __median<_Category>::median(first,last,comp);
1115  }
1116 
1117 
1137  template<typename RandomAccessIterator, typename SizeType>
1138  inline
1139  typename std::iterator_traits<RandomAccessIterator>::value_type
1140  median_n(RandomAccessIterator first, RandomAccessIterator last, SizeType n)
1141  {
1142  typedef typename std::iterator_traits<RandomAccessIterator>::iterator_category _Category;
1143 
1144  return __median<_Category>::median_n(first,last,n);
1145  }
1146 
1167  template<typename RandomAccessIterator, typename SizeType, typename StrictWeakOrdering>
1168  inline
1169  typename std::iterator_traits<RandomAccessIterator>::value_type
1170  median_n(RandomAccessIterator first, RandomAccessIterator last, SizeType n, StrictWeakOrdering comp)
1171  {
1172  typedef typename std::iterator_traits<RandomAccessIterator>::iterator_category _Category;
1173 
1174  return __median<_Category>::median_n(first,last,n,comp);
1175  }
1176 
1177 
1196  template<typename RandomAccessIterator>
1197  inline
1198  typename std::iterator_traits<RandomAccessIterator>::value_type
1199  first_quartile(RandomAccessIterator first, RandomAccessIterator last)
1200  {
1201  assert(last != first);
1202  std::size_t n = slip::cardinal<std::size_t>(first,last);
1204  tmp(n,first,last);
1205  std::sort(tmp.begin(),tmp.end());
1206  return *(tmp.begin()+n/4);
1207  }
1208 
1227  template<typename RandomAccessIterator>
1228  inline
1229  typename std::iterator_traits<RandomAccessIterator>::value_type
1230  third_quartile(RandomAccessIterator first, RandomAccessIterator last)
1231  {
1232  assert(last != first);
1233  std::size_t n=slip::cardinal<std::size_t>(first,last);
1235  tmp(n,first,last);
1236  std::sort(tmp.begin(),tmp.end());
1237  return *((tmp.end()-1)-n/4);
1238  }
1239 
1240 
1241 
1267  template<typename ForwardIterator>
1268  void n_max_elements(ForwardIterator first, ForwardIterator last,
1269  std::vector<ForwardIterator>& max,
1270  const std::size_t n = 1)
1271  {
1272 
1273  assert(n <= slip::cardinal<std::size_t>(first,last));
1274  assert(max.size() == n);
1275  assert(n > 0);
1276  if(n == 1)
1277  {
1278  max[0] = std::max_element(first,last);
1279  }
1280  else
1281  {
1282  std::multiset<ForwardIterator,slip::gt_it<ForwardIterator> > S;
1283 
1284  while(first != last)
1285  {
1286  S.insert(first);
1287  first++;
1288  }
1289 
1290  typename std::multiset<ForwardIterator,gt_it<ForwardIterator> >::iterator it = S.begin();
1291  for(std::size_t i = 0; i < n; ++i)
1292  {
1293  max[i] = *it++;
1294  }
1295 
1296  }
1297 }
1298 
1299 
1325  template<typename ForwardIterator>
1326  void n_min_elements(ForwardIterator first, ForwardIterator last,
1327  std::vector<ForwardIterator>& min,
1328  const std::size_t n = 1)
1329  {
1330  assert(n <= slip::cardinal<std::size_t>(first,last));
1331  assert(min.size() == n);
1332  assert(n > 0);
1333  if(n == 1)
1334  {
1335  min[0] = std::min_element(first,last);
1336  }
1337  else
1338  {
1339  std::multiset<ForwardIterator,slip::lt_it<ForwardIterator> > S;
1340 
1341  while(first != last)
1342  {
1343  S.insert(first);
1344  first++;
1345  }
1346 
1347  typename std::multiset<ForwardIterator,lt_it<ForwardIterator> >::iterator it = S.begin();
1348  for(std::size_t i = 0; i < n; ++i)
1349  {
1350  min[i] = *it++;
1351  }
1352 
1353  }
1354  }
1355 
1380  template<typename RandomAccessIterator, typename RandomAccessIterator2>
1381  void center(RandomAccessIterator first, RandomAccessIterator last,
1382  RandomAccessIterator2 out_first)
1383  {
1384  typedef typename std::iterator_traits<RandomAccessIterator2>::value_type value_type;
1385  value_type mean = slip::mean<value_type>(first,last);
1386 
1387  for (; first != last; ++first, ++out_first)
1388  {
1389  *out_first = (*first - mean);
1390  }
1391  }
1392 
1417  template<typename RandomAccessIterator, typename RandomAccessIterator2>
1418  void studentize(RandomAccessIterator first, RandomAccessIterator last,
1419  RandomAccessIterator2 out_first)
1420  {
1421  typedef typename std::iterator_traits<RandomAccessIterator2>::value_type value_type;
1422  value_type mean = slip::mean<value_type>(first,last);
1423  value_type std_dev = slip::std_dev<value_type>(first,last,mean);
1424  if(std_dev != value_type(0))
1425  {
1426  for (; first != last; ++first, ++out_first)
1427  {
1428  *out_first = (*first - mean) / std_dev;
1429  }
1430  }
1431  else
1432  {
1433  for (; first != last; ++first, ++out_first)
1434  {
1435  *out_first = (*first - mean);
1436  }
1437  }
1438  }
1439 
1440 
1442 
1443 
1475  template<typename Value_T,
1476  typename InputIterator,
1477  typename MaskIterator>
1478  inline
1479  Value_T mean_mask(InputIterator first, InputIterator last,
1480  MaskIterator mask_first,
1481  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1482  {
1483  assert(first != last);
1484  Value_T sum = Value_T(0);
1485  long int count = 0;
1486  while(first != last)
1487  {
1488  if(*mask_first == value)
1489  {
1490  sum += *first;
1491  ++count;
1492  }
1493 
1494  mask_first++;
1495  first++;
1496  }
1497  Value_T result = Value_T(0);
1498  if (count != 0)
1499  {
1500  result = Value_T(sum) / Value_T(count);
1501  }
1502  return result;
1503  }
1504 
1538  template<typename T, int N, typename InputIterator, typename MaskIterator>
1539  inline
1540  T nth_moment_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1541  {
1542  T __init = T();
1543  int count = 0;
1544  for (; first != last; ++first,++mask_first)
1545  {
1546  if(*mask_first == value)
1547  {
1548  __init = __init + slip::nth_power<N>(*first - mean);
1549  count++;
1550  }
1551  }
1552  T result = T(0);
1553  if(count != 0)
1554  {
1555  result = __init / static_cast<T>(count);
1556  }
1557  return result;
1558  }
1559 
1560 
1599  template<typename T, typename InputIterator, typename InputIterator2, typename MaskIterator>
1600  inline
1601  T covariance_mask(InputIterator first, InputIterator last,
1602  InputIterator2 first2, MaskIterator mask_first,
1603  T mean1, T mean2, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1604  {
1605  assert(first != last);
1606  T __init = T();
1607  long int count = 0;
1608  for (; first != last; ++first, ++first2,++mask_first)
1609  {
1610  if(*mask_first == value)
1611  {
1612  __init = __init + (*first - mean1) * (*first2 - mean2);
1613  count++;
1614  }
1615  }
1616  T result = T(0);
1617  if(count != 0)
1618  {
1619  result = __init / static_cast<T>(count);
1620  }
1621  return result;
1622  }
1623 
1662  template<typename T, typename InputIterator, typename InputIterator2, typename MaskIterator>
1663  inline
1664  T unbiased_covariance_mask(InputIterator first, InputIterator last,
1665  InputIterator2 first2, MaskIterator mask_first,
1666  T mean1, T mean2, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1667  {
1668  T __init = T();
1669  long int count = 0;
1670  for (; first != last; ++first, ++first2,++mask_first)
1671  {
1672  if(*mask_first == value)
1673  {
1674  __init = __init + (*first - mean1) * (*first2 - mean2);
1675  count++;
1676  }
1677  }
1678 
1679  T result = T(0);
1680  if(count != 0)
1681  {
1682  result = __init / static_cast<T>(count-1);
1683  }
1684  return result;
1685  }
1686 
1687 
1724  template<typename T, typename InputIterator, typename MaskIterator>
1725  inline
1726  T variance_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1727  {
1728  return slip::covariance_mask(first,last,first,mask_first, mean,mean,value);
1729  }
1730 
1731 
1768  template<typename T, typename InputIterator, typename MaskIterator>
1769  inline
1770  T unbiased_variance_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1771  {
1772  return slip::unbiased_covariance_mask(first,last,first,mask_first, mean,mean,value);
1773  }
1774 
1810  template<typename T, typename InputIterator, typename MaskIterator>
1811  inline
1812  T std_dev_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1813  {
1814  return std::sqrt(slip::variance_mask(first,last,mask_first,mean,value));
1815  }
1816 
1817 
1853  template<typename T, typename InputIterator, typename MaskIterator>
1854  inline
1855  T unbiased_std_dev_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1856  {
1857  return std::sqrt(slip::unbiased_variance_mask(first,last,mask_first,mean,value));
1858  }
1859 
1860 
1905  template<typename T, typename InputIterator, typename MaskIterator>
1906  inline
1907  T kurtosis_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1908  {
1909  T __init = T(0);
1910  T __init2 = T(0);
1911  long int count = 0;
1912  for (; first != last; ++first,++mask_first)
1913  {
1914  if (*mask_first == value)
1915  {
1916  T p2 = slip::nth_power<2>(*first - mean);
1917  __init = __init + p2;
1918  __init2 = __init2 + (p2 * p2);
1919  count++;
1920  }
1921  }
1922  T result = T(0);
1923  if( __init != T(0))
1924  {
1925  result = (__init2 * count) / (__init * __init);
1926  }
1927  return result;
1928  }
1929 
1930 
1967  template<typename T,
1968  typename InputIterator,
1969  typename MaskIterator>
1970  inline
1971  T unbiased_kurtosis_mask(InputIterator first, InputIterator last,
1972  MaskIterator mask_first,
1973  T mean,
1974  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
1975  {
1976  T __init = T(0);
1977  T __init2 = T(0);
1978  long int count = 0;
1979  for (; first != last; ++first,++mask_first)
1980  {
1981  if (*mask_first == value)
1982  {
1983  T p2 = slip::nth_power<2>(*first - mean);
1984  __init = __init + p2;
1985  __init2 = __init2 + (p2 * p2);
1986  count++;
1987  }
1988  }
1989 
1990  T count_m1 = T(count - 1);
1991  T count_m2 = T(count - 2);
1992  T count_m3 = T(count - 3);
1993  assert(count > 3);
1994  T result = T(0);
1995  if(__init != T(0))
1996  {
1997  result = (((T(count+1)*T(count)* count_m1) * __init2 )
1998  / ( (count_m2 * count_m3) * (__init * __init) ))
1999  - ( (T(3)* (count_m1*count_m1)) / (count_m2 * count_m3)) + T(3);
2000  }
2001  return result;
2002 
2003  }
2004 
2005 
2043  template<typename T,
2044  typename InputIterator,
2045  typename MaskIterator>
2046  inline
2047  T skewness_mask(InputIterator first, InputIterator last,
2048  MaskIterator mask_first,
2049  T mean,
2050  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2051  {
2052  T __init = T(0);
2053  T __init2 = T(0);
2054  long int count = 0;
2055  for (; first != last; ++first,++mask_first)
2056  {
2057  if (*mask_first == value)
2058  {
2059  T p1 = (*first - mean);
2060  T p2 = p1 * p1;
2061  __init = __init + p2;
2062  __init2 = __init2 + (p2 * p1);
2063  count++;
2064 
2065  }
2066  }
2067  assert(count > 0);
2068  T result = T(0);
2069  if(__init != T(0))
2070  {
2071  result = __init2 / (T(count)*slip::nth_power<3>(std::sqrt(__init/T(count))));
2072  }
2073  return result;
2074  }
2075 
2076 
2114  template<typename T,
2115  typename InputIterator,
2116  typename MaskIterator>
2117  inline
2118  T unbiased_skewness_mask(InputIterator first, InputIterator last,
2119  MaskIterator mask_first,
2120  T mean,
2121  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2122  {
2123  T __init = T(0);
2124  T __init2 = T(0);
2125  long int count = 0;
2126  for (; first != last; ++first,++mask_first)
2127  {
2128  if (*mask_first == value)
2129  {
2130  T p1 = (*first - mean);
2131  T p2 = p1 * p1;
2132  __init = __init + p2;
2133  __init2 = __init2 + (p2 * p1);
2134  count++;
2135 
2136  }
2137  }
2138  assert(count > 2);
2139  T result = T(0);
2140  if(__init != T(0))
2141  {
2142  result = (__init2 * T(count)) / (T(count-1)*T(count-2)*slip::nth_power<3>(std::sqrt(__init/T(count-1))));
2143  }
2144  return result;
2145 }
2146 
2181  template<typename T,
2182  typename InputIterator,
2183  typename MaskIterator>
2184  inline
2185  T rms_mask(InputIterator first, InputIterator last,
2186  MaskIterator mask_first,
2187  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2188  {
2189  return std::sqrt(slip::covariance_mask(first,last,first,mask_first, T(0),T(0),value));
2190  }
2191 
2219  template<typename Integer,typename MaskIterator>
2220  inline
2221  Integer cardinal_mask(MaskIterator mask_first,
2222  MaskIterator mask_last,
2223  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2224  {
2225  Integer count = 0;
2226  while(mask_first != mask_last)
2227  {
2228  if (*mask_first == value)
2229  {
2230  count++;
2231  }
2232  mask_first++;
2233  }
2234  return count;
2235  }
2236 
2254  template<typename InputIterator,
2255  typename MaskIterator>
2256  inline
2257  typename std::iterator_traits<InputIterator>::value_type
2258  median_from_sorted_data_mask(InputIterator first, InputIterator last,
2259  MaskIterator mask_first,
2260  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2261  {
2262  MaskIterator mask_last=mask_first+(last - first);
2263  std::size_t mask_count=slip::cardinal_mask<std::size_t>(mask_first,mask_last,value);
2264  assert(mask_count != 0);
2265  std::size_t count = 0;
2266  while(first != last)
2267  {
2268  if (*mask_first == value)
2269  {
2270  count++;
2271  }
2272  if (count>mask_count/2)
2273  {
2274  return *first;
2275  }
2276  first++;
2277  mask_first++;
2278  }
2279  std::cerr << "Error computing median_from_sorted_data_mask"<<std::endl;
2280  return *first;
2281  }
2282 
2314  template<typename InputIterator, typename MaskIterator>
2315  inline
2316  typename std::iterator_traits<InputIterator>::value_type
2317  median_mask(InputIterator first, InputIterator last,
2318  MaskIterator mask_first,
2319  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2320  {
2321  std::size_t mask_count =
2322  slip::cardinal_mask<std::size_t>(mask_first,mask_first+(last-first),
2323  value);
2324 
2325  assert(mask_count != 0);
2327  std::size_t count = 0;
2328  while(first != last)
2329  {
2330  if (*mask_first == value)
2331  {
2332  tmp[count]=*first;
2333  count++;
2334  }
2335  first++;
2336  mask_first++;
2337  }
2338 
2339  std::sort(tmp.begin(),tmp.end());
2340  return slip::median_from_sorted_data_n(tmp.begin(),mask_count);
2341 
2342  }
2343 
2375  template<typename InputIterator,
2376  typename MaskIterator>
2377  inline
2378  typename std::iterator_traits<InputIterator>::value_type
2379  first_quartile_mask(InputIterator first, InputIterator last,
2380  MaskIterator mask_first,
2381  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2382  {
2383  std::size_t mask_count = slip::cardinal_mask<std::size_t>(mask_first,mask_first+(last-first),value);
2384  assert(mask_count != 0);
2386  std::size_t count = 0;
2387  while(first != last)
2388  {
2389  if (*mask_first == value)
2390  {
2391  tmp[count]=*first;
2392  count++;
2393  }
2394  first++;
2395  mask_first++;
2396 
2397  }
2398 
2399  std::sort(tmp.begin(),tmp.end());
2400  return slip::first_quartile(tmp.begin(),tmp.end());
2401 
2402  }
2403 
2435  template<typename InputIterator, typename MaskIterator>
2436  inline
2437  typename std::iterator_traits<InputIterator>::value_type
2438  third_quartile_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2439  {
2440  std::size_t mask_count=slip::cardinal_mask<std::size_t>(mask_first,mask_first+(last-first),value);
2441  assert(mask_count != 0);
2443 
2444  std::size_t count = 0;
2445  while(first != last)
2446  {
2447  if (*mask_first == value)
2448  {
2449  tmp[count]=*first;
2450  count++;
2451  }
2452  first++;
2453  mask_first++;
2454  }
2455 
2456  std::sort(tmp.begin(),tmp.end());
2457  return slip::third_quartile(tmp.begin(),tmp.end());
2458 
2459  }
2460 
2488  template<typename InputIterator, typename MaskIterator, typename OutputIterator>
2489  inline
2490  void center_mask(InputIterator first, InputIterator last,
2491  MaskIterator mask_first,
2492  OutputIterator out_first,
2493  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2494  {
2495  assert(first != last);
2496  typedef typename std::iterator_traits<OutputIterator>::value_type value_type;
2497 
2498  value_type mean = slip::mean_mask<value_type>(first,last,mask_first,value);
2499 
2500  for (; first != last; ++first, ++out_first, ++mask_first)
2501  {
2502  if(*mask_first == value)
2503  {
2504  *out_first = (*first - mean);
2505  }
2506  }
2507 
2508  }
2509 
2510 
2538  template<typename InputIterator, typename MaskIterator, typename OutputIterator>
2539  inline
2540  void studentize_mask(InputIterator first, InputIterator last,
2541  MaskIterator mask_first,
2542  OutputIterator out_first,
2543  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
2544  {
2545  assert(first != last);
2546  typedef typename std::iterator_traits<OutputIterator>::value_type value_type;
2547 
2548  value_type mean = slip::mean_mask<value_type>(first,last,mask_first,value);
2549  value_type std_dev = slip::std_dev_mask<value_type>(first,last,mask_first,mean,value);
2550 
2551  if(std_dev != value_type(0))
2552  {
2553  for (; first != last; ++first, ++out_first, ++mask_first)
2554  {
2555  if(*mask_first == value)
2556  {
2557  *out_first = (*first - mean) / std_dev;
2558  }
2559  }
2560  }
2561  else
2562  {
2563  for (; first != last; ++first, ++out_first, ++mask_first)
2564  {
2565  if(*mask_first == value)
2566  {
2567  *out_first = (*first - mean);
2568  }
2569  }
2570  }
2571 
2572  }
2573 
2574 
2576 
2603  template<typename Integer,typename InputIterator, typename Predicate>
2604  inline
2605  Integer cardinal_if(InputIterator first,
2606  InputIterator last,
2607  Predicate pred)
2608  {
2609  Integer count = 0;
2610  while(first != last)
2611  {
2612  if (pred(*first))
2613  {
2614  count++;
2615  }
2616  first++;
2617  }
2618  return count;
2619  }
2620 
2650  template<typename Value_T,typename InputIterator, typename Predicate>
2651  inline
2652  Value_T mean_if(InputIterator first, InputIterator last, Predicate pred)
2653  {
2654  assert(first != last);
2655  Value_T sum = Value_T(0);
2656  long int count = 0;
2657  while(first != last)
2658  {
2659  if(pred(*first))
2660  {
2661  sum += *first; ++count;
2662  }
2663 
2664  first++;
2665  }
2666  Value_T result = Value_T(0);
2667  if(count != 0)
2668  {
2669  result = Value_T(sum) / Value_T(count);
2670  }
2671  return result;
2672  }
2673 
2705  template<typename T, int N, typename InputIterator, typename Predicate>
2706  inline
2707  T nth_moment_if(InputIterator first, InputIterator last, T mean, Predicate pred)
2708  {
2709  T __init = T();
2710  long int count = 0;
2711  for (; first != last; ++first)
2712  {
2713  if(pred(*first))
2714  {
2715  __init = __init + slip::nth_power<N>(*first - mean);
2716  count++;
2717  }
2718  }
2719  T result = T(0);
2720  if(count != 0)
2721  {
2722  result = __init / count;
2723  }
2724  return result;
2725  }
2726 
2727 
2763  template<typename T,
2764  typename InputIterator,
2765  typename InputIterator2,
2766  typename Predicate>
2767  inline
2768  T covariance_if(InputIterator first, InputIterator last,
2769  InputIterator2 first2,
2770  T mean1, T mean2, Predicate pred)
2771  {
2772  T __init = T();
2773  long int count = 0;
2774  for (; first != last; ++first, ++first2)
2775  {
2776  if(pred(*first))
2777  {
2778  __init = __init + (*first - mean1) * (*first2 - mean2);
2779  count++;
2780  }
2781  }
2782  T result = T(0);
2783  if(count != 0)
2784  {
2785  result = __init / count;
2786  }
2787  return result;
2788  }
2789 
2825  template<typename T, typename InputIterator, typename InputIterator2, typename Predicate>
2826  inline
2827  T unbiased_covariance_if(InputIterator first, InputIterator last,
2828  InputIterator2 first2,
2829  T mean1, T mean2,Predicate pred)
2830  {
2831  T __init = T();
2832  long int count = 0;
2833  for (; first != last; ++first, ++first2)
2834  {
2835  if(pred(*first))
2836  {
2837  __init = __init + (*first - mean1) * (*first2 - mean2);
2838  count++;
2839  }
2840  }
2841  T result = T(0);
2842  if(count != 0)
2843  {
2844  result = __init / static_cast<T>(count - 1);
2845  }
2846  return result;
2847  }
2848 
2849 
2884  template<typename T, typename InputIterator, typename Predicate>
2885  inline
2886  T variance_if(InputIterator first, InputIterator last, T mean, Predicate pred)
2887  {
2888  return slip::covariance_if(first,last,first, mean,mean,pred);
2889  }
2890 
2891 
2926  template<typename T, typename InputIterator, typename Predicate>
2927  inline
2928  T unbiased_variance_if(InputIterator first, InputIterator last, T mean, Predicate pred)
2929  {
2930  return slip::unbiased_covariance_if(first,last,first, mean,mean,pred);
2931  }
2932 
2967  template<typename T, typename InputIterator, typename Predicate>
2968  inline
2969  T std_dev_if(InputIterator first, InputIterator last, T mean, Predicate pred)
2970  {
2971  return std::sqrt(slip::variance_if(first,last,mean,pred));
2972  }
2973 
2974 
3009  template<typename T, typename InputIterator, typename Predicate>
3010  inline
3011  T unbiased_std_dev_if(InputIterator first, InputIterator last, T mean, Predicate pred)
3012  {
3013  return std::sqrt(slip::unbiased_variance_if(first,last,mean,pred));
3014  }
3015 
3016 
3059  template<typename T, typename InputIterator, typename Predicate>
3060  inline
3061  T kurtosis_if(InputIterator first, InputIterator last, T mean, Predicate pred)
3062  {
3063  T __init = T();
3064  T __init2 = T();
3065  long int count = 0;
3066  for (; first != last; ++first)
3067  {
3068  if (pred(*first))
3069  {
3070  T p2 = slip::nth_power<2>(*first - mean);
3071  __init = __init + p2;
3072  __init2 = __init2 + (p2 * p2);
3073  count++;
3074  }
3075  }
3076  T result = T(0);
3077  if( __init != T(0))
3078  {
3079  result = (__init2 * T(count)) / (__init * __init);
3080  }
3081  return result;
3082  }
3083 
3084 
3119  template<typename T, typename InputIterator, typename Predicate>
3120  inline
3121  T unbiased_kurtosis_if(InputIterator first, InputIterator last, T mean, Predicate pred)
3122  {
3123  T __init = T();
3124  T __init2 = T();
3125  long int count = 0;
3126  for (; first != last; ++first)
3127  {
3128  if (pred(*first)){
3129  T p2 = slip::nth_power<2>(*first - mean);
3130  __init = __init + p2;
3131  __init2 = __init2 + (p2 * p2);
3132  count++;
3133  }
3134  }
3135  assert(count > 3);
3136  T count_m1 = T(count - 1);
3137  T count_m2 = T(count - 2);
3138  T count_m3 = T(count - 3);
3139 
3140  T result = T(0);
3141  if( __init != T(0))
3142  {
3143  result = (((T(count+1)*T(count)* count_m1) * __init2 )
3144  / ( (count_m2 * count_m3) * (__init * __init) ))
3145  - ( (T(3)* (count_m1*count_m1)) / (count_m2 * count_m3)) + T(3);
3146  }
3147  return result;
3148  }
3149 
3150 
3186  template<typename T, typename InputIterator, typename Predicate>
3187  inline
3188  T skewness_if(InputIterator first, InputIterator last, T mean, Predicate pred)
3189  {
3190  T __init = T();
3191  T __init2 = T();
3192  long int count = 0;
3193  for (; first != last; ++first)
3194  {
3195  if (pred(*first))
3196  {
3197  T p1 = (*first - mean);
3198  T p2 = p1 * p1;
3199  __init = __init + p2;
3200  __init2 = __init2 + (p2 * p1);
3201  count++;
3202  }
3203  }
3204  assert(count > 0);
3205  T result = T(0);
3206  if( __init != T(0))
3207  {
3208  result = __init2 / (T(count)*slip::nth_power<3>(std::sqrt(__init/T(count))));
3209  }
3210  return result;
3211  }
3212 
3248  template<typename T, typename InputIterator, typename Predicate>
3249  inline
3250  T unbiased_skewness_if(InputIterator first, InputIterator last, T mean, Predicate pred)
3251  {
3252  T __init = T();
3253  T __init2 = T();
3254  long int count = 0;
3255  for (; first != last; ++first)
3256  {
3257  if (pred(*first))
3258  {
3259  T p1 = (*first - mean);
3260  T p2 = p1 * p1;
3261  __init = __init + p2;
3262  __init2 = __init2 + (p2 * p1);
3263  count++;
3264  }
3265  }
3266  assert(count > 2);
3267  T result = T(0);
3268  if( __init != T(0))
3269  {
3270  result = (__init2 * T(count)) / (T(count-1)*T(count-2)*slip::nth_power<3>(std::sqrt(__init/T(count-1))));
3271  }
3272  return result;
3273  }
3274 
3307  template<typename T, typename InputIterator, typename Predicate>
3308  inline
3309  T rms_if(InputIterator first, InputIterator last, Predicate pred)
3310  {
3311  return std::sqrt(slip::covariance_if(first,last,first,T(0),T(0),pred));
3312  }
3313 
3314 
3315 
3331  template<typename InputIterator, typename Predicate>
3332  inline
3333  typename std::iterator_traits<InputIterator>::value_type
3334  median_from_sorted_data_if(InputIterator first, InputIterator last,
3335  Predicate pred)
3336  {
3337  std::size_t mask_count=slip::cardinal_if<std::size_t>(first,last,pred);
3338  assert(mask_count != 0);
3339  std::size_t count = 0;
3340  while(first != last)
3341  {
3342  if (pred(*first))
3343  {
3344  count++;
3345  }
3346  if (count > mask_count/2)
3347  {
3348  return *first;
3349  }
3350  first++;
3351  }
3352  std::cerr << "Error computing median_from_sorted_data_if"<<std::endl;
3353  return *first;
3354  }
3355 
3384  template<typename InputIterator, typename Predicate>
3385  inline
3386  typename std::iterator_traits<InputIterator>::value_type
3387  median_if(InputIterator first, InputIterator last,
3388  Predicate pred)
3389  {
3390  std::size_t mask_count=slip::cardinal_if<std::size_t>(first,last,pred);
3391  assert(mask_count != 0);
3393  std::size_t count = 0;
3394 
3395  while(first != last)
3396  {
3397  if (pred(*first))
3398  {
3399  tmp[count]=*first;
3400  count++;
3401  }
3402  first++;
3403  }
3404  std::sort(tmp.begin(),tmp.end());
3405  return slip::median_from_sorted_data_n(tmp.begin(),mask_count);
3406 
3407  }
3408 
3437  template<typename InputIterator, typename Predicate>
3438  inline
3439  typename std::iterator_traits<InputIterator>::value_type
3440  first_quartile_if(InputIterator first, InputIterator last, Predicate pred)
3441  {
3442  std::size_t mask_count=slip::cardinal_if<std::size_t>(first,last,pred);
3443  assert(mask_count != 0);
3445  std::size_t count = 0;
3446 
3447  while(first != last)
3448  {
3449  if (pred(*first))
3450  {
3451  tmp[count] = *first;
3452  count++;
3453  }
3454  first++;
3455  }
3456 
3457  std::sort(tmp.begin(),tmp.end());
3458  return slip::first_quartile(tmp.begin(),tmp.end());
3459 
3460  }
3461 
3462 
3491  template<typename InputIterator, typename Predicate>
3492  inline
3493  typename std::iterator_traits<InputIterator>::value_type
3494  third_quartile_if(InputIterator first, InputIterator last, Predicate pred)
3495  {
3496  std::size_t mask_count=slip::cardinal_if<std::size_t>(first,last,pred);
3497  assert(mask_count != 0);
3499  std::size_t count = 0;
3500 
3501  while(first != last)
3502  {
3503  if (pred(*first))
3504  {
3505  tmp[count] = *first;
3506  count++;
3507  }
3508  first++;
3509  }
3510 
3511  std::sort(tmp.begin(),tmp.end());
3512  return slip::third_quartile(tmp.begin(),tmp.end());
3513 
3514  }
3515 
3516 
3546  template<typename InputIterator, typename Predicate, typename OutputIterator>
3547  inline
3548  void center_if(InputIterator first, InputIterator last,
3549  Predicate pred,
3550  OutputIterator out_first)
3551  {
3552  assert(first != last);
3553 
3554  typedef typename std::iterator_traits<OutputIterator>::value_type value_type;
3555  value_type mean = slip::mean_if<value_type>(first,last,pred);
3556 
3557  while(first != last)
3558  {
3559  if(pred(*first))
3560  {
3561  *out_first = (*first - mean);
3562  }
3563  ++out_first;
3564  ++first;
3565  }
3566  }
3567 
3568 
3598  template<typename InputIterator, typename Predicate, typename OutputIterator>
3599  inline
3600  void studentize_if(InputIterator first, InputIterator last,
3601  Predicate pred,
3602  OutputIterator out_first)
3603  {
3604  assert(first != last);
3605 
3606  typedef typename std::iterator_traits<OutputIterator>::value_type value_type;
3607  value_type mean = slip::mean_if<value_type>(first,last,pred);
3608  value_type std_dev = slip::std_dev_if<value_type>(first,last,mean,pred);
3609 
3610  if(std_dev != value_type(0))
3611  {
3612  while(first != last)
3613  {
3614  if(pred(*first))
3615  {
3616  *out_first = (*first - mean) / std_dev;
3617  }
3618  ++out_first;
3619  ++first;
3620  }
3621  }
3622  else
3623  {
3624  while(first != last)
3625  {
3626  if(pred(*first))
3627  {
3628  *out_first = (*first - mean);
3629  }
3630  ++out_first;
3631  ++first;
3632  }
3633  }
3634  }
3635 
3636 
3637 
3638 
3639 
3640 
3664 template <typename InputIterator, typename T>
3665  void statistics(InputIterator first,
3666  InputIterator last,
3667  slip::Statistics<T>& statistic)
3668 
3669  {
3670  std::size_t n = slip::cardinal<std::size_t>(first,last);
3672  tmp(n,first,last);
3673  std::sort(tmp.begin(),tmp.end());
3674 
3675 
3676  statistic.min() = *tmp.begin();
3677  statistic.first_quartile() = *(tmp.begin()+n/4);
3678  statistic.median() = *(tmp.begin()+n/2);
3679  statistic.third_quartile()= *((tmp.end()-1)-n/4);
3680  statistic.max() = *(tmp.end() - 1);
3681  statistic.mean() = slip::mean<T>(first,last);
3682  statistic.std_dev()= slip::std_dev(first,last,statistic.mean());
3683  statistic.skewness() = slip::skewness(first,last,statistic.mean());
3684  statistic.kurtosis() = slip::kurtosis(first,last,statistic.mean());
3685  statistic.cardinal() = n;
3686 
3687  }
3688 
3689 
3713 template <typename InputIterator, typename T>
3714  void unbiased_statistics(InputIterator first,
3715  InputIterator last,
3716  slip::Statistics<T>& statistic)
3717 
3718  {
3719  std::size_t n = slip::cardinal<std::size_t>(first,last);
3721  tmp(n,first,last);
3722  std::sort(tmp.begin(),tmp.end());
3723 
3724 
3725  statistic.min() = *tmp.begin();
3726  statistic.first_quartile() = *(tmp.begin()+n/4);
3727  statistic.median() = *(tmp.begin()+n/2);
3728  statistic.third_quartile()= *((tmp.end()-1)-n/4);
3729  statistic.max() = *(tmp.end() - 1);
3730  statistic.mean() = slip::mean<T>(first,last);
3731  statistic.std_dev()= slip::unbiased_std_dev(first,last,statistic.mean());
3732  statistic.skewness() = slip::unbiased_skewness(first,last,statistic.mean());
3733  statistic.kurtosis() = slip::unbiased_kurtosis(first,last,statistic.mean());
3734  statistic.cardinal() = n;
3735 
3736  }
3737 
3738 
3739 
3790  template <typename InputIterator, typename T, typename MaskIterator>
3791  void statistics_mask(InputIterator first,
3792  InputIterator last,
3793  MaskIterator mask_first,
3794  slip::Statistics<T>& statistic,
3795  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
3796 
3797  {
3798 
3799  std::size_t n = slip::cardinal_mask<std::size_t>(mask_first,mask_first+(last-first),value);
3800  assert(n != 0);
3802  std::size_t count = 0;
3803  while(first != last)
3804  {
3805  if (*mask_first == value)
3806  {
3807  tmp[count] = *first;
3808  count++;
3809  }
3810  first++;
3811  mask_first++;
3812 
3813  }
3814 
3815  std::sort(tmp.begin(),tmp.end());
3816 
3817 
3818 
3819  statistic.min() = *(tmp.begin());
3820  statistic.first_quartile() = *(tmp.begin()+n/4);
3821  statistic.median() = *(tmp.begin()+n/2);
3822  statistic.third_quartile()= *((tmp.end()-1)-n/4);
3823  statistic.max() = *(tmp.end() - 1);
3824  statistic.mean() = slip::mean<T>(tmp.begin(),tmp.end());
3825  statistic.std_dev()= slip::std_dev(tmp.begin(),tmp.end(),statistic.mean());
3826  statistic.skewness() = slip::skewness(tmp.begin(),tmp.end(),statistic.mean());
3827  statistic.kurtosis() = slip::kurtosis(tmp.begin(),tmp.end(),statistic.mean());
3828  statistic.cardinal() = n;
3829 
3830  }
3831 
3832 
3883  template <typename InputIterator, typename T, typename MaskIterator>
3884  void unbiased_statistics_mask(InputIterator first,
3885  InputIterator last,
3886  MaskIterator mask_first,
3887  slip::Statistics<T>& statistic,
3888  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
3889 
3890  {
3891 
3892  std::size_t n = slip::cardinal_mask<std::size_t>(mask_first,mask_first+(last-first),value);
3893  assert(n != 0);
3895  std::size_t count = 0;
3896  while(first != last)
3897  {
3898  if (*mask_first == value)
3899  {
3900  tmp[count] = *first;
3901  count++;
3902  }
3903  first++;
3904  mask_first++;
3905 
3906  }
3907 
3908  std::sort(tmp.begin(),tmp.end());
3909 
3910 
3911 
3912  statistic.min() = *(tmp.begin());
3913  statistic.first_quartile() = *(tmp.begin()+n/4);
3914  statistic.median() = *(tmp.begin()+n/2);
3915  statistic.third_quartile()= *((tmp.end()-1)-n/4);
3916  statistic.max() = *(tmp.end() - 1);
3917  statistic.mean() = slip::mean<T>(tmp.begin(),tmp.end());
3918  statistic.std_dev()= slip::unbiased_std_dev(tmp.begin(),tmp.end(),statistic.mean());
3919  statistic.skewness() = slip::unbiased_skewness(tmp.begin(),tmp.end(),statistic.mean());
3920  statistic.kurtosis() = slip::unbiased_kurtosis(tmp.begin(),tmp.end(),statistic.mean());
3921  statistic.cardinal() = n;
3922 
3923  }
3924 
3925 
3953  template <typename InputIterator, typename T, typename Predicate>
3954  void statistics_if(InputIterator first,
3955  InputIterator last,
3956  slip::Statistics<T>& statistic,
3957  Predicate pred)
3958 
3959  {
3960 
3961  std::size_t n = slip::cardinal_if<std::size_t>(first,last,pred);
3962  assert(n != 0);
3964  std::size_t count = 0;
3965  while(first != last)
3966  {
3967  if (pred(*first))
3968  {
3969  tmp[count]=*first;
3970  count++;
3971  }
3972  first++;
3973  }
3974 
3975 
3976  std::sort(tmp.begin(),tmp.end());
3977 
3978 
3979 
3980  statistic.min() = *tmp.begin();
3981  statistic.first_quartile() = *(tmp.begin()+n/4);
3982  statistic.median() = *(tmp.begin()+n/2);
3983  statistic.third_quartile()= *((tmp.end()-1)-n/4);
3984  statistic.max() = *(tmp.end() - 1);
3985  statistic.mean() = slip::mean<T>(tmp.begin(),tmp.end());
3986  statistic.std_dev()= slip::std_dev(tmp.begin(),tmp.end(),statistic.mean());
3987  statistic.skewness() = slip::skewness(tmp.begin(),tmp.end(),statistic.mean());
3988  statistic.kurtosis() = slip::kurtosis(tmp.begin(),tmp.end(),statistic.mean());
3989  statistic.cardinal() = n;
3990 
3991  }
3992 
3993 
4021  template <typename InputIterator, typename T, typename Predicate>
4022  void unbiased_statistics_if(InputIterator first,
4023  InputIterator last,
4024  slip::Statistics<T>& statistic,
4025  Predicate pred)
4026 
4027  {
4028 
4029  std::size_t n = slip::cardinal_if<std::size_t>(first,last,pred);
4030  assert(n != 0);
4032  std::size_t count = 0;
4033  while(first != last)
4034  {
4035  if (pred(*first))
4036  {
4037  tmp[count]=*first;
4038  count++;
4039  }
4040  first++;
4041  }
4042 
4043 
4044  std::sort(tmp.begin(),tmp.end());
4045 
4046 
4047 
4048  statistic.min() = *tmp.begin();
4049  statistic.first_quartile() = *(tmp.begin()+n/4);
4050  statistic.median() = *(tmp.begin()+n/2);
4051  statistic.third_quartile()= *((tmp.end()-1)-n/4);
4052  statistic.max() = *(tmp.end() - 1);
4053  statistic.mean() = slip::mean<T>(tmp.begin(),tmp.end());
4054  statistic.std_dev()= slip::unbiased_std_dev(tmp.begin(),tmp.end(),statistic.mean());
4055  statistic.skewness() = slip::unbiased_skewness(tmp.begin(),tmp.end(),statistic.mean());
4056  statistic.kurtosis() = slip::unbiased_kurtosis(tmp.begin(),tmp.end(),statistic.mean());
4057  statistic.cardinal() = n;
4058 
4059  }
4060 
4061 
4063  /* @{ */
4087  template<typename DataT,
4088  typename MeanT>
4089  MeanT mean_next(const int n,
4090  const MeanT& prev_mean,
4091  const DataT& xnp1)
4092  {
4093  MeanT an = static_cast<MeanT>(1)/static_cast<MeanT>(n+1);
4094  MeanT bn = static_cast<MeanT>(n)*an;
4095  return bn * prev_mean + an * xnp1;
4096  }
4097 
4098 
4125  template<typename DataT,
4126  typename VarT>
4127  void var_next(const int n,
4128  const VarT& prev_mean,
4129  const VarT& prev_var,
4130  const DataT& xnp1,
4131  VarT& next_mean,
4132  VarT& next_var)
4133  {
4134  VarT an = static_cast<VarT>(1)/static_cast<VarT>(n+1);
4135  VarT bn = static_cast<VarT>(n)*an;
4136  VarT cn = bn * an;
4137  VarT s = (static_cast<VarT>(xnp1) - prev_mean);
4138  next_mean = bn * prev_mean + an * static_cast<VarT>(xnp1);
4139  next_var = bn * prev_var + cn * (s * s);
4140  }
4141 /* @} */
4142 
4143 }//slip::
4144 
4145 #endif //SLIP_STATISTICS_HPP
T unbiased_kurtosis_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the unbiased kurtosis of a range using a predicate A high kurtosis distribution has a sharp...
Integer cardinal_mask(MaskIterator mask_first, MaskIterator mask_last, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the cardinal or the number of elements of a mask range.
T unbiased_skewness_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the unbiased skewness of a range over a mask skewness is a measure of the asymmetry of the ...
T & kurtosis()
Returns the kurtosis.
Definition: statistics.hpp:186
T covariance_mask(InputIterator first, InputIterator last, InputIterator2 first2, MaskIterator mask_first, T mean1, T mean2, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the covariance of a two sequences over a mask .
T unbiased_skewness(InputIterator first, InputIterator last, T mean)
Computes the unbiased skewness of a range skewness is a measure of the asymmetry of the probability ...
Definition: statistics.hpp:820
T kurtosis_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the kurtosis of a range over a mask A high kurtosis distribution has a sharper peak and lon...
std::iterator_traits< InputIterator >::value_type third_quartile_if(InputIterator first, InputIterator last, Predicate pred)
Computes the third quartile value from a non sorted range using a predicate.
std::iterator_traits< InputIterator >::value_type median_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the median value from a non sorted range over a mask.
T skewness_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the skewness of a range over a mask skewness is a measure of the asymmetry of the probabili...
void center(RandomAccessIterator first, RandomAccessIterator last, RandomAccessIterator2 out_first)
Substracts its mean to a range.
T kurtosis_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the kurtosis of a range using a predicate A high kurtosis distribution has a sharper peak a...
T variance_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the variance of a range over a mask .
T & max()
Returns the first maximal value.
Definition: statistics.hpp:150
T & std_dev()
Returns the standard deviation.
Definition: statistics.hpp:168
T unbiased_std_dev(InputIterator first, InputIterator last, T mean)
Computes the unbiased standard deviation of a range .
Definition: statistics.hpp:626
std::iterator_traits< InputIterator >::value_type median_from_sorted_data(InputIterator first, InputIterator last)
Computes the median value from a sorted range: returns *(first + (last - first) / 2) ...
Definition: statistics.hpp:891
std::iterator_traits< InputIterator >::value_type first_quartile_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the first quartile value from a non sorted range over a mask.
T unbiased_covariance_if(InputIterator first, InputIterator last, InputIterator2 first2, T mean1, T mean2, Predicate pred)
Computes the unbiased covariance of a two sequences using a predicate on the first one ...
T & min(const GrayscaleImage< T > &M1)
Returns the min element of a GrayscaleImage.
std::iterator_traits< RandomAccessIterator >::value_type first_quartile(RandomAccessIterator first, RandomAccessIterator last)
Computes the first quartile value from a non sorted range.
Value_T mean_if(InputIterator first, InputIterator last, Predicate pred)
Computes the mean value of a range using a predicate .
T unbiased_kurtosis(InputIterator first, InputIterator last, T mean)
Computes the unbiased kurtosis of a range A high kurtosis distribution has a sharper peak and longer...
Definition: statistics.hpp:715
Provides a class to tag SLIP iterators.
T unbiased_variance_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the unbiased variance of a range using a predicate .
void statistics_if(InputIterator first, InputIterator last, slip::Statistics< T > &statistic, Predicate pred)
compute all statistics of a range according to a preidcate.
iterator begin()
Returns a read/write iterator that points to the first element in the Array. Iteration is done in ord...
Definition: Array.hpp:1077
std::iterator_traits< InputIterator >::value_type third_quartile_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the third quartile value from a non sorted range over a mask.
T unbiased_variance_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the unbiased variance of a range over a mask .
std::iterator_traits< RandomAccessIterator >::value_type median_from_data_n(RandomAccessIterator first, RandomAccessIterator last, Size n)
Computes the median value from a non sorted range.
Definition: statistics.hpp:944
void n_max_elements(ForwardIterator first, ForwardIterator last, std::vector< ForwardIterator > &max, const std::size_t n=1)
finds the n largest elements in the range [first, last).
void unbiased_statistics(InputIterator first, InputIterator last, slip::Statistics< T > &statistic)
compute all unbiased statistics of a range
std::iterator_traits< RandomAccessIterator >::value_type median_n(RandomAccessIterator first, RandomAccessIterator last, SizeType n, StrictWeakOrdering comp)
Computes the median value from a range of size n.
T nth_moment(InputIterator first, InputIterator last, T mean)
Computes the nth moment of a range .
Definition: statistics.hpp:399
std::iterator_traits< RandomAccessIterator >::value_type median(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp)
Computes the median value from a range.
T std_dev_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the standard deviation of a range over a mask .
Integer cardinal_if(InputIterator first, InputIterator last, Predicate pred)
Computes the cardinal or the number of elements of a range using a predicate.
std::iterator_traits< InputIterator >::value_type first_quartile_if(InputIterator first, InputIterator last, Predicate pred)
Computes the first quartile value from a non sorted range using a predicate.
This is a structure to store descriptive statistics.
Definition: statistics.hpp:107
T rms(InputIterator first, InputIterator last)
Computes the root mean square (rms) value of a range .
Definition: statistics.hpp:866
std::iterator_traits< RandomAccessIterator >::value_type third_quartile(RandomAccessIterator first, RandomAccessIterator last)
Computes the third quartile value from a non sorted range.
T unbiased_std_dev_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the unbiased standard deviation of a range using a predicate .
slip::block< T, 10 > all()
Returns a slip::block<T,10> with all the statistics.
Definition: statistics.hpp:204
T & min()
Returns the minimum value.
Definition: statistics.hpp:114
Value_T weighted_mean(InputIterator first, InputIterator last, InputIterator w_first, InputIterator w_last)
Computes the weighted mean value of a range: .
Definition: statistics.hpp:352
std::iterator_traits< InputIterator >::value_type median_from_sorted_data_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the median value from a sorted range over a mask.
std::iterator_traits< RandomAccessIterator >::value_type median(RandomAccessIterator first, RandomAccessIterator last)
Computes the median value from a range.
void center_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator out_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Substracts its mean to a range according a mask.
T & first_quartile()
Returns the first quartile value.
Definition: statistics.hpp:123
std::iterator_traits< InputIterator >::value_type median_from_sorted_data_if(InputIterator first, InputIterator last, Predicate pred)
Computes the median value from a sorted range using a predicate.
Provides a class to manipulate 1d static and generic arrays.
T rms_if(InputIterator first, InputIterator last, Predicate pred)
Computes the root mean square (rms) value of a range using a predicate .
Provides a class to manipulate 1d dynamic and generic arrays.
slip::block< T, 10 > stat_
Definition: statistics.hpp:209
void statistics_mask(InputIterator first, InputIterator last, MaskIterator mask_first, slip::Statistics< T > &statistic, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
compute all statistics of a range according to a mask range.
void studentize_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator out_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Substracts its mean to a range and divide it by its standard deviation according a mask...
void center_if(InputIterator first, InputIterator last, Predicate pred, OutputIterator out_first)
Substracts its mean to a range using a predicate.
T & mean()
Returns the mean value.
Definition: statistics.hpp:159
void studentize_if(InputIterator first, InputIterator last, Predicate pred, OutputIterator out_first)
Substracts its mean to a range and divide it by its standard deviation using a predicate.
void studentize(RandomAccessIterator first, RandomAccessIterator last, RandomAccessIterator2 out_first)
Substracts its mean to a range and divide it by its standard deviation.
T variance(InputIterator first, InputIterator last, T mean)
Computes the variance of a range .
Definition: statistics.hpp:535
T unbiased_skewness_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the unbiased skewness of a range using a predicate skewness is a measure of the asymmetry o...
MeanT mean_next(const int n, const MeanT &prev_mean, const DataT &xnp1)
Recursive mean algorithm.
T & third_quartile()
Returns the third quartile value.
Definition: statistics.hpp:141
T variance_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the variance of a range using a predicate .
iterator end()
Returns a read/write iterator that points one past the last element in the Array. Iteration is done i...
Definition: Array.hpp:1084
T unbiased_kurtosis_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the unbiased kurtosis of a range over a mask A high kurtosis distribution has a sharper pea...
T unbiased_covariance_mask(InputIterator first, InputIterator last, InputIterator2 first2, MaskIterator mask_first, T mean1, T mean2, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the unbiased covariance of a two sequences over a mask .
T std_dev_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the standard deviation of a range using a predicate .
Value_T mean(InputIterator first, InputIterator last)
Computes the mean value of a range .
Definition: statistics.hpp:314
T rms_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the root mean square (rms) value of a range over a mask .
Provides some mathematical functors and constants.
HyperVolume< T > sqrt(const HyperVolume< T > &M)
T nth_moment_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the nth moment of a range over a mask .
std::iterator_traits< InputIterator >::value_type median_if(InputIterator first, InputIterator last, Predicate pred)
Computes the median value from a non sorted range using a predicate.
T & skewness()
Returns the skewness.
Definition: statistics.hpp:177
T unbiased_std_dev_mask(InputIterator first, InputIterator last, MaskIterator mask_first, T mean, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the unbiased standard deviation of a range over a mask .
Integer cardinal(InputIterator first, InputIterator last)
Computes the cardinal or the number of elements of a range.
Definition: statistics.hpp:285
void unbiased_statistics_if(InputIterator first, InputIterator last, slip::Statistics< T > &statistic, Predicate pred)
compute all unbiased statistics of a range according to a preidcate.
T nth_moment_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the nth moment of a range using a predicate .
T covariance_if(InputIterator first, InputIterator last, InputIterator2 first2, T mean1, T mean2, Predicate pred)
Computes the covariance of a two sequences using a predicate on the first one .
std::iterator_traits< RandomAccessIterator >::value_type median_from_sorted_data_n(RandomAccessIterator first, Size n)
Computes the median value from a sorted range: returns *(first + n/2).
Definition: statistics.hpp:913
void unbiased_statistics_mask(InputIterator first, InputIterator last, MaskIterator mask_first, slip::Statistics< T > &statistic, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
compute all unbiased statistics of a range according to a mask range.
Value_T mean_mask(InputIterator first, InputIterator last, MaskIterator mask_first, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Computes the mean value of a range over a mask .
void n_min_elements(ForwardIterator first, ForwardIterator last, std::vector< ForwardIterator > &min, const std::size_t n=1)
finds the n smallest elements in the range [first, last).
T skewness(InputIterator first, InputIterator last, T mean)
Computes the skewness of a range skewness is a measure of the asymmetry of the probability distribut...
Definition: statistics.hpp:770
T covariance(InputIterator first, InputIterator last, InputIterator2 first2, T mean1, T mean2)
Computes the covariance of a two sequences .
Definition: statistics.hpp:443
T & cardinal()
Returns the cardinal.
Definition: statistics.hpp:195
void var_next(const int n, const VarT &prev_mean, const VarT &prev_var, const DataT &xnp1, VarT &next_mean, VarT &next_var)
Recursive variance algorithm.
T std_dev(InputIterator first, InputIterator last, T mean)
Computes the standard deviation of a range .
Definition: statistics.hpp:596
void statistics(InputIterator first, InputIterator last, slip::Statistics< T > &statistic)
compute all statistics of a range
T unbiased_variance(InputIterator first, InputIterator last, T mean)
Computes the unbiased variance of a range .
Definition: statistics.hpp:566
T & median()
Returns the median value.
Definition: statistics.hpp:132
This is a linear (one-dimensional) dynamic template container. This container statisfies the RandomAc...
Definition: Array.hpp:94
std::iterator_traits< RandomAccessIterator >::value_type median_n(RandomAccessIterator first, RandomAccessIterator last, SizeType n)
Computes the median value from a range of size n.
T & max(const GrayscaleImage< T > &M1)
Returns the max element of a GrayscaleImage.
T kurtosis(InputIterator first, InputIterator last, T mean)
Computes the kurtosis of a range A high kurtosis distribution has a sharper peak and longer...
Definition: statistics.hpp:666
T unbiased_covariance(InputIterator first, InputIterator last, InputIterator2 first2, T mean1, T mean2)
Computes the unbiased covariance of a two sequences .
Definition: statistics.hpp:488
T skewness_if(InputIterator first, InputIterator last, T mean, Predicate pred)
Computes the skewness of a range using a predicate skewness is a measure of the asymmetry of the pro...