22 #ifndef EDSP_STATISTICAL_ENTROPY_HPP 23 #define EDSP_STATISTICAL_ENTROPY_HPP 25 #include <edsp/meta/iterator.hpp> 29 namespace edsp {
namespace statistics {
50 template <
typename ForwardIt>
51 constexpr meta::value_type_t<ForwardIt>
entropy(ForwardIt first, ForwardIt last) {
52 using input_t = meta::value_type_t<ForwardIt>;
53 const auto predicate = [](
const input_t accumulated,
const input_t current) {
54 return (accumulated + std::log2(current) * current);
56 const auto size =
static_cast<input_t
>(
std::distance(first, last));
57 const auto acc = std::accumulate(first, last, static_cast<input_t>(0), predicate);
58 return -acc / std::log2(size);
63 #endif // EDSP_STATISTICAL_ENTROPY_HPP constexpr meta::value_type_t< ForwardIt > entropy(ForwardIt first, ForwardIt last)
Computes the normalized entropy of the probability mass function given in the range [first...
Definition: entropy.hpp:51
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
Definition: amplifier.hpp:29