IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
BasicStatistics.h
Go to the documentation of this file.
1 // BasicStatistics.h:
3 // ------------------
4 //
14 
15 #ifndef __IPSDKMATH_BASICSTATISTICS_H__
16 #define __IPSDKMATH_BASICSTATISTICS_H__
17 
19 #include <IPSDKUtil/BaseTypes.h>
21 #include <algorithm>
22 #include <vector>
23 
24 namespace ipsdk {
25 namespace math {
26 
29 
33 template <typename IteratorType>
34 void
35 extractMinMax(const IteratorType& iterBegin,
36  const IteratorType& iterEnd,
37  typename std::iterator_traits<IteratorType>::value_type& minValue,
38  typename std::iterator_traits<IteratorType>::value_type& maxValue)
39 {
40  // initialize output values
41  typedef typename std::iterator_traits<IteratorType>::value_type T;
42  minValue = NumericLimits<T>::max();
43  maxValue = NumericLimits<T>::min();
44 
45  // parse all data
46  IteratorType iter = iterBegin;
47  while (iter != iterEnd) {
48 
49  if (*iter < minValue)
50  minValue = *iter;
51  if (*iter > maxValue)
52  maxValue = *iter;
53 
54  ++iter;
55  }
56 }
57 template <typename ContainerType>
58 void
59 extractMinMax(const ContainerType& coll,
60  typename ContainerType::value_type& minValue,
61  typename ContainerType::value_type& maxValue)
62 {
63  extractMinMax(coll.begin(), coll.end(), minValue, maxValue);
64 }
66 
71 template <typename T>
72 T
73 median(std::vector<T>& coll)
74 {
75  // check for collection size
76  const ipUInt32 size = static_cast<ipUInt32>(coll.size());
77  if (size == 0)
78  return 0;
79 
80  // compute median value
81  std::nth_element(coll.begin(),
82  coll.begin() + size / 2,
83  coll.end());
84 
85  return coll[size / 2];
86 }
87 
89 template <typename T>
91 mean(const std::vector<T>& coll);
92 
94 template <typename T>
96 variance(const std::vector<T>& coll);
97 
99 template <typename T>
101 stdDev(const std::vector<T>& coll);
102 
104 template <typename T>
105 IPSDKMATH_API std::pair<ipReal64, ipReal64>
106 meanAndVariance(const std::vector<T>& coll);
107 
114 template <typename T>
116 correlation(const std::vector<T>& coll1, const std::vector<T>& coll2);
117 
120 
121 } // end of namespace math
122 } // end of namespace ipsdk
123 
124 #endif // __IPSDKMATH_BASICSTATISTICS_H__
IPSDKMATH_API ipReal64 stdDev(const std::vector< T > &coll)
function allowing to compute standard deviation for a vector
Definition of import/export macro for library.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
void extractMinMax(const IteratorType &iterBegin, const IteratorType &iterEnd, typename std::iterator_traits< IteratorType >::value_type &minValue, typename std::iterator_traits< IteratorType >::value_type &maxValue)
function allowing to compute minimum and maximum value for a collection
Definition: BasicStatistics.h:35
IPSDKMATH_API std::pair< ipReal64, ipReal64 > meanAndVariance(const std::vector< T > &coll)
function allowing to compute mean and variance for a vector
T median(std::vector< T > &coll)
function allowing to compute median of a collection
Definition: BasicStatistics.h:73
IPSDKMATH_API ipReal64 mean(const std::vector< T > &coll)
function allowing to compute mean for a vector
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
Definition: NumericLimits.h:27
Base types for multiplatform compatibility.
#define IPSDKMATH_API
Import/Export macro for library IPSDKMath.
Definition: IPSDKMathExports.h:27
IPSDKMATH_API ipReal64 correlation(const std::vector< T > &coll1, const std::vector< T > &coll2)
function allowing to compute correlation between two vectors of data
IPSDKMATH_API ipReal64 variance(const std::vector< T > &coll)
function allowing to compute variance for a vector
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53