22 #ifndef EDSP_STATISTICAL_CENTROID_HPP 23 #define EDSP_STATISTICAL_CENTROID_HPP 25 #include <edsp/meta/iterator.hpp> 27 namespace edsp {
namespace statistics {
42 template <
typename ForwardIt>
43 constexpr meta::value_type_t<ForwardIt>
centroid(ForwardIt first, ForwardIt last) {
44 using input_t = meta::value_type_t<ForwardIt>;
45 auto weighted_sum =
static_cast<input_t
>(0);
46 auto unweighted_sum =
static_cast<input_t
>(0);
47 for (input_t i = 0; first != last; ++first, ++i) {
48 weighted_sum += i * (*first);
49 unweighted_sum += *first;
51 return weighted_sum / unweighted_sum;
68 template <
typename ForwardIt>
69 constexpr meta::value_type_t<ForwardIt>
centroid(ForwardIt first1, ForwardIt last1, ForwardIt first2) {
70 using input_t = meta::value_type_t<ForwardIt>;
71 auto weighted_sum =
static_cast<input_t
>(0);
72 auto unweighted_sum =
static_cast<input_t
>(0);
73 for (; first1 != last1; ++first1, ++first2) {
74 weighted_sum += (*first2) * (*first1);
75 unweighted_sum += *first1;
77 return weighted_sum / unweighted_sum;
82 #endif // EDSP_STATISTICAL_CENTROID_HPP Definition: amplifier.hpp:29
constexpr meta::value_type_t< ForwardIt > centroid(ForwardIt first, ForwardIt last)
Computes the centroid value of the range [first, last)
Definition: centroid.hpp:43