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)
42 : entropy_function(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:
62 EntropyGain() {}
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
76 CEREAL_REGISTER_TYPE(forpy::EntropyGain);
77 #endif // FORPY_GAINS_ENTROPYGAIN_H_
forpy::IGainCalculator
Interface for a gain calculator class.
Definition: igaincalculator.h:29
forpy::EntropyGain::EntropyGain
EntropyGain()
Definition: entropygain.h:62
forpy::EntropyGain::getEntropy_function
std::shared_ptr< IEntropyFunction > getEntropy_function() const
forpy::EntropyGain::operator()
float operator()(const float &current_entropy, const std::vector< float > &members_numbers_left, const std::vector< float > &members_numbers_right)
igaincalculator.h
CEREAL_REGISTER_TYPE
CEREAL_REGISTER_TYPE(forpy::EntropyGain)
forpy::EntropyGain::EntropyGain
EntropyGain(const std::shared_ptr< IEntropyFunction > &entropy_function)
Definition: entropygain.h:40
forpy::EntropyGain::access
friend class cereal::access
Definition: entropygain.h:67
forpy::EntropyGain::entropy_function
std::shared_ptr< IEntropyFunction > entropy_function
Definition: entropygain.h:65
forpy::EntropyGain
Calculates the gain as difference of current entropy and the weighted sum of subgroup entropies...
Definition: entropygain.h:34
forpy::EntropyGain::operator==
bool operator==(const IGainCalculator &rhs) const
forpy
Definition: fastdprov.h:13
forpy::EntropyGain::approx
float approx(const std::vector< float > &members_numbers_left, const std::vector< float > &members_numbers_right)
forpy::EntropyGain::serialize
void serialize(Archive &ar, const uint &)
Definition: entropygain.h:69
forpy::uint
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113