forpy 2

fastclassopt.h
Go to the documentation of this file.
1 /* Author: Christoph Lassner. */
2 #pragma once
3 #ifndef FORPY_THRESHOLD_OPTIMIZERS_FASTCLASSOPT_H_
4 #define FORPY_THRESHOLD_OPTIMIZERS_FASTCLASSOPT_H_
5
6 #include "../global.h"
7 #include "../util/serialization/basics.h"
8
9 #include "../impurities/ientropyfunction.h"
10 #include "../impurities/shannonentropy.h"
11 #include "../types.h"
12 #include "../util/desk.h"
13 #include "./classification_opt.h"
14 #include "./ithreshopt.h"
15
16 namespace forpy {
17
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wunused-variable"
20
21 const int DLOG_FCOPT_V = 100;
23 const size_t LOG_FCOPT_NID = 3;
24 const bool LOG_FCOPT_ALLN = true;
26
40 class FastClassOpt : public ClassificationOpt {
41 public:
49 FastClassOpt(const size_t &n_thresholds = 0,
50 const float &gain_threshold = 1E-7f);
51
53 virtual std::shared_ptr<IThreshOpt> create_duplicate(
55 const uint & /*random_seed*/) const {
56 return std::make_shared<FastClassOpt>(n_thresholds, gain_threshold);
57 }
58 void full_entropy(const IDataProvider &dprov, Desk *) const;
59 void optimize(Desk *) const;
61
62 inline friend std::ostream &operator<<(std::ostream &stream,
63 const FastClassOpt & /*self*/) {
64 stream << "forpy::FastClassOpt";
65 return stream;
66 };
67 bool operator==(const IThreshOpt &rhs) const;
68
69 private:
70 template <typename IT>
71 inline SplitOptRes<IT> &optimize__setup(DeciderDesk &d) const;
72 template <typename IT>
73 inline void optimize__sort(DeciderDesk &d) const;
74 template <typename IT>
75 inline std::unique_ptr<std::vector<IT>> optimize__thresholds(Desk *d) const;
76 friend class cereal::access;
77 template <class Archive>
78 void serialize(Archive &ar, const uint &) {
79 ar(cereal::make_nvp("base", cereal::base_class<ClassificationOpt>(this)));
80 }
81
82 using ClassificationOpt::class_transl_ptr;
83 using ClassificationOpt::gain_threshold;
84 using ClassificationOpt::n_classes;
85 using ClassificationOpt::n_thresholds;
86 using ClassificationOpt::true_max;
87 DISALLOW_COPY_AND_ASSIGN(FastClassOpt);
88 };
89 } // namespace forpy
90
91 CEREAL_REGISTER_TYPE(forpy::FastClassOpt);
92 #endif // FORPY_THRESHOLD_OPTIMIZERS_FASTCLASSOPT_H_
forpy::FastClassOpt::operator<<
friend std::ostream & operator<<(std::ostream &stream, const FastClassOpt &)
Definition: fastclassopt.h:62
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::FastClassOpt::serialize
void serialize(Archive &ar, const uint &)
Definition: fastclassopt.h:78
forpy::IDataProvider
A data provider for the training of one tree.
Definition: idataprovider.h:22
forpy::ClassificationOpt::n_classes
size_t n_classes
Definition: classification_opt.h:113
forpy::FastClassOpt::access
friend class cereal::access
Definition: fastclassopt.h:76
forpy::FastClassOpt::DISALLOW_COPY_AND_ASSIGN
DISALLOW_COPY_AND_ASSIGN(FastClassOpt)
classification_opt.h
ithreshopt.h
forpy::LOG_FCOPT_ALLN
const bool LOG_FCOPT_ALLN
Variables to control debugging and log output for the forpy::RegressionOpt.
Definition: fastclassopt.h:24
forpy::FastClassOpt::optimize
void optimize(Desk *) const
Interface implementation.
forpy::LOG_FCOPT_NID
const size_t LOG_FCOPT_NID
Variables to control debugging and log output for the forpy::RegressionOpt.
Definition: fastclassopt.h:23
forpy::ClassificationOpt::class_transl_ptr
std::shared_ptr< std::vector< uint > > class_transl_ptr
Definition: classification_opt.h:116
forpy::ClassificationOpt
Optimize split thresholds to optimize classification results.
Definition: classification_opt.h:55
forpy::DLOG_FCOPT_V
const int DLOG_FCOPT_V
Variables to control debugging and log output for the forpy::RegressionOpt.
Definition: fastclassopt.h:22
forpy::FastClassOpt::optimize__sort
void optimize__sort(DeciderDesk &d) const
forpy::FastClassOpt::optimize__setup
SplitOptRes< IT > & optimize__setup(DeciderDesk &d) const
forpy::FastClassOpt::optimize__thresholds
std::unique_ptr< std::vector< IT > > optimize__thresholds(Desk *d) const
forpy
Definition: fastdprov.h:13
forpy::ClassificationOpt::gain_threshold
float gain_threshold
Definition: classification_opt.h:114
forpy::ClassificationOpt::n_thresholds
size_t n_thresholds
Definition: classification_opt.h:112
forpy::Desk
Main thread desk object.
Definition: desk.h:201
forpy::FastClassOpt
Optimize split thresholds to optimize classification results.
Definition: fastclassopt.h:40
forpy::FastClassOpt::operator==
bool operator==(const IThreshOpt &rhs) const
forpy::FastClassOpt::full_entropy
void full_entropy(const IDataProvider &dprov, Desk *) const
Interface implementation.
forpy::FastClassOpt::create_duplicate
virtual std::shared_ptr< IThreshOpt > create_duplicate(const uint &) const
Interface implementation.
Definition: fastclassopt.h:54
forpy::uint
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113
CEREAL_REGISTER_TYPE
CEREAL_REGISTER_TYPE(forpy::FastClassOpt)
forpy::ClassificationOpt::true_max
int true_max
Definition: classification_opt.h:117
forpy::FastClassOpt::FastClassOpt
FastClassOpt(const size_t &n_thresholds=0, const float &gain_threshold=1E-7f)