forpy  2
entropygain.h
Go to the documentation of this file.
1 /* Author: Christoph Lassner. */
2 #pragma once
3 #ifndef FORPY_GAINS_ENTROPYGAIN_H_
4 #define FORPY_GAINS_ENTROPYGAIN_H_
5 
6 #include "../global.h"
7 
8 #include "../util/serialization/basics.h"
9 
10 #include <algorithm>
11 #include <limits>
12 #include <numeric>
13 #include <vector>
14 
15 #include "../impurities/impurities.h"
16 #include "../util/checks.h"
17 #include "./igaincalculator.h"
18 
19 namespace forpy {
34 class EntropyGain : public IGainCalculator {
35  public:
40  explicit EntropyGain(
41  const std::shared_ptr<IEntropyFunction> &entropy_function)
43 
45  float approx(const std::vector<float> &members_numbers_left,
46  const std::vector<float> &members_numbers_right);
47 
49  float operator()(const float &current_entropy,
50  const std::vector<float> &members_numbers_left,
51  const std::vector<float> &members_numbers_right);
52 
54  float operator()(const std::vector<float> &members_numbers_left,
55  const std::vector<float> &members_numbers_right);
56 
57  bool operator==(const IGainCalculator &rhs) const;
58 
59  std::shared_ptr<IEntropyFunction> getEntropy_function() const;
60 
61  protected:
63 
64  private:
65  std::shared_ptr<IEntropyFunction> entropy_function;
66 
67  friend class cereal::access;
68  template <class Archive>
69  void serialize(Archive &ar, const uint &) {
70  ar(cereal::make_nvp("base", cereal::base_class<IGainCalculator>(this)),
71  CEREAL_NVP(entropy_function));
72  }
73 };
74 }; // namespace forpy
75 
77 #endif // FORPY_GAINS_ENTROPYGAIN_H_
Interface for a gain calculator class.
std::shared_ptr< IEntropyFunction > getEntropy_function() const
float operator()(const float &current_entropy, const std::vector< float > &members_numbers_left, const std::vector< float > &members_numbers_right)
CEREAL_REGISTER_TYPE(forpy::EntropyGain)
EntropyGain(const std::shared_ptr< IEntropyFunction > &entropy_function)
Definition: entropygain.h:40
friend class cereal::access
Definition: entropygain.h:67
std::shared_ptr< IEntropyFunction > entropy_function
Definition: entropygain.h:65
Calculates the gain as difference of current entropy and the weighted sum of subgroup entropies...
Definition: entropygain.h:34
bool operator==(const IGainCalculator &rhs) const
float approx(const std::vector< float > &members_numbers_left, const std::vector< float > &members_numbers_right)
void serialize(Archive &ar, const uint &)
Definition: entropygain.h:69
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113