prediction_early_stop.h 1.08 KB
Newer Older
cbecker's avatar
cbecker committed
1
2
3
4
5
6
7
8
#ifndef LIGHTGBM_PREDICTION_EARLY_STOP_H_
#define LIGHTGBM_PREDICTION_EARLY_STOP_H_

#include <functional>
#include <string>

#include <LightGBM/export.h>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
namespace LightGBM {

struct PredictionEarlyStopInstance {
  /// Callback function type for early stopping.
  /// Takes current prediction and number of elements in prediction
  /// @returns true if prediction should stop according to criterion
  using FunctionType = std::function<bool(const double*, int)>;

  FunctionType callback_function;  // callback function itself
  int          round_period;       // call callback_function every `runPeriod` iterations
};

struct PredictionEarlyStopConfig {
  int round_period;
  double margin_threshold;
};

/// Create an early stopping algorithm of type `type`, with given round_period and margin threshold
LIGHTGBM_EXPORT PredictionEarlyStopInstance CreatePredictionEarlyStopInstance(const std::string& type,
                                                                              const PredictionEarlyStopConfig& config);
cbecker's avatar
cbecker committed
29
30
31
32

}   // namespace LightGBM

#endif // LIGHTGBM_PREDICTION_EARLY_STOP_H_