"vscode:/vscode.git/clone" did not exist on "8d12dca13677190f37de58621cc6d65243c7fc76"
objective_function.h 1.39 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef LIGHTGBM_OBJECTIVE_FUNCTION_H_
#define LIGHTGBM_OBJECTIVE_FUNCTION_H_

#include <LightGBM/meta.h>
#include <LightGBM/config.h>
#include <LightGBM/dataset.h>

namespace LightGBM {

/*!
* \brief The interface of Objective Function.
*/
class ObjectiveFunction {
public:
  /*! \brief virtual destructor */
  virtual ~ObjectiveFunction() {}

  /*!
  * \brief Initialize
  * \param metadata Label data
  * \param num_data Number of data
  */
  virtual void Init(const Metadata& metadata, data_size_t num_data) = 0;

  /*!
Qiwei Ye's avatar
Qiwei Ye committed
26
27
  * \brief calculating first order derivative of loss function
  * \param score prediction score in this round
Guolin Ke's avatar
Guolin Ke committed
28
29
30
  * \gradients Output gradients
  * \hessians Output hessians
  */
31
  virtual void GetGradients(const double* score,
Guolin Ke's avatar
Guolin Ke committed
32
33
    score_t* gradients, score_t* hessians) const = 0;

Guolin Ke's avatar
Guolin Ke committed
34
35
36
37
38
39
40
  virtual const char* GetName() const = 0;

  ObjectiveFunction() = default;
  /*! \brief Disable copy */
  ObjectiveFunction& operator=(const ObjectiveFunction&) = delete;
  /*! \brief Disable copy */
  ObjectiveFunction(const ObjectiveFunction&) = delete;
Guolin Ke's avatar
Guolin Ke committed
41
42
43
44
45
46

  /*!
  * \brief Create object of objective function
  * \param type Specific type of objective function
  * \param config Config for objective function
  */
47
  LIGHTGBM_EXPORT static ObjectiveFunction* CreateObjectiveFunction(const std::string& type,
Guolin Ke's avatar
Guolin Ke committed
48
49
50
51
52
    const ObjectiveConfig& config);
};

}  // namespace LightGBM

Guolin Ke's avatar
Guolin Ke committed
53
#endif   // LightGBM_OBJECTIVE_FUNCTION_H_