MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / BinaryMetric

Class BinaryMetric

src/metric/binary_metric.hpp:24–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22*/
23template<typename PointWiseLossCalculator>
24class BinaryMetric: public Metric {
25 public:
26 explicit BinaryMetric(const Config&) {
27 }
28
29 virtual ~BinaryMetric() {
30 }
31
32 void Init(const Metadata& metadata, data_size_t num_data) override {
33 name_.emplace_back(PointWiseLossCalculator::Name());
34
35 num_data_ = num_data;
36 // get label
37 label_ = metadata.label();
38
39 // get weights
40 weights_ = metadata.weights();
41
42 if (weights_ == nullptr) {
43 sum_weights_ = static_cast<double>(num_data_);
44 } else {
45 sum_weights_ = 0.0f;
46 for (data_size_t i = 0; i < num_data; ++i) {
47 sum_weights_ += weights_[i];
48 }
49 }
50 }
51
52 const std::vector<std::string>& GetName() const override {
53 return name_;
54 }
55
56 double factor_to_bigger_better() const override {
57 return -1.0f;
58 }
59
60 std::vector<double> Eval(const double* score, const ObjectiveFunction* objective) const override {
61 double sum_loss = 0.0f;
62 if (objective == nullptr) {
63 if (weights_ == nullptr) {
64 #pragma omp parallel for schedule(static) reduction(+:sum_loss)
65 for (data_size_t i = 0; i < num_data_; ++i) {
66 // add loss
67 sum_loss += PointWiseLossCalculator::LossOnPoint(label_[i], score[i]);
68 }
69 } else {
70 #pragma omp parallel for schedule(static) reduction(+:sum_loss)
71 for (data_size_t i = 0; i < num_data_; ++i) {
72 // add loss
73 sum_loss += PointWiseLossCalculator::LossOnPoint(label_[i], score[i]) * weights_[i];
74 }
75 }
76 } else {
77 if (weights_ == nullptr) {
78 #pragma omp parallel for schedule(static) reduction(+:sum_loss)
79 for (data_size_t i = 0; i < num_data_; ++i) {
80 double prob = 0;
81 objective->ConvertOutput(&score[i], &prob);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected