forpy 2

regression_opt.h
Go to the documentation of this file.
1 /* Author: Christoph Lassner. */
2 #pragma once
3 #ifndef FORPY_THRESHOLD_OPTIMIZERS_REGOPT_H_
4 #define FORPY_THRESHOLD_OPTIMIZERS_REGOPT_H_
5
6 #include "../global.h"
7 #include "../util/serialization/basics.h"
8
9 #include "../types.h"
10 #include "../util/desk.h"
11 #include "./ithreshopt.h"
12
13 namespace forpy {
14
15 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Wunused-variable"
17
18 const int DLOG_ROPT_V = 1;
20 const size_t LOG_ROPT_NID = 12043;
21 const bool LOG_ROPT_ALLN = false;
23
33 #ifdef FORPY_SKLEARN_COMPAT
34 const float REGOPT_EPS = 1E-7;
35 #else
36 const float REGOPT_EPS = 1E-7f;
37 #endif
38 #pragma clang diagnostic pop
39
54 class RegressionOpt : public IThreshOpt {
55 public:
63 RegressionOpt(const size_t &n_thresholds = 0,
64 const float &gain_threshold = 1E-7f);
65
67 virtual std::shared_ptr<IThreshOpt> create_duplicate(
69 const uint & /*random_seed*/) const {
70 return std::make_shared<RegressionOpt>(n_thresholds, gain_threshold);
71 }
72 void check_annotations(IDataProvider *dprov);
73 inline void transfer_or_run_check(IThreshOpt *other, IDataProvider *dprov) {
74 auto *ot_ropt = dynamic_cast<RegressionOpt *>(other);
75 if (ot_ropt == nullptr) ot_ropt->check_annotations(dprov);
76 };
77 void full_entropy(const IDataProvider &dprov, Desk *) const;
78 void optimize(Desk *) const;
79 float get_gain_threshold_for(const size_t & /*node_id*/) {
80 return gain_threshold;
81 };
83
84 inline friend std::ostream &operator<<(std::ostream &stream,
85 const RegressionOpt & /*self*/) {
86 stream << "forpy::RegressionOpt";
87 return stream;
88 };
89 bool operator==(const IThreshOpt &rhs) const;
90
91 private:
92 inline SplitOptRes<float> &optimize__setup(DeciderDesk &d) const;
93 inline void optimize__sort(DeciderDesk &d) const;
94 inline std::unique_ptr<std::vector<float>> optimize__thresholds(
95 Desk *d) const;
96 friend class cereal::access;
97 template <class Archive>
98 void serialize(Archive &ar, const uint &) {
99 ar(cereal::make_nvp("base", cereal::base_class<IThreshOpt>(this)),
100 CEREAL_NVP(n_thresholds), CEREAL_NVP(gain_threshold));
101 }
102
103 size_t n_thresholds;
104 float gain_threshold;
105
106 DISALLOW_COPY_AND_ASSIGN(RegressionOpt);
107 };
108 } // namespace forpy
109
110 CEREAL_REGISTER_TYPE(forpy::RegressionOpt);
111 #endif // FORPY_THRESHOLD_OPTIMIZERS_REGOPT_H_
forpy::IThreshOpt
Find an optimal threshold.
Definition: ithreshopt.h:23
forpy::DeciderDesk
Desk for decider training.
Definition: desk.h:61
forpy::SplitOptRes
Definition: types.h:119
forpy::RegressionOpt::optimize__setup
SplitOptRes< float > & optimize__setup(DeciderDesk &d) const
forpy::IDataProvider
A data provider for the training of one tree.
Definition: idataprovider.h:22
forpy::RegressionOpt::serialize
void serialize(Archive &ar, const uint &)
Definition: regression_opt.h:98
forpy::RegressionOpt::RegressionOpt
RegressionOpt(const size_t &n_thresholds=0, const float &gain_threshold=1E-7f)
forpy::RegressionOpt::get_gain_threshold_for
float get_gain_threshold_for(const size_t &)
Interface implementation.
Definition: regression_opt.h:79
forpy::RegressionOpt
Optimize split thresholds to optimize regression results (MSE).
Definition: regression_opt.h:54
ithreshopt.h
forpy::RegressionOpt::n_thresholds
size_t n_thresholds
Definition: regression_opt.h:103
forpy::LOG_ROPT_ALLN
const bool LOG_ROPT_ALLN
Variables to control debugging and log output for the forpy::RegressionOpt.
Definition: regression_opt.h:21
CEREAL_REGISTER_TYPE
CEREAL_REGISTER_TYPE(forpy::RegressionOpt)
forpy::RegressionOpt::check_annotations
void check_annotations(IDataProvider *dprov)
Interface implementation.
forpy::RegressionOpt::transfer_or_run_check
void transfer_or_run_check(IThreshOpt *other, IDataProvider *dprov)
Interface implementation.
Definition: regression_opt.h:73
forpy::RegressionOpt::operator<<
friend std::ostream & operator<<(std::ostream &stream, const RegressionOpt &)
Definition: regression_opt.h:84
forpy::RegressionOpt::gain_threshold
float gain_threshold
Definition: regression_opt.h:104
forpy::RegressionOpt::full_entropy
void full_entropy(const IDataProvider &dprov, Desk *) const
Interface implementation.
forpy::RegressionOpt::optimize
void optimize(Desk *) const
Interface implementation.
forpy::RegressionOpt::create_duplicate
virtual std::shared_ptr< IThreshOpt > create_duplicate(const uint &) const
Interface implementation.
Definition: regression_opt.h:68
forpy::RegressionOpt::DISALLOW_COPY_AND_ASSIGN
DISALLOW_COPY_AND_ASSIGN(RegressionOpt)
forpy::RegressionOpt::operator==
bool operator==(const IThreshOpt &rhs) const
forpy::RegressionOpt::optimize__sort
void optimize__sort(DeciderDesk &d) const
forpy::LOG_ROPT_NID
const size_t LOG_ROPT_NID
Variables to control debugging and log output for the forpy::RegressionOpt.
Definition: regression_opt.h:20
forpy::RegressionOpt::optimize__thresholds
std::unique_ptr< std::vector< float > > optimize__thresholds(Desk *d) const
forpy
Definition: fastdprov.h:13
forpy::Desk
Main thread desk object.
Definition: desk.h:201
forpy::REGOPT_EPS
const float REGOPT_EPS
Regression epsilon. No differences less than this are considered existent. This is relevant for: ...
Definition: regression_opt.h:36
forpy::RegressionOpt::access
friend class cereal::access
Definition: regression_opt.h:96
forpy::DLOG_ROPT_V
const int DLOG_ROPT_V
Variables to control debugging and log output for the forpy::RegressionOpt.
Definition: regression_opt.h:19
forpy::uint
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113