#include <algorithm>
#include <iterator>
#include <numeric>
#include <vector>
Go to the source code of this file.
|
template<typename Container , typename T = typename std::decay<decltype(*std::begin(std::declval<Container>()))>::type> |
T | standard_deviation (Container &&c) |
|
template<typename Container , typename T = typename std::decay<decltype(*std::begin(std::declval<Container>()))>::type> |
T | mean (Container &&c) |
|
template<typename T > |
T | median (std::vector< T > a) |
|
◆ mean()
template<typename
Container , typename T = typename std::decay<decltype(*std::begin(std::declval<Container>()))>::type>
◆ median()
template<typename T >
T median |
( |
std::vector< T > |
a | ) |
|
|
inline |
60{
61 std::size_t n = a.size();
62
63 if (n % 2 == 0)
64 {
65
66
67
68 std::nth_element(a.begin(),
69 a.begin() + n / 2,
70 a.end());
71
72
73
74 std::nth_element(a.begin(),
75 a.begin() + (n - 1) / 2,
76 a.end());
77
78
79
80 return (T)(a[(n - 1) / 2]
81 + a[n / 2])
82 / 2.0;
83 }
84
85
86 else
87 {
88
89
90
91 std::nth_element(a.begin(),
92 a.begin() + n / 2,
93 a.end());
94
95
96
97 return (T)a[n / 2];
98 }
99}
Referenced by WorldSession::ComputeNewClockDelta().
◆ standard_deviation()
template<typename
Container , typename T = typename std::decay<decltype(*std::begin(std::declval<Container>()))>::type>
29{
30 auto b = std::begin(c), e = std::end(c);
31 auto size = std::distance(b, e);
32 auto sum = std::accumulate(b, e, T());
33 auto mean = sum / size;
34
35 if (size == 1)
36 {
37 return (T) 0;
38 }
39
40 T accum = T();
41 for (const auto d : c)
42 {
44 }
45 return std::sqrt(accum / (size - 1));
46}
T mean(Container &&c)
Definition: MathUtil.h:49
References mean().
Referenced by WorldSession::ComputeNewClockDelta().