Program Listing for File ientropy.hpp
↰ Return to documentation for file (rcppsw/math/ientropy.hpp)
#pragma once
/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <algorithm>
#include <vector>
#include "rcppsw/math/expression.hpp"
#include "rcppsw/math/radians.hpp"
#include "rcppsw/rcppsw.hpp"
/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::math {
/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class ientropy : public math::expression<double> {
 public:
  double operator()(const std::vector<double>& groups) {
    double entropy = 0.0;
    std::for_each(groups.begin(), groups.end(), [&](const auto& prop) {
      entropy += prop * std::log2(prop);
    });
    return eval(-entropy);
  }
};
} /* namespace rcppsw::math */