prediction_early_stop.h 1.3 KB
Newer Older
1
2
3
4
/*!
 * Copyright (c) 2017 Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for license information.
 */
5
6
#ifndef LIGHTGBM_INCLUDE_LIGHTGBM_PREDICTION_EARLY_STOP_H_
#define LIGHTGBM_INCLUDE_LIGHTGBM_PREDICTION_EARLY_STOP_H_
cbecker's avatar
cbecker committed
7

8
9
#include <LightGBM/export.h>

10
11
12
#include <string>
#include <functional>

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
33
34
35

}   // namespace LightGBM

36
#endif  // LIGHTGBM_INCLUDE_LIGHTGBM_PREDICTION_EARLY_STOP_H_