forpy  2
classificationerror.h
Go to the documentation of this file.
1 /* Author: Christoph Lassner. */
2 #pragma once
3 #ifndef FORPY_IMPURITIES_CLASSIFICATIONERROR_H_
4 #define FORPY_IMPURITIES_CLASSIFICATIONERROR_H_
5 
6 #include "../global.h"
7 
8 #include "../util/serialization/basics.h"
9 
10 #include <limits>
11 #include <vector>
12 
13 #include "../util/exponentials.h"
14 #include "./ientropyfunction.h"
15 
16 namespace forpy {
23  public:
26 
27  inline float operator()(const float *class_members_numbers, const size_t &n,
28  const float &fsum) const {
29  // Deal with the special case quickly.
30  if (fsum == 0.f) return 0.f;
31 
32  return 1.f -
33  *std::max_element(class_members_numbers, class_members_numbers + n) /
34  fsum;
35  }
36 
37  inline friend std::ostream &operator<<(std::ostream &stream,
38  const ClassificationError & /*self*/) {
39  stream << "forpy::ClassificationError";
40  return stream;
41  };
42  bool operator==(const IEntropyFunction &rhs) const;
43 
44  private:
46 
47  friend class cereal::access;
48  template <class Archive>
49  void serialize(Archive &ar, const uint &) {
50  ar(cereal::make_nvp("base", cereal::base_class<IEntropyFunction>(this)));
51  }
52 };
53 } // namespace forpy
54 
56 #endif // FORPY_IMPURITIES_CLASSIFICATIONERROR_H_
void serialize(Archive &ar, const uint &)
float operator()(const float *class_members_numbers, const size_t &n, const float &fsum) const
Interface for an entropy calculation functor.
DISALLOW_COPY_AND_ASSIGN(ClassificationError)
CEREAL_REGISTER_TYPE(forpy::ClassificationError)
bool operator==(const IEntropyFunction &rhs) const
friend std::ostream & operator<<(std::ostream &stream, const ClassificationError &)
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113
friend class cereal::access
Computes the classification error as .