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

Function CreateMulticlass

src/boosting/prediction_early_stop.cpp:25–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25PredictionEarlyStopInstance CreateMulticlass(const PredictionEarlyStopConfig& config) {
26 // margin_threshold will be captured by value
27 const double margin_threshold = config.margin_threshold;
28
29 return PredictionEarlyStopInstance{
30 [margin_threshold](const double* pred, int sz) {
31 if (sz < 2) {
32 Log::Fatal("Multiclass early stopping needs predictions to be of length two or larger");
33 }
34
35 // copy and sort
36 std::vector<double> votes(static_cast<size_t>(sz));
37 for (int i = 0; i < sz; ++i) {
38 votes[i] = pred[i];
39 }
40 std::partial_sort(votes.begin(), votes.begin() + 2, votes.end(), std::greater<double>());
41
42 const auto margin = votes[0] - votes[1];
43
44 if (margin > margin_threshold) {
45 return true;
46 }
47
48 return false;
49 },
50 config.round_period
51 };
52}
53
54PredictionEarlyStopInstance CreateBinary(const PredictionEarlyStopConfig& config) {
55 // margin_threshold will be captured by value

Callers 1

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected